summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJim McDonough <jmcd@samba.org>2002-10-29 14:45:41 +0000
committerJim McDonough <jmcd@samba.org>2002-10-29 14:45:41 +0000
commite5fda27b09ed7f550ecbc9a9b3cae9d0f21e1d52 (patch)
tree393007cb256e7329e75e7b63bac6777117d75303 /source3
parent0fff69f974ac8add92da2ee3e0e08084c09e6e9a (diff)
downloadsamba-e5fda27b09ed7f550ecbc9a9b3cae9d0f21e1d52.tar.gz
samba-e5fda27b09ed7f550ecbc9a9b3cae9d0f21e1d52.tar.bz2
samba-e5fda27b09ed7f550ecbc9a9b3cae9d0f21e1d52.zip
Move guid formatting functions over from HEAD.
(This used to be commit 60b9e352b3c0769d0d3fe3067399bb3441f29502)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/util_uuid.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c
index 63e2504982..1543094d40 100644
--- a/source3/lib/util_uuid.c
+++ b/source3/lib/util_uuid.c
@@ -31,7 +31,7 @@ struct uuid {
uint32 time_low;
uint16 time_mid;
uint16 time_hi_and_version;
- uint16 clock_seq;
+ uint8 clock_seq[2];
uint8 node[6];
};
@@ -43,7 +43,7 @@ static void uuid_pack(const struct uuid *uu, GUID *ptr)
SIVAL(out, 0, uu->time_low);
SSVAL(out, 4, uu->time_mid);
SSVAL(out, 6, uu->time_hi_and_version);
- SSVAL(out, 8, uu->clock_seq);
+ memcpy(out+8, uu->clock_seq, 2);
memcpy(out+10, uu->node, 6);
}
@@ -54,7 +54,7 @@ static void uuid_unpack(const GUID in, struct uuid *uu)
uu->time_low = IVAL(ptr, 0);
uu->time_mid = SVAL(ptr, 4);
uu->time_hi_and_version = SVAL(ptr, 6);
- uu->clock_seq = SVAL(ptr, 8);
+ memcpy(uu->clock_seq, ptr+8, 2);
memcpy(uu->node, ptr+10, 6);
}
@@ -66,7 +66,38 @@ void uuid_generate_random(GUID *out)
generate_random_buffer(tmp.info, sizeof(tmp.info), True);
uuid_unpack(tmp, &uu);
- uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000;
+ uu.clock_seq[0] = (uu.clock_seq[0] & 0x3F) | 0x80;
uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF) | 0x4000;
uuid_pack(&uu, out);
}
+
+char *uuid_to_string(const GUID in)
+{
+ struct uuid uu;
+ char *out;
+
+ uuid_unpack(in, &uu);
+
+ asprintf(&out, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+ uu.time_low, uu.time_mid, uu.time_hi_and_version,
+ uu.clock_seq[0], uu.clock_seq[1],
+ uu.node[0], uu.node[1], uu.node[2],
+ uu.node[3], uu.node[4], uu.node[5]);
+
+ return out;
+}
+
+const char *uuid_string_static(const GUID in)
+{
+ struct uuid uu;
+ static char out[37];
+
+ uuid_unpack(in, &uu);
+ slprintf(out, sizeof(out) -1,
+ "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+ uu.time_low, uu.time_mid, uu.time_hi_and_version,
+ uu.clock_seq[0], uu.clock_seq[1],
+ uu.node[0], uu.node[1], uu.node[2],
+ uu.node[3], uu.node[4], uu.node[5]);
+ return out;
+}