OSSP CVS Repository

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

ossp-pkg/uuid/uuid.c 1.12 -> 1.13

--- uuid.c       2004/01/10 11:14:18     1.12
+++ uuid.c       2004/01/10 11:54:05     1.13
@@ -107,13 +107,18 @@
 #endif
 
 /* UUID binary representation according to UUID standards */
-struct uuid_st {
+typedef struct {
     uuid_uint32_t   time_low;
     uuid_uint16_t   time_mid;
     uuid_uint16_t   time_hi_and_version;
     uuid_uint8_t    clock_seq_hi_and_reserved;
     uuid_uint8_t    clock_seq_low;
     uuid_uint8_t    node[6];
+} uuid_obj_t;
+
+/* abstract data type (ADT) of API */
+struct uuid_st {
+    uuid_obj_t obj;
 };
 
 /* create UUID object */
@@ -154,13 +159,13 @@
         return UUID_RC_ARG;
 
     /* clear all octets to create "nil UUID" */
-    memset(uuid, '\0', sizeof(uuid_t));
+    memset((void *)&(uuid->obj), '\0', sizeof(uuid->obj));
 
     return UUID_RC_OK;
 }
 
 /* compare UUID objects */
-uuid_rc_t uuid_compare(uuid_t *a, uuid_t *b, int *result)
+uuid_rc_t uuid_compare(uuid_t *uuid1, uuid_t *uuid2, int *result)
 {
     int r;
 
@@ -176,31 +181,31 @@
     } while (0)
 
     /* special cases: NULL or equal UUIDs */
-    if (a == b)
+    if (uuid1 == uuid2)
         RESULT(0);
-    if (a == NULL && b == NULL)
+    if (uuid1 == NULL && uuid2 == NULL)
         RESULT(0);
-    if (a == NULL)
-        RESULT((uuid_isnil(b, &r), r) ? 0 : -1);
-    if (b == NULL)
-        RESULT((uuid_isnil(a, &r), r) ? 0 : 1);
+    if (uuid1 == NULL)
+        RESULT((uuid_isnil(uuid2, &r), r) ? 0 : -1);
+    if (uuid2 == NULL)
+        RESULT((uuid_isnil(uuid1, &r), r) ? 0 : 1);
 
     /* standard cases: regular different UUIDs */
-    if (a->time_low != b->time_low)
-        RESULT((a->time_low < b->time_low) ? -1 : 1);
-    if ((r = (int)a->time_mid
-           - (int)b->time_mid) != 0)
+    if (uuid1->obj.time_low != uuid2->obj.time_low)
+        RESULT((uuid1->obj.time_low < uuid2->obj.time_low) ? -1 : 1);
+    if ((r = (int)uuid1->obj.time_mid
+           - (int)uuid2->obj.time_mid) != 0)
         RESULT((r < 0) ? -1 : 1);
-    if ((r = (int)a->time_hi_and_version
-           - (int)b->time_hi_and_version) != 0)
+    if ((r = (int)uuid1->obj.time_hi_and_version
+           - (int)uuid2->obj.time_hi_and_version) != 0)
         RESULT((r < 0) ? -1 : 1);
-    if ((r = (int)a->clock_seq_hi_and_reserved
-           - (int)b->clock_seq_hi_and_reserved) != 0)
+    if ((r = (int)uuid1->obj.clock_seq_hi_and_reserved
+           - (int)uuid2->obj.clock_seq_hi_and_reserved) != 0)
         RESULT((r < 0) ? -1 : 1);
-    if ((r = (int)a->clock_seq_low
-           - (int)b->clock_seq_low) != 0)
+    if ((r = (int)uuid1->obj.clock_seq_low
+           - (int)uuid2->obj.clock_seq_low) != 0)
         RESULT((r < 0) ? -1 : 1);
-    if ((r = memcmp(a->node, b->node, sizeof(a->node))) != 0)
+    if ((r = memcmp(uuid1->obj.node, uuid2->obj.node, sizeof(uuid1->obj.node))) != 0)
         RESULT((r < 0) ? -1 : 1);
 
     /* default case: the keys are equal */
@@ -222,7 +227,7 @@
 
     /* a "nil UUID" is defined as all octets zero, so check for this case */
     *result = TRUE;
-    for (i = 0, ucp = (unsigned char *)uuid; i < UUID_LEN_BIN; i++) {
+    for (i = 0, ucp = (unsigned char *)&(uuid->obj); i < UUID_LEN_BIN; i++) {
         if (*ucp++ != '\0') {
             *result = FALSE;
             break;
@@ -232,7 +237,8 @@
     return UUID_RC_OK;
 }
 
-/* unpack UUID binary presentation into UUID object (allows in-place operation!) */
+/* unpack UUID binary presentation into UUID object
+   (allows in-place operation for internal efficiency!) */
 uuid_rc_t uuid_unpack(uuid_t *uuid, const void *buf)
 {
     const uuid_uint8_t *in;
@@ -252,32 +258,33 @@
     tmp32 = (tmp32 << 8) | *in++;
     tmp32 = (tmp32 << 8) | *in++;
     tmp32 = (tmp32 << 8) | *in++;
-    uuid->time_low = tmp32;
+    uuid->obj.time_low = tmp32;
 
     /* unpack "time_mid" field */
     tmp16 = *in++;
     tmp16 = (tmp16 << 8) | *in++;
-    uuid->time_mid = tmp16;
+    uuid->obj.time_mid = tmp16;
 
     /* unpack "time_hi_and_version" field */
     tmp16 = *in++;
     tmp16 = (tmp16 << 8) | *in++;
-    uuid->time_hi_and_version = tmp16;
+    uuid->obj.time_hi_and_version = tmp16;
 
     /* unpack "clock_seq_hi_and_reserved" field */
-    uuid->clock_seq_hi_and_reserved = *in++;
+    uuid->obj.clock_seq_hi_and_reserved = *in++;
 
     /* unpack "clock_seq_low" field */
-    uuid->clock_seq_low = *in++;
+    uuid->obj.clock_seq_low = *in++;
 
     /* unpack "node" field */
-    for (i = 0; i < sizeof(uuid->node); i++)
-        uuid->node[i] = *in++;
+    for (i = 0; i < sizeof(uuid->obj.node); i++)
+        uuid->obj.node[i] = *in++;
 
     return UUID_RC_OK;
 }
 
-/* pack UUID object into binary representation (allows in-place operation!) */
+/* pack UUID object into binary representation
+   (allows in-place operation for internal efficiency!) */
 uuid_rc_t uuid_pack(uuid_t *uuid, void **buf)
 {
     uuid_uint8_t *out;
@@ -298,31 +305,31 @@
     out = (uuid_uint8_t *)(*buf);
 
     /* pack "time_low" field */
-    tmp32 = uuid->time_low;
+    tmp32 = uuid->obj.time_low;
     out[3] = (uuid_uint8_t)(tmp32 & 0xff); tmp32 >>= 8;
     out[2] = (uuid_uint8_t)(tmp32 & 0xff); tmp32 >>= 8;
     out[1] = (uuid_uint8_t)(tmp32 & 0xff); tmp32 >>= 8;
     out[0] = (uuid_uint8_t)(tmp32 & 0xff);
 
     /* pack "time_mid" field */
-    tmp16 = uuid->time_mid;
+    tmp16 = uuid->obj.time_mid;
     out[5] = (uuid_uint8_t)(tmp16 & 0xff); tmp16 >>= 8;
     out[4] = (uuid_uint8_t)(tmp16 & 0xff);
 
     /* pack "time_hi_and_version" field */
-    tmp16 = uuid->time_hi_and_version;
+    tmp16 = uuid->obj.time_hi_and_version;
     out[7] = (uuid_uint8_t)(tmp16 & 0xff); tmp16 >>= 8;
     out[6] = (uuid_uint8_t)(tmp16 & 0xff);
 
     /* pack "clock_seq_hi_and_reserved" field */
-    out[8] = uuid->clock_seq_hi_and_reserved;
+    out[8] = uuid->obj.clock_seq_hi_and_reserved;
 
     /* pack "clock_seq_low" field */
-    out[9] = uuid->clock_seq_low;
+    out[9] = uuid->obj.clock_seq_low;
 
     /* pack "node" field */
-    for (i = 0; i < sizeof(uuid->node); i++)
-        out[10+i] = uuid->node[i];
+    for (i = 0; i < sizeof(uuid->obj.node); i++)
+        out[10+i] = uuid->obj.node[i];
 
     return UUID_RC_OK;
 }
@@ -374,22 +381,22 @@
         return UUID_RC_ARG;
 
     /* parse hex values of "time" parts */
-    uuid->time_low            = (uuid_uint32_t)strtoul(str,    NULL, 16);
-    uuid->time_mid            = (uuid_uint16_t)strtoul(str+9,  NULL, 16);
-    uuid->time_hi_and_version = (uuid_uint16_t)strtoul(str+14, NULL, 16);
+    uuid->obj.time_low            = (uuid_uint32_t)strtoul(str,    NULL, 16);
+    uuid->obj.time_mid            = (uuid_uint16_t)strtoul(str+9,  NULL, 16);
+    uuid->obj.time_hi_and_version = (uuid_uint16_t)strtoul(str+14, NULL, 16);
 
     /* parse hex values of "clock" parts */
     tmp16 = (uuid_uint16_t)strtoul(str+19, NULL, 16);
-    uuid->clock_seq_low             = (uuid_uint8_t)(tmp16 & 0xff); tmp16 >>= 8;
-    uuid->clock_seq_hi_and_reserved = (uuid_uint8_t)(tmp16 & 0xff);
+    uuid->obj.clock_seq_low             = (uuid_uint8_t)(tmp16 & 0xff); tmp16 >>= 8;
+    uuid->obj.clock_seq_hi_and_reserved = (uuid_uint8_t)(tmp16 & 0xff);
 
     /* parse hex values of "node" part */
     cp = str+24;
     hexbuf[2] = '\0';
-    for (i = 0; i < sizeof(uuid->node); i++) {
+    for (i = 0; i < sizeof(uuid->obj.node); i++) {
         hexbuf[0] = *cp++;
         hexbuf[1] = *cp++;
-        uuid->node[i] = strtoul(hexbuf, NULL, 16);
+        uuid->obj.node[i] = strtoul(hexbuf, NULL, 16);
     }
 
     return UUID_RC_OK;
@@ -410,17 +417,17 @@
     /* format UUID into string representation */
     sprintf(*str,
         "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-        (unsigned long)uuid->time_low,
-        (unsigned int)uuid->time_mid,
-        (unsigned int)uuid->time_hi_and_version,
-        (unsigned int)uuid->clock_seq_hi_and_reserved,
-        (unsigned int)uuid->clock_seq_low,
-        (unsigned int)uuid->node[0],
-        (unsigned int)uuid->node[1],
-        (unsigned int)uuid->node[2],
-        (unsigned int)uuid->node[3],
-        (unsigned int)uuid->node[4],
-        (unsigned int)uuid->node[5]);
+        (unsigned long)uuid->obj.time_low,
+        (unsigned int)uuid->obj.time_mid,
+        (unsigned int)uuid->obj.time_hi_and_version,
+        (unsigned int)uuid->obj.clock_seq_hi_and_reserved,
+        (unsigned int)uuid->obj.clock_seq_low,
+        (unsigned int)uuid->obj.node[0],
+        (unsigned int)uuid->obj.node[1],
+        (unsigned int)uuid->obj.node[2],
+        (unsigned int)uuid->obj.node[3],
+        (unsigned int)uuid->obj.node[4],
+        (unsigned int)uuid->obj.node[5]);
 
     return UUID_RC_OK;
 }
@@ -491,12 +498,12 @@
 static void uuid_brand(uuid_t *uuid, int version)
 {
     /* set version (as given) */
-    uuid->time_hi_and_version &= 0x0fff;
-    uuid->time_hi_and_version |= (((uuid_uint16_t)version & 0x0fff) << 12);
+    uuid->obj.time_hi_and_version &= 0x0fff;
+    uuid->obj.time_hi_and_version |= (((uuid_uint16_t)version & 0x0fff) << 12);
 
     /* set variant (always DCE 1.1 only) */
-    uuid->clock_seq_hi_and_reserved &= ~((0x03) << 6);
-    uuid->clock_seq_hi_and_reserved |= (0x02 << 6);
+    uuid->obj.clock_seq_hi_and_reserved &= ~((0x03) << 6);
+    uuid->obj.clock_seq_hi_and_reserved |= (0x02 << 6);
     return;
 }
 
@@ -555,8 +562,9 @@
             return rc;
         if ((rc = uuid_parse(uuid_object, ns)) != UUID_RC_OK)
             return rc;
-        uuid_pack(uuid_object, (void **)&uuid_object);
-        md5_update(md5, (void *)uuid_object, UUID_LEN_BIN);
+        uuid_octets = (void *)&(uuid_object->obj);
+        uuid_pack(uuid_object, &uuid_octets);
+        md5_update(md5, uuid_octets, UUID_LEN_BIN);
         uuid_destroy(uuid_object);
     }
     else {
@@ -579,7 +587,8 @@
     /* store MD5 result into UUID
        (requires MD5_LEN_BIN space, UUID_LEN_BIN space is available,
        and both are equal in size, so we are safe!) */
-    md5_store(md5, (void *)&uuid, NULL);
+    uuid_octets = (void *)&(uuid->obj);
+    md5_store(md5, &uuid_octets, NULL);
 
     /* destroy MD5 context */
     md5_destroy(md5);
@@ -587,7 +596,7 @@
     /* fulfill requirement of standard and convert UUID data into
        local/host byte order (this uses fact that uuid_unpack() is
        able to operate in-place!) */
-    uuid_unpack(uuid, (void *)uuid);
+    uuid_unpack(uuid, (void *)&(uuid->obj));
 
     /* brand UUID with version and variant */
     uuid_brand(uuid, 3);
@@ -599,7 +608,7 @@
 static uuid_rc_t uuid_generate_v4(uuid_t *uuid, unsigned int mode, va_list ap)
 {
     /* fill UUID with random data */
-    uuid_prng_getdata((void *)uuid, sizeof(uuid_t));
+    uuid_prng_getdata((void *)&(uuid->obj), sizeof(uuid->obj));
 
     /* brand UUID with version and variant */
     uuid_brand(uuid, 4);

CVSTrac 2.0.1