]>
Commit | Line | Data |
---|---|---|
1f2f436a A |
1 | --- unparse.c.orig 2010-06-27 12:49:24.000000000 -0700 |
2 | +++ unparse.c 2010-06-27 13:06:53.000000000 -0700 | |
3 | @@ -37,10 +37,10 @@ | |
4 | #include "uuidP.h" | |
5 | ||
6 | static const char *fmt_lower = | |
7 | - "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"; | |
8 | + "0123456789abcdef"; | |
9 | ||
10 | static const char *fmt_upper = | |
11 | - "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"; | |
12 | + "0123456789ABCDEF"; | |
13 | ||
14 | #ifdef UUID_UNPARSE_DEFAULT_UPPER | |
15 | #define FMT_DEFAULT fmt_upper | |
16 | @@ -50,14 +50,24 @@ static const char *fmt_upper = | |
17 | ||
18 | static void uuid_unparse_x(const uuid_t uu, char *out, const char *fmt) | |
19 | { | |
20 | - struct uuid uuid; | |
21 | - | |
22 | - uuid_unpack(uu, &uuid); | |
23 | - sprintf(out, fmt, | |
24 | - uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, | |
25 | - uuid.clock_seq >> 8, uuid.clock_seq & 0xFF, | |
26 | - uuid.node[0], uuid.node[1], uuid.node[2], | |
27 | - uuid.node[3], uuid.node[4], uuid.node[5]); | |
28 | + const uint8_t *uuid_array = (const uint8_t *)uu; | |
29 | + int uuid_index; | |
30 | + | |
31 | + for ( uuid_index = 0; uuid_index < sizeof(uuid_t); ++uuid_index ) { | |
32 | + // insert '-' after the 4th, 6th, 8th, and 10th uuid byte | |
33 | + switch (uuid_index) { | |
34 | + case 4: | |
35 | + case 6: | |
36 | + case 8: | |
37 | + case 10: | |
38 | + *out++ = '-'; | |
39 | + break; | |
40 | + } | |
41 | + // insert uuid byte as two hex characters | |
42 | + *out++ = fmt[*uuid_array >> 4]; | |
43 | + *out++ = fmt[*uuid_array++ & 0xF]; | |
44 | + } | |
45 | + *out = 0; | |
46 | } | |
47 | ||
48 | void uuid_unparse_lower(const uuid_t uu, char *out) |