OSSP CVS Repository

ossp - Difference in ossp-pkg/uuid/uuid.c versions 1.14 and 1.15
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/uuid/uuid.c 1.14 -> 1.15

--- uuid.c       2004/01/10 12:16:03     1.14
+++ uuid.c       2004/01/10 15:19:21     1.15
@@ -458,14 +458,75 @@
     return;
 }
 
+/* INTERNAL: generate UUID version 1, time part */
+static uuid_rc_t uuid_generate_v1_time(uuid_t *uuid, unsigned int mode, va_list ap)
+{
+    struct timeval tv;
+    ui64_t t;
+    ui64_t offset;
+    ui64_t ov;
+
+    /* determine current system time */
+    if (gettimeofday(&tv, NULL) == -1)
+        return UUID_RC_SYS;
+
+    /* convert from timeval (sec,usec) to OSSP ui64 (100*nsec) format */
+    t = ui64_n2i(tv.tv_sec);
+    t = ui64_muln(t, 1000000, NULL);
+    t = ui64_addn(t, tv.tv_usec, NULL);
+    t = ui64_muln(t, 10, NULL);
+
+    /* adjust for offset between UUID and Unix Epoch time through adding
+       the magic offset 01B21DD213814000 from draft-leach-uuids-guids-01.
+       (UUID UTC base time is October 15, 1582
+        Unix UTC base time is January  1, 1970) */
+    offset = ui64_s2i("01B21DD213814000", NULL, 16);
+    t = ui64_add(t, offset, NULL);
+
+    /* store the 60 LSB of the time in the UUID */
+    t = ui64_rol(t, 16, &ov);
+    uuid->obj.time_hi_and_version =
+        (uuid_uint16_t)(ui64_i2n(ov) & 0x00000fff); /* 12 of 16 bit only! */
+    t = ui64_rol(t, 16, &ov);
+    uuid->obj.time_mid =
+        (uuid_uint16_t)(ui64_i2n(ov) & 0x0000ffff); /* all 16 bit */
+    t = ui64_rol(t, 32, &ov);
+    uuid->obj.time_low =
+        (uuid_uint32_t)(ui64_i2n(ov) & 0xffffffff); /* all 32 bit */
+
+    return UUID_RC_OK;
+}
+
+/* INTERNAL: generate UUID version 1, clock part */
+static uuid_rc_t uuid_generate_v1_clock(uuid_t *uuid, unsigned int mode, va_list ap)
+{
+    /* FIXME */
+    return UUID_RC_OK;
+}
+
+/* INTERNAL: generate UUID version 1, node part */
+static uuid_rc_t uuid_generate_v1_node(uuid_t *uuid, unsigned int mode, va_list ap)
+{
+    /* FIXME */
+    return UUID_RC_OK;
+}
+
 /* INTERNAL: generate UUID version 1: time, clock and node based */
 static uuid_rc_t uuid_generate_v1(uuid_t *uuid, unsigned int mode, va_list ap)
 {
+    uuid_rc_t rc;
+
+    /* generate individual parts of v1 UUID */
+    if ((rc = uuid_generate_v1_time (uuid, mode, ap)) != UUID_RC_OK)
+        return rc;
+    if ((rc = uuid_generate_v1_clock(uuid, mode, ap)) != UUID_RC_OK)
+        return rc;
+    if ((rc = uuid_generate_v1_node (uuid, mode, ap)) != UUID_RC_OK)
+        return rc;
+
     /* brand with version and variant */
     uuid_brand(uuid, 1);
 
-    /* FIXME */
-
     return UUID_RC_OK;
 }
 

CVSTrac 2.0.1