File: uuid-test.c

package info (click to toggle)
fence-virt 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 772 kB
  • sloc: ansic: 10,257; cpp: 382; makefile: 272; sh: 214; lex: 113; yacc: 105
file content (62 lines) | stat: -rw-r--r-- 842 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "config.h"

#include <uuid/uuid.h>
#include <errno.h>
#include <string.h>

int
is_uuid(const char *value)
{
	uuid_t id;
	char test_value[37];

	if (strlen(value) < 36) {
		return 0;
	}

	if (uuid_is_null(id) < 0) {
		errno = EINVAL;
		return -1;
	}

	if (uuid_parse(value, id) < 0) {
		return 0;
	}

	memset(test_value, 0, sizeof(test_value));
	uuid_unparse(id, test_value);

	if (strcasecmp(value, test_value)) {
		return 0;
	}

	return 1;
}

#ifdef STANDALONE
#include <stdio.h>

int 
main(int argc, char **argv)
{
	int ret;

	if (argc < 2) {
		printf("Usage: uuidtest <value>\n");
		return 1;
	}

	ret = is_uuid(argv[1]);
	if (ret == 0) {
		printf("%s is NOT a uuid\n", argv[1]);
	} else if (ret == 1) {
		printf("%s is a uuid\n", argv[1]);
	} else {
		printf("Error: %s\n", strerror(errno));
		return 1;
	}

	return 0;
}

#endif