OSSP CVS Repository

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

ossp-pkg/uuid/uuid.c 1.52 -> 1.53

--- uuid.c       2005/08/30 20:34:35     1.52
+++ uuid.c       2005/08/31 14:28:28     1.53
@@ -92,35 +92,40 @@
 /* create UUID object */
 uuid_rc_t uuid_create(uuid_t **uuid)
 {
+    uuid_t *obj;
+
     /* argument sanity check */
     if (uuid == NULL)
         return UUID_RC_ARG;
 
     /* allocate UUID object */
-    if ((*uuid = (uuid_t *)malloc(sizeof(uuid_t))) == NULL)
+    if ((obj = (uuid_t *)malloc(sizeof(uuid_t))) == NULL)
         return UUID_RC_MEM;
 
-    /* set UUID object initially to "Nil UUID" */
-    uuid_load(*uuid, "nil");
-
-    /* create PRNG and MD5 sub-objects */
-    if (prng_create(&(*uuid)->prng) != PRNG_RC_OK)
+    /* create PRNG, MD5 and SHA1 sub-objects */
+    if (prng_create(&obj->prng) != PRNG_RC_OK)
         return UUID_RC_INT;
-    if (md5_create(&(*uuid)->md5) != MD5_RC_OK)
+    if (md5_create(&obj->md5) != MD5_RC_OK)
         return UUID_RC_INT;
-    if (sha1_create(&(*uuid)->sha1) != SHA1_RC_OK)
+    if (sha1_create(&obj->sha1) != SHA1_RC_OK)
         return UUID_RC_INT;
 
+    /* set UUID object initially to "Nil UUID" */
+    uuid_load(obj, "nil");
+
     /* resolve MAC address for insertion into node field of UUIDs */
-    if (!mac_address((unsigned char *)((*uuid)->mac), sizeof((*uuid)->mac))) {
-        memset((*uuid)->mac, '\0', sizeof((*uuid)->mac));
-        (*uuid)->mac[0] = BM_OCTET(1,0,0,0,0,0,0,0);
+    if (!mac_address((unsigned char *)(obj->mac), sizeof(obj->mac))) {
+        memset(obj->mac, '\0', sizeof(obj->mac));
+        obj->mac[0] = BM_OCTET(1,0,0,0,0,0,0,0);
     }
 
     /* initialize time attributes */
-    (*uuid)->time_last.tv_sec  = 0;
-    (*uuid)->time_last.tv_usec = 0;
-    (*uuid)->time_seq = 0;
+    obj->time_last.tv_sec  = 0;
+    obj->time_last.tv_usec = 0;
+    obj->time_seq = 0;
+
+    /* store result object */
+    *uuid = obj;
 
     return UUID_RC_OK;
 }
@@ -142,6 +147,36 @@
 
     return UUID_RC_OK;
 }
+
+/* clone UUID object */
+uuid_rc_t uuid_clone(uuid_t *uuid, uuid_t **clone)
+{
+    uuid_t *obj;
+
+    /* argument sanity check */
+    if (uuid == NULL || uuid_clone == NULL)
+        return UUID_RC_ARG;
+
+    /* allocate UUID object */
+    if ((obj = (uuid_t *)malloc(sizeof(uuid_t))) == NULL)
+        return UUID_RC_MEM;
+
+    /* clone entire internal state */
+    memcpy(obj, uuid, sizeof(uuid));
+
+    /* re-initialize with new PRNG, MD5 and SHA1 sub-objects */
+    if (prng_create(&obj->prng) != PRNG_RC_OK)
+        return UUID_RC_INT;
+    if (md5_create(&obj->md5) != MD5_RC_OK)
+        return UUID_RC_INT;
+    if (sha1_create(&obj->sha1) != SHA1_RC_OK)
+        return UUID_RC_INT;
+
+    /* store result object */
+    *clone = obj;
+
+    return UUID_RC_OK;
+}
 
 /* check whether UUID object represents "Nil UUID" */
 uuid_rc_t uuid_isnil(const uuid_t *uuid, int *result)

CVSTrac 2.0.1