2 Copyright © 2007-2018, The AROS Development Team. All rights reserved.
6 #include <aros/symbolsets.h>
7 #include <aros/debug.h>
8 #include <aros/libcall.h>
9 #include <proto/exec.h>
15 #include "uuid_private.h"
16 #include LC_LIBDEFS_FILE
18 static char value(char chr
)
23 chr
-= isupper(chr
) ? 'A' - 10 : 'a' - 10;
27 AROS_LH2(int, UUID_Parse
,
28 AROS_LHA(const char *, in
, A0
),
29 AROS_LHA(uuid_t
*, uuid
, A1
),
30 struct uuid_base
*, UUIDBase
, 7, UUID
)
35 uuid_t tmp
= {0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0}};
37 D(bug("[UUID] UUID_Parse(%s, %p)\n", in
, uuid
));
39 if (strlen(in
) == UUID_STRLEN
)
41 for (i
=0; i
< 8; i
++, in
++)
45 tmp
.time_low
= (tmp
.time_low
<< 4) | value(*in
);
53 for (i
=0; i
< 4; i
++, in
++)
57 tmp
.time_mid
= (tmp
.time_mid
<< 4) | value(*in
);
65 for (i
=0; i
< 4; i
++, in
++)
69 tmp
.time_hi_and_version
=
70 (tmp
.time_hi_and_version
<< 4) | value(*in
);
78 if (!(isxdigit(in
[0]) && isxdigit(in
[1])))
81 tmp
.clock_seq_hi_and_reserved
= (value(in
[0]) << 4) | value(in
[1]);
83 if (!(isxdigit(in
[2]) && isxdigit(in
[3])))
86 tmp
.clock_seq_low
= (value(in
[2]) << 4) | value(in
[3]);
92 for (i
=0; i
< 6; i
++, in
+=2)
94 if (!(isxdigit(in
[0]) && isxdigit(in
[1])))
97 tmp
.node
[i
] = (value(in
[0]) << 4) | value(in
[1]);
109 AROS_LH2(void, UUID_Unparse
,
110 AROS_LHA(const uuid_t
*, uuid
, A0
),
111 AROS_LHA(char *, out
, A1
),
112 struct uuid_base
*, UUIDBase
, 8, UUID
)
116 snprintf(out
, UUID_STRLEN
+ 1,
117 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
118 (unsigned int)uuid
->time_low
,
120 uuid
->time_hi_and_version
,
121 uuid
->clock_seq_hi_and_reserved
,
123 uuid
->node
[0],uuid
->node
[1],uuid
->node
[2],
124 uuid
->node
[3],uuid
->node
[4],uuid
->node
[5]);