OSSP CVS Repository

ossp - Check-in [5039]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 5039
Date: 2005-Mar-29 21:01:41 (local)
2005-Mar-29 19:01:41 (UTC)
User:rse
Branch:
Comment: Cleanup the source code even more by following a large set of FlexeLint's suggestions.
Tickets:
Inspections:
Files:
ossp-pkg/uuid/ChangeLog      1.71 -> 1.72     4 inserted, 0 deleted
ossp-pkg/uuid/uuid.c      added-> 1.51
ossp-pkg/uuid/uuid.h.in      1.6 -> 1.7     4 inserted, 4 deleted
ossp-pkg/uuid/uuid_ac.h      1.3 -> 1.4     1 inserted, 1 deleted
ossp-pkg/uuid/uuid_bm.h      1.4 -> 1.5     3 inserted, 3 deleted
ossp-pkg/uuid/uuid_cli.c      1.18 -> 1.19     4 inserted, 4 deleted
ossp-pkg/uuid/uuid_dce.c      1.2 -> 1.3     14 inserted, 11 deleted
ossp-pkg/uuid/uuid_mac.c      1.6 -> 1.7     2 inserted, 2 deleted
ossp-pkg/uuid/uuid_md5.c      added-> 1.11
ossp-pkg/uuid/uuid_prng.c      1.4 -> 1.5     2 inserted, 2 deleted
ossp-pkg/uuid/uuid_sha1.c      1.1 -> 1.2     1 inserted, 2 deleted
ossp-pkg/uuid/uuid_str.c      1.4 -> 1.5     6 inserted, 4 deleted
ossp-pkg/uuid/uuid_ui64.c      1.3 -> 1.4     15 inserted, 11 deleted

ossp-pkg/uuid/ChangeLog 1.71 -> 1.72

--- ChangeLog    2005/03/06 11:29:25     1.71
+++ ChangeLog    2005/03/29 19:01:41     1.72
@@ -13,6 +13,10 @@
 
   Changes between 1.2.0 and 1.2.1 (23-Jan-2005 to xx-Mar-2005)
 
+   o Cleanup the source code even more by following a large
+     set of FlexeLint's suggestions.
+     [Ralf S. Engelschall]
+
    o Fixed generated "section" number in uuid-config(1).
      [Piotr Roszatycki <dexter@debian.org>]
 


ossp-pkg/uuid/uuid.c -> 1.51

*** /dev/null    Mon Apr 29 20:33:00 2024
--- -    Mon Apr 29 20:34:25 2024
***************
*** 0 ****
--- 1,1032 ----
+ /*
+ **  OSSP uuid - Universally Unique Identifier
+ **  Copyright (c) 2004-2005 Ralf S. Engelschall <rse@engelschall.com>
+ **  Copyright (c) 2004-2005 The OSSP Project <http://www.ossp.org/>
+ **
+ **  This file is part of OSSP uuid, a library for the generation
+ **  of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
+ **
+ **  Permission to use, copy, modify, and distribute this software for
+ **  any purpose with or without fee is hereby granted, provided that
+ **  the above copyright notice and this permission notice appear in all
+ **  copies.
+ **
+ **  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ **  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ **  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ **  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
+ **  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ **  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ **  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ **  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ **  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ **  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ **  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ **  SUCH DAMAGE.
+ **
+ **  uuid.c: library API implementation
+ */
+ 
+ /* system headers */
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <stdarg.h>
+ #include <string.h>
+ #include <unistd.h>
+ #include <ctype.h>
+ #include <fcntl.h>
+ #include <time.h>
+ #include <sys/time.h>
+ #include <sys/types.h>
+ 
+ /* own headers */
+ #include "config.h"
+ #include "uuid.h"
+ #include "uuid_vers.h"
+ #include "uuid_md5.h"
+ #include "uuid_sha1.h"
+ #include "uuid_prng.h"
+ #include "uuid_mac.h"
+ #include "uuid_ui64.h"
+ #include "uuid_str.h"
+ #include "uuid_bm.h"
+ #include "uuid_ac.h"
+ 
+ /* maximum number of 100ns ticks of the actual resolution of system clock
+    (which in our case is 1us (= 1000ns) because we use gettimeofday(2) */
+ #define UUIDS_PER_TICK 10
+ 
+ /* time offset between UUID and Unix Epoch time according to standards.
+    (UUID UTC base time is October 15, 1582
+     Unix UTC base time is January  1, 1970) */
+ #define UUID_TIMEOFFSET "01B21DD213814000"
+ 
+ /* IEEE 802 MAC address encoding/decoding bit fields */
+ #define IEEE_MAC_MCBIT BM_OCTET(0,0,0,0,0,0,0,1)
+ #define IEEE_MAC_LOBIT BM_OCTET(0,0,0,0,0,0,1,0)
+ 
+ /* IEEE 802 MAC address octet length */
+ #define IEEE_MAC_OCTETS 6
+ 
+ /* UUID binary representation according to UUID standards */
+ typedef struct {
+     uuid_uint32_t  time_low;                  /* bits  0-31 of time field */
+     uuid_uint16_t  time_mid;                  /* bits 32-47 of time field */
+     uuid_uint16_t  time_hi_and_version;       /* bits 48-59 of time field plus 4 bit version */
+     uuid_uint8_t   clock_seq_hi_and_reserved; /* bits  8-13 of clock sequence field plus 2 bit variant */
+     uuid_uint8_t   clock_seq_low;             /* bits  0-7  of clock sequence field */
+     uuid_uint8_t   node[IEEE_MAC_OCTETS];     /* bits  0-47 of node MAC address */
+ } uuid_obj_t;
+ 
+ /* abstract data type (ADT) of API */
+ struct uuid_st {
+     uuid_obj_t     obj;                       /* inlined UUID object */
+     prng_t        *prng;                      /* RPNG sub-object */
+     md5_t         *md5;                       /* MD5 sub-object */
+     sha1_t        *sha1;                      /* SHA-1 sub-object */
+     uuid_uint8_t   mac[IEEE_MAC_OCTETS];      /* pre-determined MAC address */
+     struct timeval time_last;                 /* last retrieved timestamp */
+     unsigned long  time_seq;                  /* last timestamp sequence counter */
+ };
+ 
+ /* create UUID object */
+ uuid_rc_t uuid_create(uuid_t **uuid)
+ {
+     /* argument sanity check */
+     if (uuid == NULL)
+         return UUID_RC_ARG;
+ 
+     /* allocate UUID object */
+     if ((*uuid = (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)
+         return UUID_RC_INT;
+     if (md5_create(&(*uuid)->md5) != MD5_RC_OK)
+         return UUID_RC_INT;
+     if (sha1_create(&(*uuid)->sha1) != SHA1_RC_OK)
+         return UUID_RC_INT;
+ 
+     /* 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);
+     }
+ 
+     /* initialize time attributes */
+     (*uuid)->time_last.tv_sec  = 0;
+     (*uuid)->time_last.tv_usec = 0;
+     (*uuid)->time_seq = 0;
+ 
+     return UUID_RC_OK;
+ }
+ 
+ /* destroy UUID object */
+ uuid_rc_t uuid_destroy(uuid_t *uuid)
+ {
+     /* argument sanity check */
+     if (uuid == NULL)
+         return UUID_RC_ARG;
+ 
+     /* destroy PRNG, MD5 and SHA-1 sub-objects */
+     prng_destroy(uuid->prng);
+     md5_destroy(uuid->md5);
+     sha1_destroy(uuid->sha1);
+ 
+     /* free UUID object */
+     free(uuid);
+ 
+     return UUID_RC_OK;
+ }
+ 
+ /* check whether UUID object represents "Nil UUID" */
+ uuid_rc_t uuid_isnil(const uuid_t *uuid, int *result)
+ {
+     const unsigned char *ucp;
+     int i;
+ 
+     /* sanity check argument(s) */
+     if (uuid == NULL || result == NULL)
+         return UUID_RC_ARG;
+ 
+     /* a "Nil UUID" is defined as all octets zero, so check for this case */
+     *result = UUID_TRUE;
+     for (i = 0, ucp = (unsigned char *)&(uuid->obj); i < UUID_LEN_BIN; i++) {
+         if (*ucp++ != '\0') {
+             *result = UUID_FALSE;
+             break;
+         }
+     }
+ 
+     return UUID_RC_OK;
+ }
+ 
+ /* compare UUID objects */
+ uuid_rc_t uuid_compare(const uuid_t *uuid1, const uuid_t *uuid2, int *result)
+ {
+     int r;
+ 
+     /* argument sanity check */
+     if (result == NULL)
+         return UUID_RC_ARG;
+ 
+     /* convenience macro for setting result */
+ #define RESULT(r) \
+     /*lint -save -e801 -e717*/ \
+     do { \
+         *result = (r); \
+         goto result_exit; \
+     } while (0) \
+     /*lint -restore*/
+ 
+     /* special cases: NULL or equal UUIDs */
+     if (uuid1 == uuid2)
+         RESULT(0);
+     if (uuid1 == NULL && uuid2 == NULL)
+         RESULT(0);
+     if (uuid1 == NULL)
+         RESULT((uuid_isnil(uuid2, &r) == UUID_RC_OK ? r : 0) ? 0 : -1);
+     if (uuid2 == NULL)
+         RESULT((uuid_isnil(uuid1, &r) == UUID_RC_OK ? r : 0) ? 0 : 1);
+ 
+     /* standard cases: regular different UUIDs */
+     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)uuid1->obj.time_hi_and_version
+            - (int)uuid2->obj.time_hi_and_version) != 0)
+         RESULT((r < 0) ? -1 : 1);
+     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)uuid1->obj.clock_seq_low
+            - (int)uuid2->obj.clock_seq_low) != 0)
+         RESULT((r < 0) ? -1 : 1);
+     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 */
+     *result = 0;
+ 
+     result_exit:
+     return UUID_RC_OK;
+ }
+ 
+ /* INTERNAL: unpack UUID binary presentation into UUID object
+    (allows in-place operation for internal efficiency!) */
+ static uuid_rc_t uuid_import_bin(uuid_t *uuid, const void *data_ptr, size_t data_len)
+ {
+     const uuid_uint8_t *in;
+     uuid_uint32_t tmp32;
+     uuid_uint16_t tmp16;
+     unsigned int i;
+ 
+     /* sanity check argument(s) */
+     if (uuid == NULL || data_ptr == NULL || data_len < UUID_LEN_BIN)
+         return UUID_RC_ARG;
+ 
+     /* treat input data buffer as octet stream */
+     in = (const uuid_uint8_t *)data_ptr;
+ 
+     /* unpack "time_low" field */
+     tmp32 = *in++;
+     tmp32 = (tmp32 << 8) | *in++;
+     tmp32 = (tmp32 << 8) | *in++;
+     tmp32 = (tmp32 << 8) | *in++;
+     uuid->obj.time_low = tmp32;
+ 
+     /* unpack "time_mid" field */
+     tmp16 = *in++;
+     tmp16 = (uuid_uint16_t)(tmp16 << 8) | *in++;
+     uuid->obj.time_mid = tmp16;
+ 
+     /* unpack "time_hi_and_version" field */
+     tmp16 = *in++;
+     tmp16 = (uuid_uint16_t)(tmp16 << 8) | *in++;
+     uuid->obj.time_hi_and_version = tmp16;
+ 
+     /* unpack "clock_seq_hi_and_reserved" field */
+     uuid->obj.clock_seq_hi_and_reserved = *in++;
+ 
+     /* unpack "clock_seq_low" field */
+     uuid->obj.clock_seq_low = *in++;
+ 
+     /* unpack "node" field */
+     for (i = 0; i < sizeof(uuid->obj.node); i++)
+         uuid->obj.node[i] = *in++;
+ 
+     return UUID_RC_OK;
+ }
+ 
+ /* INTERNAL: pack UUID object into binary representation
+    (allows in-place operation for internal efficiency!) */
+ static uuid_rc_t uuid_export_bin(const uuid_t *uuid, void **data_ptr, size_t *data_len)
+ {
+     uuid_uint8_t *out;
+     uuid_uint32_t tmp32;
+     uuid_uint16_t tmp16;
+     unsigned int i;
+ 
+     /* sanity check argument(s) */
+     if (uuid == NULL || data_ptr == NULL)
+         return UUID_RC_ARG;
+ 
+     /* optionally allocate octet data buffer */
+     if (*data_ptr == NULL) {
+         if ((*data_ptr = malloc(sizeof(uuid_t))) == NULL)
+             return UUID_RC_MEM;
+         if (data_len != NULL)
+             *data_len = UUID_LEN_BIN;
+     }
+     else {
+         if (data_len == NULL)
+             return UUID_RC_ARG;
+         if (*data_len < UUID_LEN_BIN)
+             return UUID_RC_MEM;
+         *data_len = UUID_LEN_BIN;
+     }
+ 
+     /* treat output data buffer as octet stream */
+     out = (uuid_uint8_t *)(*data_ptr);
+ 
+     /* pack "time_low" field */
+     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->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->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->obj.clock_seq_hi_and_reserved;
+ 
+     /* pack "clock_seq_low" field */
+     out[9] = uuid->obj.clock_seq_low;
+ 
+     /* pack "node" field */
+     for (i = 0; i < sizeof(uuid->obj.node); i++)
+         out[10+i] = uuid->obj.node[i];
+ 
+     return UUID_RC_OK;
+ }
+ 
+ /* INTERNAL: check for valid UUID string representation syntax */
+ static int uuid_isstr(const char *str, size_t str_len)
+ {
+     int i;
+     const char *cp;
+ 
+     /* example reference:
+        f81d4fae-7dec-11d0-a765-00a0c91e6bf6
+        012345678901234567890123456789012345
+        0         1         2         3       */
+     if (str == NULL)
+         return UUID_FALSE;
+     if (str_len == 0)
+         str_len = strlen(str);
+     if (str_len < UUID_LEN_STR)
+         return UUID_FALSE;
+     for (i = 0, cp = str; i < UUID_LEN_STR; i++, cp++) {
+         if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) {
+             if (*cp == '-')
+                 continue;
+             else
+                 return UUID_FALSE;
+         }
+         if (!isxdigit((int)(*cp)))
+             return UUID_FALSE;
+     }
+     return UUID_TRUE;
+ }
+ 
+ /* INTERNAL: import UUID object from string representation */
+ static uuid_rc_t uuid_import_str(uuid_t *uuid, const void *data_ptr, size_t data_len)
+ {
+     uuid_uint16_t tmp16;
+     const char *cp;
+     char hexbuf[3];
+     const char *str;
+     unsigned int i;
+ 
+     /* sanity check argument(s) */
+     if (uuid == NULL || data_ptr == NULL || data_len < UUID_LEN_STR)
+         return UUID_RC_ARG;
+ 
+     /* check for correct UUID string representation syntax */
+     str = (const char *)data_ptr;
+     if (!uuid_isstr(str, 0))
+         return UUID_RC_ARG;
+ 
+     /* parse hex values of "time" parts */
+     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->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->obj.node); i++) {
+         hexbuf[0] = *cp++;
+         hexbuf[1] = *cp++;
+         uuid->obj.node[i] = (uuid_uint8_t)strtoul(hexbuf, NULL, 16);
+     }
+ 
+     return UUID_RC_OK;
+ }
+ 
+ /* INTERNAL: export UUID object to string representation */
+ static uuid_rc_t uuid_export_str(const uuid_t *uuid, void **data_ptr, size_t *data_len)
+ {
+     char *data_buf;
+ 
+     /* sanity check argument(s) */
+     if (uuid == NULL || data_ptr == NULL)
+         return UUID_RC_ARG;
+ 
+     /* determine output buffer */
+     if (*data_ptr == NULL) {
+         if ((data_buf = (void *)malloc(UUID_LEN_STR+1)) == NULL)
+             return UUID_RC_MEM;
+         if (data_len != NULL)
+             *data_len = UUID_LEN_STR+1;
+     }
+     else {
+         data_buf = (char *)(*data_ptr);
+         if (data_len == NULL)
+             return UUID_RC_ARG;
+         if (*data_len < UUID_LEN_STR+1)
+             return UUID_RC_MEM;
+         *data_len = UUID_LEN_STR+1;
+     }
+ 
+     /* format UUID into string representation */
+     if (str_snprintf(data_buf, UUID_LEN_STR+1,
+         "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+         (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]) != UUID_LEN_STR) {
+         if (*data_ptr == NULL)
+             free(data_buf);
+         return UUID_RC_INT;
+     }
+ 
+     /* pass back new buffer if locally allocated */
+     if (*data_ptr == NULL)
+         *data_ptr = data_buf;
+ 
+     return UUID_RC_OK;
+ }
+ 
+ /* decoding tables */
+ static struct {
+     uuid_uint8_t num;
+     const char *desc;
+ } uuid_dectab_variant[] = {
+     { BM_OCTET(0,0,0,0,0,0,0,0), "reserved (NCS backward compatible)" },
+     { BM_OCTET(1,0,0,0,0,0,0,0), "DCE 1.1, ISO/IEC 11578:1996" },
+     { BM_OCTET(1,1,0,0,0,0,0,0), "reserved (Microsoft GUID)" },
+     { BM_OCTET(1,1,1,0,0,0,0,0), "reserved (future use)" }
+ };
+ static struct {
+     int num;
+     const char *desc;
+ } uuid_dectab_version[] = {
+     { 1, "time and node based" },
+     { 3, "name based, MD5" },
+     { 4, "random data based" },
+     { 5, "name based, SHA-1" }
+ };
+ 
+ /* INTERNAL: dump UUID object as descriptive text */
+ static uuid_rc_t uuid_export_txt(const uuid_t *uuid, void **data_ptr, size_t *data_len)
+ {
+     uuid_rc_t rc;
+     char **out;
+     char *out_ptr;
+     size_t out_len;
+     const char *version;
+     const char *variant;
+     char *content;
+     int isnil;
+     uuid_uint8_t tmp8;
+     uuid_uint16_t tmp16;
+     uuid_uint32_t tmp32;
+     uuid_uint8_t tmp_bin[UUID_LEN_BIN];
+     char tmp_str[UUID_LEN_STR+1];
+     void *tmp_ptr;
+     size_t tmp_len;
+     ui64_t t;
+     ui64_t t_offset;
+     int t_nsec;
+     int t_usec;
+     time_t t_sec;
+     char t_buf[19+1]; /* YYYY-MM-DD HH:MM:SS */
+     struct tm *tm;
+     int i;
+ 
+     /* sanity check argument(s) */
+     if (uuid == NULL || data_ptr == NULL)
+         return UUID_RC_ARG;
+ 
+     /* initialize output buffer */
+     out_ptr = NULL;
+     out = &out_ptr;
+ 
+     /* check for special case of "Nil UUID" */
+     if ((rc = uuid_isnil(uuid, &isnil)) != UUID_RC_OK)
+         return rc;
+ 
+     /* decode into string representation */
+     tmp_ptr = (void *)&tmp_str;
+     tmp_len = sizeof(tmp_str);
+     if ((rc = uuid_export(uuid, UUID_FMT_STR, &tmp_ptr, &tmp_len)) != UUID_RC_OK)
+         return rc;
+     str_rsprintf(out, "UUID:    %s\n", tmp_str);
+ 
+     /* decode UUID variant */
+     tmp8 = uuid->obj.clock_seq_hi_and_reserved;
+     if (isnil)
+         variant = "n.a.";
+     else {
+         variant = "unknown";
+         for (i = 7; i >= 0; i--) {
+             if ((tmp8 & BM_BIT(i,1)) == 0) {
+                 tmp8 &= ~BM_MASK(i,0);
+                 break;
+             }
+         }
+         for (i = 0; i < (int)(sizeof(uuid_dectab_variant)/sizeof(uuid_dectab_variant[0])); i++) {
+             if (uuid_dectab_variant[i].num == tmp8) {
+                 variant = uuid_dectab_variant[i].desc;
+                 break;
+             }
+         }
+     }
+     str_rsprintf(out, "variant: %s\n", variant);
+ 
+     /* decode UUID version */
+     tmp16 = (BM_SHR(uuid->obj.time_hi_and_version, 12) & BM_MASK(3,0));
+     if (isnil)
+         version = "n.a.";
+     else {
+         version = "unknown";
+         for (i = 0; i < (int)(sizeof(uuid_dectab_version)/sizeof(uuid_dectab_version[0])); i++) {
+             if (uuid_dectab_version[i].num == (int)tmp16) {
+                 version = uuid_dectab_version[i].desc;
+                 break;
+             }
+         }
+     }
+     str_rsprintf(out, "version: %d (%s)\n", (int)tmp16, version);
+ 
+     /*
+      * decode UUID content
+      */
+ 
+     if (tmp8 == BM_OCTET(1,0,0,0,0,0,0,0) && tmp16 == 1) {
+         /* decode DCE 1.1 version 1 UUID */
+ 
+         /* decode system time */
+         t = ui64_rol(ui64_n2i((unsigned long)(uuid->obj.time_hi_and_version & BM_MASK(11,0))), 48, NULL),
+         t = ui64_or(t, ui64_rol(ui64_n2i((unsigned long)(uuid->obj.time_mid)), 32, NULL));
+         t = ui64_or(t, ui64_n2i((unsigned long)(uuid->obj.time_low)));
+         t_offset = ui64_s2i(UUID_TIMEOFFSET, NULL, 16);
+         t = ui64_sub(t, t_offset, NULL);
+         t = ui64_divn(t, 10, &t_nsec);
+         t = ui64_divn(t, 1000000, &t_usec);
+         t_sec = (time_t)ui64_i2n(t);
+         tm = gmtime(&t_sec);
+         strftime(t_buf, sizeof(t_buf), "%Y-%m-%d %H:%M:%S", tm);
+         str_rsprintf(out, "content: time:  %s.%06d.%d UTC\n", t_buf, t_usec, t_nsec);
+ 
+         /* decode clock sequence */
+         tmp32 = ((uuid->obj.clock_seq_hi_and_reserved & BM_MASK(5,0)) << 8)
+                 + uuid->obj.clock_seq_low;
+         str_rsprintf(out, "         clock: %ld (usually random)\n", (long)tmp32);
+ 
+         /* decode node MAC address */
+         str_rsprintf(out, "         node:  %02x:%02x:%02x:%02x:%02x:%02x (%s %s)\n",
+             (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],
+             (uuid->obj.node[0] & IEEE_MAC_LOBIT ? "local" : "global"),
+             (uuid->obj.node[0] & IEEE_MAC_MCBIT ? "multicast" : "unicast"));
+     }
+     else {
+         /* decode anything else as hexadecimal byte-string only */
+ 
+         /* determine annotational hint */
+         content = "not decipherable: unknown UUID version";
+         if (isnil)
+             content = "special case: DCE 1.1 Nil UUID";
+         else if (tmp16 == 3)
+             content = "not decipherable: MD5 message digest only";
+         else if (tmp16 == 4)
+             content = "no semantics: random data only";
+         else if (tmp16 == 5)
+             content = "not decipherable: truncated SHA-1 message digest only";
+ 
+         /* pack UUID into binary representation */
+         tmp_ptr = (void *)&tmp_bin;
+         tmp_len = sizeof(tmp_bin);
+         if ((rc = uuid_export(uuid, UUID_FMT_BIN, &tmp_ptr, &tmp_len)) != UUID_RC_OK)
+             return rc;
+ 
+         /* mask out version and variant parts */
+         tmp_bin[6] &= BM_MASK(3,0);
+         tmp_bin[8] &= BM_MASK(5,0);
+ 
+         /* dump as colon-seperated hexadecimal byte-string */
+         str_rsprintf(out,
+             "content: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n"
+             "         (%s)\n",
+             (unsigned int)tmp_bin[0],  (unsigned int)tmp_bin[1],  (unsigned int)tmp_bin[2],
+             (unsigned int)tmp_bin[3],  (unsigned int)tmp_bin[4],  (unsigned int)tmp_bin[5],
+             (unsigned int)tmp_bin[6],  (unsigned int)tmp_bin[7],  (unsigned int)tmp_bin[8],
+             (unsigned int)tmp_bin[9],  (unsigned int)tmp_bin[10], (unsigned int)tmp_bin[11],
+             (unsigned int)tmp_bin[12], (unsigned int)tmp_bin[13], (unsigned int)tmp_bin[14],
+             (unsigned int)tmp_bin[15], content);
+     }
+ 
+     /* provide result */
+     out_len = strlen(out_ptr)+1;
+     if (*data_ptr == NULL) {
+         *data_ptr = (void *)out_ptr;
+         if (data_len != NULL)
+             *data_len = out_len;
+     }
+     else {
+         if (data_len == NULL)
+             return UUID_RC_ARG;
+         if (*data_len < out_len)
+             return UUID_RC_MEM;
+         memcpy(*data_ptr, out_ptr, out_len);
+     }
+ 
+     return UUID_RC_OK;
+ }
+ 
+ /* UUID importing */
+ uuid_rc_t uuid_import(uuid_t *uuid, uuid_fmt_t fmt, const void *data_ptr, size_t data_len)
+ {
+     uuid_rc_t rc;
+ 
+     /* sanity check argument(s) */
+     if (uuid == NULL || data_ptr == NULL)
+         return UUID_RC_ARG;
+ 
+     /* dispatch into format-specific functions */
+     switch (fmt) {
+         case UUID_FMT_BIN: rc = uuid_import_bin(uuid, data_ptr, data_len); break;
+         case UUID_FMT_STR: rc = uuid_import_str(uuid, data_ptr, data_len); break;
+         case UUID_FMT_TXT: rc = UUID_RC_IMP; /* not implemented */ break;
+         default:           rc = UUID_RC_ARG;
+     }
+ 
+     return rc;
+ }
+ 
+ /* UUID exporting */
+ uuid_rc_t uuid_export(const uuid_t *uuid, uuid_fmt_t fmt, void **data_ptr, size_t *data_len)
+ {
+     uuid_rc_t rc;
+ 
+     /* sanity check argument(s) */
+     if (uuid == NULL || data_ptr == NULL)
+         return UUID_RC_ARG;
+ 
+     /* dispatch into format-specific functions */
+     switch (fmt) {
+         case UUID_FMT_BIN: rc = uuid_export_bin(uuid, data_ptr, data_len); break;
+         case UUID_FMT_STR: rc = uuid_export_str(uuid, data_ptr, data_len); break;
+         case UUID_FMT_TXT: rc = uuid_export_txt(uuid, data_ptr, data_len); break;
+         default:           rc = UUID_RC_ARG;
+     }
+ 
+     return rc;
+ }
+ 
+ /* INTERNAL: brand UUID with version and variant */
+ static void uuid_brand(uuid_t *uuid, unsigned int version)
+ {
+     /* set version (as given) */
+     uuid->obj.time_hi_and_version &= BM_MASK(11,0);
+     uuid->obj.time_hi_and_version |= (uuid_uint16_t)BM_SHL(version, 12);
+ 
+     /* set variant (always DCE 1.1 only) */
+     uuid->obj.clock_seq_hi_and_reserved &= BM_MASK(5,0);
+     uuid->obj.clock_seq_hi_and_reserved |= BM_SHL(0x02, 6);
+     return;
+ }
+ 
+ /* INTERNAL: generate UUID version 1: time, clock and node based */
+ static uuid_rc_t uuid_make_v1(uuid_t *uuid, unsigned int mode, va_list ap)
+ {
+     struct timeval time_now;
+ #ifdef HAVE_NANOSLEEP
+     struct timespec ts;
+ #else
+     struct timeval tv;
+ #endif
+     ui64_t t;
+     ui64_t offset;
+     ui64_t ov;
+     uuid_uint16_t clck;
+ 
+     /*
+      *  GENERATE TIME
+      */
+ 
+     /* determine current system time and sequence counter */
+     for (;;) {
+         /* determine current system time */
+         if (gettimeofday(&time_now, NULL) == -1)
+             return UUID_RC_SYS;
+ 
+         /* check whether system time changed since last retrieve */
+         if (!(   time_now.tv_sec  == uuid->time_last.tv_sec
+               && time_now.tv_usec == uuid->time_last.tv_usec)) {
+             /* reset time sequence counter and continue */
+             uuid->time_seq = 0;
+             break;
+         }
+ 
+         /* until we are out of UUIDs per tick, increment
+            the time/tick sequence counter and continue */
+         if (uuid->time_seq < UUIDS_PER_TICK) {
+             uuid->time_seq++;
+             break;
+         }
+ 
+         /* stall the UUID generation until the system clock (which
+            has a gettimeofday(2) resolution of 1us) catches up */
+ #ifdef HAVE_NANOSLEEP
+         /* sleep for 500ns (1/2us) */
+         ts.tv_sec  = 0;
+         ts.tv_nsec = 500;
+         nanosleep(&ts, NULL);
+ #else
+         /* sleep for 1000ns (1us) */
+         tv.tv_sec  = 0;
+         tv.tv_usec = 1;
+         select(0, NULL, NULL, NULL, &tv);
+ #endif
+     }
+ 
+     /* convert from timeval (sec,usec) to OSSP ui64 (100*nsec) format */
+     t = ui64_n2i((unsigned long)time_now.tv_sec);
+     t = ui64_muln(t, 1000000, NULL);
+     t = ui64_addn(t, (int)time_now.tv_usec, NULL);
+     t = ui64_muln(t, 10, NULL);
+ 
+     /* adjust for offset between UUID and Unix Epoch time */
+     offset = ui64_s2i(UUID_TIMEOFFSET, NULL, 16);
+     t = ui64_add(t, offset, NULL);
+ 
+     /* compensate for low resolution system clock by adding
+        the time/tick sequence counter */
+     if (uuid->time_seq > 0)
+         t = ui64_addn(t, (int)uuid->time_seq, 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 */
+ 
+     /*
+      *  GENERATE CLOCK
+      */
+ 
+     /* retrieve current clock sequence */
+     clck = ((uuid->obj.clock_seq_hi_and_reserved & BM_MASK(5,0)) << 8)
+            + uuid->obj.clock_seq_low;
+ 
+     /* generate new random clock sequence (initially or if the
+        time has stepped backwards) or else just increase it */
+     if (   clck == 0
+         || (   time_now.tv_sec < uuid->time_last.tv_sec
+             || (   time_now.tv_sec == uuid->time_last.tv_sec
+                 && time_now.tv_usec < uuid->time_last.tv_usec)))
+         prng_data(uuid->prng, (void *)&clck, sizeof(clck));
+     else
+         clck++;
+     clck %= BM_POW2(14);
+ 
+     /* store back new clock sequence */
+     uuid->obj.clock_seq_hi_and_reserved =
+         (uuid->obj.clock_seq_hi_and_reserved & BM_MASK(7,6))
+         | (uuid_uint8_t)((clck >> 8) & 0xff);
+     uuid->obj.clock_seq_low =
+         (uuid_uint8_t)(clck & 0xff);
+ 
+     /*
+      *  GENERATE NODE
+      */
+ 
+     if ((mode & UUID_MAKE_MC) || (uuid->mac[0] & BM_OCTET(1,0,0,0,0,0,0,0))) {
+         /* generate random IEEE 802 local multicast MAC address */
+         if (prng_data(uuid->prng, (void *)&(uuid->obj.node), sizeof(uuid->obj.node)) != PRNG_RC_OK)
+             return UUID_RC_INT;
+         uuid->obj.node[0] |= IEEE_MAC_MCBIT;
+         uuid->obj.node[0] |= IEEE_MAC_LOBIT;
+     }
+     else {
+         /* use real regular MAC address */
+         memcpy(uuid->obj.node, uuid->mac, sizeof(uuid->mac));
+     }
+ 
+     /*
+      *  FINISH
+      */
+ 
+     /* remember current system time for next iteration */
+     uuid->time_last.tv_sec  = time_now.tv_sec;
+     uuid->time_last.tv_usec = time_now.tv_usec;
+ 
+     /* brand with version and variant */
+     uuid_brand(uuid, 1);
+ 
+     return UUID_RC_OK;
+ }
+ 
+ /* INTERNAL: pre-defined UUID values.
+    (defined as network byte ordered octet stream) */
+ static struct {
+     char *name;
+     uuid_uint8_t uuid[UUID_LEN_BIN];
+ } uuid_value_table[] = {
+     { "nil",     /* 00000000-0000-0000-0000-000000000000 ("Nil UUID") */
+       { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } },
+     { "ns:DNS",  /* 6ba7b810-9dad-11d1-80b4-00c04fd430c8 (see draft-leach-uuids-guids-01.txt) */
+       { 0x6b,0xa7,0xb8,0x10,0x9d,0xad,0x11,0xd1,0x80,0xb4,0x00,0xc0,0x4f,0xd4,0x30,0xc8 } },
+     { "ns:URL",  /* 6ba7b811-9dad-11d1-80b4-00c04fd430c8 (see draft-leach-uuids-guids-01.txt) */
+       { 0x6b,0xa7,0xb8,0x11,0x9d,0xad,0x11,0xd1,0x80,0xb4,0x00,0xc0,0x4f,0xd4,0x30,0xc8 } },
+     { "ns:OID",  /* 6ba7b812-9dad-11d1-80b4-00c04fd430c8 (see draft-leach-uuids-guids-01.txt) */
+       { 0x6b,0xa7,0xb8,0x12,0x9d,0xad,0x11,0xd1,0x80,0xb4,0x00,0xc0,0x4f,0xd4,0x30,0xc8 } },
+     { "ns:X500", /* 6ba7b814-9dad-11d1-80b4-00c04fd430c8 (see draft-leach-uuids-guids-01.txt) */
+       { 0x6b,0xa7,0xb8,0x14,0x9d,0xad,0x11,0xd1,0x80,0xb4,0x00,0xc0,0x4f,0xd4,0x30,0xc8 } }
+ };
+ 
+ /* load UUID object with pre-defined value */
+ uuid_rc_t uuid_load(uuid_t *uuid, const char *name)
+ {
+     uuid_uint8_t *uuid_octets;
+     uuid_rc_t rc;
+     unsigned int i;
+ 
+     /* sanity check argument(s) */
+     if (uuid == NULL || name == NULL)
+         return UUID_RC_ARG;
+ 
+     /* search for UUID in table */
+     uuid_octets = NULL;
+     for (i = 0; i < sizeof(uuid_value_table)/sizeof(uuid_value_table[0]); i++) {
+          if (strcmp(uuid_value_table[i].name, name) == 0) {
+              uuid_octets = uuid_value_table[i].uuid;
+              break;
+          }
+     }
+     if (uuid_octets == NULL)
+         return UUID_RC_ARG;
+ 
+     /* import value into UUID object */
+     if ((rc = uuid_import(uuid, UUID_FMT_BIN, uuid_octets, UUID_LEN_BIN)) != UUID_RC_OK)
+         return rc;
+ 
+     return UUID_RC_OK;
+ }
+ 
+ /* INTERNAL: generate UUID version 3: name based with MD5 */
+ static uuid_rc_t uuid_make_v3(uuid_t *uuid, unsigned int mode, va_list ap)
+ {
+     char *str;
+     uuid_t *uuid_ns;
+     uuid_uint8_t uuid_buf[UUID_LEN_BIN];
+     void *uuid_ptr;
+     size_t uuid_len;
+ 
+     /* determine namespace UUID and name string arguments */
+     if ((uuid_ns = (uuid_t *)va_arg(ap, void *)) == NULL)
+         return UUID_RC_ARG;
+     if ((str = (char *)va_arg(ap, char *)) == NULL)
+         return UUID_RC_ARG;
+ 
+     /* initialize MD5 context */
+     if (md5_init(uuid->md5) != MD5_RC_OK)
+         return UUID_RC_MEM;
+ 
+     /* load the namespace UUID into MD5 context */
+     uuid_ptr = (void *)&uuid_buf;
+     uuid_len = sizeof(uuid_buf);
+     uuid_export(uuid_ns, UUID_FMT_BIN, &uuid_ptr, &uuid_len);
+     md5_update(uuid->md5, uuid_buf, uuid_len);
+ 
+     /* load the argument name string into MD5 context */
+     md5_update(uuid->md5, str, strlen(str));
+ 
+     /* 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!) */
+     uuid_ptr = (void *)&(uuid->obj);
+     md5_store(uuid->md5, &uuid_ptr, NULL);
+ 
+     /* fulfill requirement of standard and convert UUID data into
+        local/host byte order (this uses fact that uuid_import_bin() is
+        able to operate in-place!) */
+     uuid_import(uuid, UUID_FMT_BIN, (void *)&(uuid->obj), UUID_LEN_BIN);
+ 
+     /* brand UUID with version and variant */
+     uuid_brand(uuid, 3);
+ 
+     return UUID_RC_OK;
+ }
+ 
+ /* INTERNAL: generate UUID version 4: random number based */
+ static uuid_rc_t uuid_make_v4(uuid_t *uuid, unsigned int mode, va_list ap)
+ {
+     /* fill UUID with random data */
+     prng_data(uuid->prng, (void *)&(uuid->obj), sizeof(uuid->obj));
+ 
+     /* brand UUID with version and variant */
+     uuid_brand(uuid, 4);
+ 
+     return UUID_RC_OK;
+ }
+ 
+ /* INTERNAL: generate UUID version 5: name based with SHA-1 */
+ static uuid_rc_t uuid_make_v5(uuid_t *uuid, unsigned int mode, va_list ap)
+ {
+     char *str;
+     uuid_t *uuid_ns;
+     uuid_uint8_t uuid_buf[UUID_LEN_BIN];
+     void *uuid_ptr;
+     size_t uuid_len;
+     uuid_uint8_t sha1_buf[SHA1_LEN_BIN];
+     void *sha1_ptr;
+ 
+     /* determine namespace UUID and name string arguments */
+     if ((uuid_ns = (uuid_t *)va_arg(ap, void *)) == NULL)
+         return UUID_RC_ARG;
+     if ((str = (char *)va_arg(ap, char *)) == NULL)
+         return UUID_RC_ARG;
+ 
+     /* initialize SHA-1 context */
+     if (sha1_init(uuid->sha1) != SHA1_RC_OK)
+         return UUID_RC_MEM;
+ 
+     /* load the namespace UUID into SHA-1 context */
+     uuid_ptr = (void *)&uuid_buf;
+     uuid_len = sizeof(uuid_buf);
+     uuid_export(uuid_ns, UUID_FMT_BIN, &uuid_ptr, &uuid_len);
+     sha1_update(uuid->sha1, uuid_buf, uuid_len);
+ 
+     /* load the argument name string into SHA-1 context */
+     sha1_update(uuid->sha1, str, strlen(str));
+ 
+     /* store SHA-1 result into UUID
+        (requires SHA1_LEN_BIN space, but UUID_LEN_BIN space is available
+        only, so use a temporary buffer to store SHA-1 results and then
+        use lower part only according to standard */
+     sha1_ptr = (void *)sha1_buf;
+     sha1_store(uuid->sha1, &sha1_ptr, NULL);
+     uuid_ptr = (void *)&(uuid->obj);
+     memcpy(uuid_ptr, sha1_ptr, UUID_LEN_BIN);
+ 
+     /* fulfill requirement of standard and convert UUID data into
+        local/host byte order (this uses fact that uuid_import_bin() is
+        able to operate in-place!) */
+     uuid_import(uuid, UUID_FMT_BIN, (void *)&(uuid->obj), UUID_LEN_BIN);
+ 
+     /* brand UUID with version and variant */
+     uuid_brand(uuid, 5);
+ 
+     return UUID_RC_OK;
+ }
+ 
+ /* generate UUID */
+ uuid_rc_t uuid_make(uuid_t *uuid, unsigned int mode, ...)
+ {
+     va_list ap;
+     uuid_rc_t rc;
+ 
+     /* sanity check argument(s) */
+     if (uuid == NULL)
+         return UUID_RC_ARG;
+ 
+     /* dispatch into version dependent generation functions */
+     va_start(ap, mode);
+     if (mode & UUID_MAKE_V1)
+         rc = uuid_make_v1(uuid, mode, ap);
+     else if (mode & UUID_MAKE_V3)
+         rc = uuid_make_v3(uuid, mode, ap);
+     else if (mode & UUID_MAKE_V4)
+         rc = uuid_make_v4(uuid, mode, ap);
+     else if (mode & UUID_MAKE_V5)
+         rc = uuid_make_v5(uuid, mode, ap);
+     else
+         rc = UUID_RC_ARG;
+     va_end(ap);
+ 
+     return rc;
+ }
+ 
+ /* translate UUID API error code into corresponding error string */
+ char *uuid_error(uuid_rc_t rc)
+ {
+     char *str;
+ 
+     switch (rc) {
+         case UUID_RC_OK:  str = "everything ok";    break;
+         case UUID_RC_ARG: str = "invalid argument"; break;
+         case UUID_RC_MEM: str = "out of memory";    break;
+         case UUID_RC_SYS: str = "system error";     break;
+         case UUID_RC_INT: str = "internal error";   break;
+         case UUID_RC_IMP: str = "not implemented";  break;
+         default:          str = NULL;               break;
+     }
+     return str;
+ }
+ 
+ /* OSSP uuid version (link-time information) */
+ unsigned long uuid_version(void)
+ {
+     return (unsigned long)(_UUID_VERSION);
+ }
+ 


ossp-pkg/uuid/uuid.h.in 1.6 -> 1.7

--- uuid.h.in    2005/01/23 11:28:51     1.6
+++ uuid.h.in    2005/03/29 19:01:41     1.7
@@ -90,12 +90,12 @@
 extern uuid_rc_t     uuid_make     (uuid_t  *_uuid, unsigned int _mode, ...);
 
 /* UUID comparison */
-extern uuid_rc_t     uuid_isnil    (uuid_t  *_uuid,                 int *_result);
-extern uuid_rc_t     uuid_compare  (uuid_t  *_uuid, uuid_t *_uuid2, int *_result);
+extern uuid_rc_t     uuid_isnil    (const uuid_t *_uuid,                       int *_result);
+extern uuid_rc_t     uuid_compare  (const uuid_t *_uuid, const uuid_t *_uuid2, int *_result);
 
 /* UUID import/export */
-extern uuid_rc_t     uuid_import   (uuid_t  *_uuid, uuid_fmt_t _fmt, const void  *_data_ptr, size_t  _data_len);
-extern uuid_rc_t     uuid_export   (uuid_t  *_uuid, uuid_fmt_t _fmt,       void **_data_ptr, size_t *_data_len);
+extern uuid_rc_t     uuid_import   (uuid_t       *_uuid, uuid_fmt_t _fmt, const void  *_data_ptr, size_t  _data_len);
+extern uuid_rc_t     uuid_export   (const uuid_t *_uuid, uuid_fmt_t _fmt,       void **_data_ptr, size_t *_data_len);
 
 /* library utilities */
 extern char         *uuid_error    (uuid_rc_t _rc);


ossp-pkg/uuid/uuid_ac.h 1.3 -> 1.4

--- uuid_ac.h    2004/12/31 19:20:34     1.3
+++ uuid_ac.h    2005/03/29 19:01:41     1.4
@@ -34,7 +34,7 @@
 
 /* define boolean values */
 #define UUID_FALSE 0
-#define UUID_TRUE  !UUID_FALSE
+#define UUID_TRUE  (/*lint -save -e506*/ !UUID_FALSE /*lint -restore*/)
 
 /* determine types of 8-bit size */
 #if SIZEOF_CHAR == 1


ossp-pkg/uuid/uuid_bm.h 1.4 -> 1.5

--- uuid_bm.h    2004/12/31 19:20:34     1.4
+++ uuid_bm.h    2005/03/29 19:01:41     1.5
@@ -38,7 +38,7 @@
 /* generate a bitmask consisting of 1 bits from (and including)
    bit position `l' (left) to (and including) bit position `r' */
 #define BM_MASK(l,r) \
-    (((1<<((l)-(r)+1))-1)<<(r))
+    ((((unsigned int)1<<(((l)-(r))+1))-1)<<(r))
 
 /* extract a value v from a word w at position `l' to `r' and return value */
 #define BM_GET(w,l,r) \
@@ -72,9 +72,9 @@
 
 /* rotate word w (of bits n..0) k bits to the left or to the right */
 #define BM_ROL(w,n,k) \
-    (BM_SHL((w),(k))&BM_MASK(n,0))|BM_SHR(((w)&BM_MASK(n,0)),(n)-(k))
+    ((BM_SHL((w),(k))&BM_MASK(n,0))|BM_SHR(((w)&BM_MASK(n,0)),(n)-(k)))
 #define BM_ROR(w,n,k) \
-    (BM_SHR(((w)&BM_MASK(n,0)),(k)))|BM_SHL(((w),(n)-(k))&BM_MASK(n,0))
+    ((BM_SHR(((w)&BM_MASK(n,0)),(k)))|BM_SHL(((w),(n)-(k))&BM_MASK(n,0)))
 
 #endif /* __UUID_BM_H__ */
 


ossp-pkg/uuid/uuid_cli.c 1.18 -> 1.19

--- uuid_cli.c   2005/01/23 11:28:51     1.18
+++ uuid_cli.c   2005/03/29 19:01:41     1.19
@@ -127,10 +127,10 @@
                 if (*p != '\0')
                     usage("invalid argument to option 'v'");
                 switch (i) {
-                    case 1: version = UUID_MAKE_V1; break;;
-                    case 3: version = UUID_MAKE_V3; break;;
-                    case 4: version = UUID_MAKE_V4; break;;
-                    case 5: version = UUID_MAKE_V5; break;;
+                    case 1: version = UUID_MAKE_V1; break;
+                    case 3: version = UUID_MAKE_V3; break;
+                    case 4: version = UUID_MAKE_V4; break;
+                    case 5: version = UUID_MAKE_V5; break;
                     default:
                         usage("invalid version on option 'v'");
                         break;


ossp-pkg/uuid/uuid_dce.c 1.2 -> 1.3

--- uuid_dce.c   2004/12/31 19:20:34     1.2
+++ uuid_dce.c   2005/03/29 19:01:41     1.3
@@ -43,6 +43,9 @@
 /* include regular API */
 #include "uuid.h"
 
+/* helper macro */
+#define LEAVE /*lint -save -e801*/ goto leave /*lint -restore*/
+
 /* create a UUID (v1 only) */
 void uuid_dce_create(uuid_dce_t *uuid_dce, int *status)
 {
@@ -149,15 +152,15 @@
 
     /* import both UUID binary representations and compare them */
     if (uuid_create(&uuid1) != UUID_RC_OK)
-        goto leave;
+        LEAVE;
     if (uuid_create(&uuid2) != UUID_RC_OK)
-        goto leave;
+        LEAVE;
     if (uuid_import(uuid1, UUID_FMT_BIN, uuid_dce1, UUID_LEN_BIN) != UUID_RC_OK)
-        goto leave;
+        LEAVE;
     if (uuid_import(uuid2, UUID_FMT_BIN, uuid_dce2, UUID_LEN_BIN) != UUID_RC_OK)
-        goto leave;
+        LEAVE;
     if (uuid_compare(uuid1, uuid2, &result) != UUID_RC_OK)
-        goto leave;
+        LEAVE;
 
     /* indicate successful operation */
     if (status != NULL)
@@ -204,13 +207,13 @@
 
     /* import string representation and export binary representation */
     if (uuid_create(&uuid) != UUID_RC_OK)
-        goto leave;
+        LEAVE;
     if (uuid_import(uuid, UUID_FMT_STR, str, UUID_LEN_STR) != UUID_RC_OK)
-        goto leave;
+        LEAVE;
     vp  = uuid_dce;
     len = UUID_LEN_BIN;
     if (uuid_export(uuid, UUID_FMT_BIN, &vp, &len) != UUID_RC_OK)
-        goto leave;
+        LEAVE;
 
     /* indicate successful operation */
     if (status != NULL)
@@ -240,13 +243,13 @@
 
     /* import binary representation and export string representation */
     if (uuid_create(&uuid) != UUID_RC_OK)
-        goto leave;
+        LEAVE;
     if (uuid_import(uuid, UUID_FMT_BIN, uuid_dce, UUID_LEN_BIN) != UUID_RC_OK)
-        goto leave;
+        LEAVE;
     vp  = str;
     len = UUID_LEN_STR;
     if (uuid_export(uuid, UUID_FMT_STR, &vp, &len) != UUID_RC_OK)
-        goto leave;
+        LEAVE;
 
     /* indicate successful operation */
     if (status != NULL)


ossp-pkg/uuid/uuid_mac.c 1.6 -> 1.7

--- uuid_mac.c   2005/01/13 08:50:11     1.6
+++ uuid_mac.c   2005/03/29 19:01:41     1.7
@@ -81,7 +81,7 @@
 #define FALSE 0
 #endif
 #ifndef TRUE
-#define TRUE !FALSE
+#define TRUE (/*lint -save -e506*/ !FALSE /*lint -restore*/)
 #endif
 
 /* return the Media Access Control (MAC) address of
@@ -107,7 +107,7 @@
             if (ifap->ifa_addr != NULL && ifap->ifa_addr->sa_family == AF_LINK) {
                 sdl = (const struct sockaddr_dl *)(void *)ifap->ifa_addr;
                 ucp = (unsigned char *)(sdl->sdl_data + sdl->sdl_nlen);
-                if (ucp != NULL && sdl->sdl_alen > 0) {
+                if (sdl->sdl_alen > 0) {
                     for (i = 0; i < MAC_LEN && i < sdl->sdl_alen; i++, ucp++)
                         data_ptr[i] = (unsigned char)(*ucp & 0xff);
                     freeifaddrs(ifap_head);


ossp-pkg/uuid/uuid_md5.c -> 1.11

*** /dev/null    Mon Apr 29 20:33:00 2024
--- -    Mon Apr 29 20:34:25 2024
***************
*** 0 ****
--- 1,464 ----
+ /*
+ **  OSSP uuid - Universally Unique Identifier
+ **  Copyright (c) 2004-2005 Ralf S. Engelschall <rse@engelschall.com>
+ **  Copyright (c) 2004-2005 The OSSP Project <http://www.ossp.org/>
+ **
+ **  This file is part of OSSP uuid, a library for the generation
+ **  of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
+ **
+ **  Permission to use, copy, modify, and distribute this software for
+ **  any purpose with or without fee is hereby granted, provided that
+ **  the above copyright notice and this permission notice appear in all
+ **  copies.
+ **
+ **  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ **  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ **  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ **  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
+ **  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ **  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ **  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ **  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ **  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ **  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ **  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ **  SUCH DAMAGE.
+ **
+ **  uuid_md5.c: MD5 API implementation
+ */
+ 
+ #include <stdlib.h>
+ #include <string.h>
+ 
+ #include "config.h"
+ #include "uuid_md5.h"
+ 
+ /*
+  * This is a RFC 1321 compliant Message Digest 5 (MD5) algorithm
+  * implementation. It is directly derived from the RSA code published in
+  * RFC 1321 with just the following functionality preserving changes:
+  * - converted function definitions from K&R to ANSI C
+  * - included contents of the "global.h" and "md5.h" headers
+  * - moved the SXX defines into the MD5Transform function
+  * - replaced MD5_memcpy() with memcpy(3) and MD5_memset() with memset(3)
+  * - renamed "index" variables to "idx" to avoid namespace conflicts
+  * - reformatted C style to conform with OSSP C style
+  * - added own OSSP style frontend API
+  */
+ 
+ /*
+ ** ==== BEGIN RFC 1321 CODE ====
+ */
+ 
+ /*
+  * RSA Data Security, Inc., MD5 message-digest algorithm
+  * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991.
+  * All rights reserved.
+  *
+  * License to copy and use this software is granted provided that it
+  * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+  * Algorithm" in all material mentioning or referencing this software
+  * or this function.
+  *
+  * License is also granted to make and use derivative works provided
+  * that such works are identified as "derived from the RSA Data
+  * Security, Inc. MD5 Message-Digest Algorithm" in all material
+  * mentioning or referencing the derived work.
+  *
+  * RSA Data Security, Inc. makes no representations concerning either
+  * the merchantability of this software or the suitability of this
+  * software for any particular purpose. It is provided "as is"
+  * without express or implied warranty of any kind.
+  *
+  * These notices must be retained in any copies of any part of this
+  * documentation and/or software.
+  */
+ 
+ /* POINTER defines a generic pointer type */
+ typedef unsigned char *POINTER;
+ 
+ /* UINT4 defines a four byte word */
+ #if SIZEOF_UNSIGNED_SHORT       == 4
+ typedef unsigned short int     UINT4;
+ #elif SIZEOF_UNSIGNED_INT       == 4
+ typedef unsigned int           UINT4;
+ #elif SIZEOF_UNSIGNED_LONG      == 4
+ typedef unsigned long int      UINT4;
+ #elif SIZEOF_UNSIGNED_LONG_LONG == 4
+ typedef unsigned long long int UINT4;
+ #else
+ #error ERROR: unable to determine UINT4 type (four byte word)
+ #endif
+ 
+ /* MD5 context. */
+ typedef struct {
+   UINT4 state[4];                                   /* state (ABCD) */
+   UINT4 count[2];        /* number of bits, modulo 2^64 (lsb first) */
+   unsigned char buffer[64];                         /* input buffer */
+ } MD5_CTX;
+ 
+ /* prototypes for internal functions */
+ static void MD5Init      (MD5_CTX *_ctx);
+ static void MD5Update    (MD5_CTX *_ctx, unsigned char *, unsigned int);
+ static void MD5Final     (unsigned char [16], MD5_CTX *);
+ static void MD5Transform (UINT4 [4], unsigned char [64]);
+ static void Encode       (unsigned char *, UINT4 *, unsigned int);
+ static void Decode       (UINT4 *, unsigned char *, unsigned int);
+ 
+ /* finalization padding */
+ static unsigned char PADDING[64] = {
+   0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+ 
+ /* F, G, H and I are basic MD5 functions. */
+ #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+ #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+ #define H(x, y, z) ((x) ^ (y) ^ (z))
+ #define I(x, y, z) ((y) ^ ((x) | (~z)))
+ 
+ /* ROTATE_LEFT rotates x left n bits. */
+ #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+ 
+ /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+    Rotation is separate from addition to prevent recomputation. */
+ #define FF(a, b, c, d, x, s, ac) { \
+  (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+  (a) = ROTATE_LEFT ((a), (s)); \
+  (a) += (b); \
+ }
+ #define GG(a, b, c, d, x, s, ac) { \
+  (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+  (a) = ROTATE_LEFT ((a), (s)); \
+  (a) += (b); \
+ }
+ #define HH(a, b, c, d, x, s, ac) { \
+  (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+  (a) = ROTATE_LEFT ((a), (s)); \
+  (a) += (b); \
+ }
+ #define II(a, b, c, d, x, s, ac) { \
+  (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+  (a) = ROTATE_LEFT ((a), (s)); \
+  (a) += (b); \
+ }
+ 
+ /* MD5 initialization. Begins an MD5 operation, writing a new context. */
+ static void MD5Init(
+     MD5_CTX *context)
+ {
+     context->count[0] = context->count[1] = 0;
+ 
+     /* Load magic initialization constants. */
+     context->state[0] = 0x67452301;
+     context->state[1] = 0xefcdab89;
+     context->state[2] = 0x98badcfe;
+     context->state[3] = 0x10325476;
+ }
+ 
+ /* MD5 block update operation. Continues an MD5 message-digest
+    operation, processing another message block, and updating the
+    context. */
+ static void MD5Update(
+     MD5_CTX *context,                                        /* context */
+     unsigned char *input,                                /* input block */
+     unsigned int inputLen)                     /* length of input block */
+ {
+     unsigned int i, idx, partLen;
+ 
+     /* Compute number of bytes mod 64 */
+     idx = (unsigned int)((context->count[0] >> 3) & 0x3F);
+ 
+     /* Update number of bits */
+     if ((context->count[0] += ((UINT4)inputLen << 3)) < ((UINT4)inputLen << 3))
+         context->count[1]++;
+     context->count[1] += ((UINT4)inputLen >> 29);
+ 
+     partLen = 64 - idx;
+ 
+     /* Transform as many times as possible.  */
+     if (inputLen >= partLen) {
+         memcpy((POINTER)&context->buffer[idx], (POINTER)input, partLen);
+         MD5Transform(context->state, context->buffer);
+         for (i = partLen; i + 63 < inputLen; i += 64)
+             MD5Transform(context->state, &input[i]);
+         idx = 0;
+     }
+     else
+         i = 0;
+ 
+     /* Buffer remaining input */
+     memcpy((POINTER)&context->buffer[idx], (POINTER)&input[i], inputLen-i);
+ }
+ 
+ /* MD5 finalization. Ends an MD5 message-digest operation, writing the
+    the message digest and zeroizing the context. */
+ static void MD5Final(
+     unsigned char digest[16],                        /* message digest */
+     MD5_CTX *context)                                       /* context */
+ {
+     unsigned char bits[8];
+     unsigned int idx, padLen;
+ 
+     /* Save number of bits */
+     Encode(bits, context->count, 8);
+ 
+     /* Pad out to 56 mod 64. */
+     idx = (unsigned int)((context->count[0] >> 3) & 0x3f);
+     padLen = (idx < 56) ? (56 - idx) : (120 - idx);
+     MD5Update(context, PADDING, padLen);
+ 
+     /* Append length (before padding) */
+     MD5Update(context, bits, 8);
+ 
+     /* Store state in digest */
+     Encode(digest, context->state, 16);
+ 
+     /* Zeroize sensitive information. */
+     memset((POINTER)context, '\0', sizeof (*context));
+ }
+ 
+ /* MD5 basic transformation. Transforms state based on block. */
+ static void MD5Transform(
+     UINT4 state[4],
+     unsigned char block[64])
+ {
+     UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+ 
+     Decode(x, block, 64);
+ 
+     /* Round 1 */
+ #define S11 7
+ #define S12 12
+ #define S13 17
+ #define S14 22
+     FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
+     FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
+     FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
+     FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
+     FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
+     FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
+     FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
+     FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
+     FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
+     FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
+     FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
+     FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
+     FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
+     FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
+     FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
+     FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
+ 
+    /* Round 2 */
+ #define S21 5
+ #define S22 9
+ #define S23 14
+ #define S24 20
+     GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
+     GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
+     GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
+     GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
+     GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
+     GG (d, a, b, c, x[10], S22,  0x2441453); /* 22 */
+     GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
+     GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
+     GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
+     GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
+     GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
+     GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
+     GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
+     GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
+     GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
+     GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
+ 
+     /* Round 3 */
+ #define S31 4
+ #define S32 11
+ #define S33 16
+ #define S34 23
+     HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
+     HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
+     HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
+     HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
+     HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
+     HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
+     HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
+     HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
+     HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
+     HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
+     HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
+     HH (b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
+     HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
+     HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
+     HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
+     HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
+ 
+     /* Round 4 */
+ #define S41 6
+ #define S42 10
+ #define S43 15
+ #define S44 21
+     II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
+     II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
+     II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
+     II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
+     II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
+     II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
+     II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
+     II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
+     II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
+     II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
+     II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
+     II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
+     II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
+     II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
+     II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
+     II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
+ 
+     state[0] += a;
+     state[1] += b;
+     state[2] += c;
+     state[3] += d;
+ 
+     /* Zeroize sensitive information. */
+     memset((POINTER)x, '\0', sizeof (x));
+ }
+ 
+ /* Encodes input (UINT4) into output (unsigned char).
+    Assumes len is a multiple of 4. */
+ static void Encode(
+     unsigned char *output,
+     UINT4 *input,
+     unsigned int len)
+ {
+     unsigned int i, j;
+ 
+     for (i = 0, j = 0; j < len; i++, j += 4) {
+         output[j]   = (unsigned char)( input[i]        & 0xff);
+         output[j+1] = (unsigned char)((input[i] >> 8)  & 0xff);
+         output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
+         output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
+     }
+ }
+ 
+ /* Decodes input (unsigned char) into output (UINT4).
+    Assumes len is a multiple of 4. */
+ static void Decode(
+     UINT4 *output,
+     unsigned char *input,
+     unsigned int len)
+ {
+     unsigned int i, j;
+ 
+     for (i = 0, j = 0; j < len; i++, j += 4)
+         output[i] =   ( (UINT4)input[j])
+                     | (((UINT4)input[j+1]) << 8 )
+                     | (((UINT4)input[j+2]) << 16)
+                     | (((UINT4)input[j+3]) << 24);
+ }
+ 
+ /*
+ ** ==== END RFC 1321 CODE ====
+ */
+ 
+ struct md5_st {
+     MD5_CTX ctx;
+ };
+ 
+ md5_rc_t md5_create(md5_t **md5)
+ {
+     if (md5 == NULL)
+         return MD5_RC_ARG;
+     if ((*md5 = (md5_t *)malloc(sizeof(md5_t))) == NULL)
+         return MD5_RC_MEM;
+     MD5Init(&((*md5)->ctx));
+     return MD5_RC_OK;
+ }
+ 
+ md5_rc_t md5_init(md5_t *md5)
+ {
+     if (md5 == NULL)
+         return MD5_RC_ARG;
+     MD5Init(&(md5->ctx));
+     return MD5_RC_OK;
+ }
+ 
+ md5_rc_t md5_update(md5_t *md5, const void *data_ptr, size_t data_len)
+ {
+     if (md5 == NULL)
+         return MD5_RC_ARG;
+     MD5Update(&(md5->ctx), (unsigned char *)data_ptr, (unsigned int)data_len);
+     return MD5_RC_OK;
+ }
+ 
+ md5_rc_t md5_store(md5_t *md5, void **data_ptr, size_t *data_len)
+ {
+     MD5_CTX ctx;
+ 
+     if (md5 == NULL || data_ptr == NULL)
+         return MD5_RC_ARG;
+     if (*data_ptr == NULL) {
+         if ((*data_ptr = malloc(MD5_LEN_BIN)) == NULL)
+             return MD5_RC_MEM;
+         if (data_len != NULL)
+             *data_len = MD5_LEN_BIN;
+     }
+     else {
+         if (data_len != NULL) {
+             if (*data_len < MD5_LEN_BIN)
+                 return MD5_RC_MEM;
+             *data_len = MD5_LEN_BIN;
+         }
+     }
+     memcpy((void *)(&ctx), (void *)(&(md5->ctx)), sizeof(MD5_CTX));
+     MD5Final((unsigned char *)(*data_ptr), &(ctx));
+     return MD5_RC_OK;
+ }
+ 
+ md5_rc_t md5_format(md5_t *md5, char **data_ptr, size_t *data_len)
+ {
+     static const char hex[] = "0123456789abcdef";
+     unsigned char buf[MD5_LEN_BIN];
+     unsigned char *bufptr;
+     size_t buflen;
+     md5_rc_t rc;
+     int i;
+ 
+     if (md5 == NULL || data_ptr == NULL)
+         return MD5_RC_ARG;
+     if (*data_ptr == NULL) {
+         if ((*data_ptr = (char *)malloc(MD5_LEN_STR+1)) == NULL)
+             return MD5_RC_MEM;
+         if (data_len != NULL)
+             *data_len = MD5_LEN_STR+1;
+     }
+     else {
+         if (data_len != NULL) {
+             if (*data_len < MD5_LEN_STR+1)
+                 return MD5_RC_MEM;
+             *data_len = MD5_LEN_STR+1;
+         }
+     }
+ 
+     bufptr = buf;
+     buflen = sizeof(buf);
+     if ((rc = md5_store(md5, (void **)((void *)&bufptr), &buflen)) != MD5_RC_OK)
+         return rc;
+ 
+     for (i = 0; i < (int)buflen; i++) {
+            (*data_ptr)[(i*2)+0] = hex[(int)(bufptr[i] >> 4)];
+            (*data_ptr)[(i*2)+1] = hex[(int)(bufptr[i] & 0x0f)];
+     }
+     (*data_ptr)[(i*2)] = '\0';
+     return MD5_RC_OK;
+ }
+ 
+ md5_rc_t md5_destroy(md5_t *md5)
+ {
+     if (md5 == NULL)
+         return MD5_RC_ARG;
+     free(md5);
+     return MD5_RC_OK;
+ }
+ 


ossp-pkg/uuid/uuid_prng.c 1.4 -> 1.5

--- uuid_prng.c  2004/12/31 19:20:34     1.4
+++ uuid_prng.c  2005/03/29 19:01:41     1.5
@@ -104,8 +104,8 @@
                     break;
                 continue;
             }
-            n -= i;
-            p += i;
+            n -= (unsigned int)i;
+            p += (unsigned int)i;
             cnt = 0;
         }
     }


ossp-pkg/uuid/uuid_sha1.c 1.1 -> 1.2

--- uuid_sha1.c  2005/01/23 11:28:51     1.1
+++ uuid_sha1.c  2005/03/29 19:01:41     1.2
@@ -92,7 +92,6 @@
 enum {
     shaSuccess = 0,
     shaNull,            /* null pointer parameter */
-    shaInputTooLong,    /* input data too long */
     shaStateError       /* called Input after Result */
 };
 
@@ -173,7 +172,7 @@
         context->Computed    = 1;
     }
     for (i = 0; i < SHA1HashSize; i++)
-        Message_Digest[i] = context->Intermediate_Hash[i>>2] >> 8 * (3 - (i & 0x03));
+        Message_Digest[i] = context->Intermediate_Hash[i>>2] >> (8 * (3 - (i & 0x03)));
 
     return shaSuccess;
 }


ossp-pkg/uuid/uuid_str.c 1.4 -> 1.5

--- uuid_str.c   2004/12/31 19:20:34     1.4
+++ uuid_str.c   2005/03/29 19:01:41     1.5
@@ -100,7 +100,7 @@
 
 /* some handy macros */
 #define char_to_int(p) (p - '0')
-#define MAX(p,q) ((p >= q) ? p : q)
+#define STR_MAX(p,q) ((p >= q) ? p : q)
 #define NUL '\0'
 
 static void
@@ -281,6 +281,7 @@
                 break;
             case 'E':
                 flags |= DP_F_UP;
+                /* FALLTHROUGH */
             case 'e':
                 if (cflags == DP_C_LDOUBLE)
                     fvalue = va_arg(args, LDOUBLE);
@@ -289,6 +290,7 @@
                 break;
             case 'G':
                 flags |= DP_F_UP;
+                /* FALLTHROUGH */
             case 'g':
                 if (cflags == DP_C_LDOUBLE)
                     fvalue = va_arg(args, LDOUBLE);
@@ -322,7 +324,7 @@
                     num = va_arg(args, LLONG *);
                     *num = (LLONG) currlen;
                 } else {
-                    int    *num;
+                    int *num;
                     num = va_arg(args, int *);
                     *num = currlen;
                 }
@@ -440,13 +442,13 @@
     convert[place] = 0;
 
     zpadlen = max - place;
-    spadlen = min - MAX(max, place) - (signvalue ? 1 : 0);
+    spadlen = min - STR_MAX(max, place) - (signvalue ? 1 : 0);
     if (zpadlen < 0)
         zpadlen = 0;
     if (spadlen < 0)
         spadlen = 0;
     if (flags & DP_F_ZERO) {
-        zpadlen = MAX(zpadlen, spadlen);
+        zpadlen = STR_MAX(zpadlen, spadlen);
         spadlen = 0;
     }
     if (flags & DP_F_MINUS)


ossp-pkg/uuid/uuid_ui64.c 1.3 -> 1.4

--- uuid_ui64.c  2004/12/31 19:20:34     1.3
+++ uuid_ui64.c  2005/03/29 19:01:41     1.4
@@ -38,10 +38,12 @@
 
 /* fill an ui64_t with a sequence of a particular digit */
 #define ui64_fill(__x, __n) \
+    /*lint -save -e717*/ \
     do { int __i; \
       for (__i = 0; __i < UI64_DIGITS; __i++) \
           (__x).x[__i] = (__n); \
-    } while(0)
+    } while (0) \
+    /*lint -restore*/
 
 /* the value zero */
 ui64_t ui64_zero(void)
@@ -85,8 +87,10 @@
 
     n = 0;
     i = (int)sizeof(n);
+    /*lint -save -e774*/
     if (i > UI64_DIGITS)
         i = UI64_DIGITS;
+    /*lint -restore*/
     while (--i >= 0) {
         n = (n * UI64_BASE) + x.x[i];
     }
@@ -144,19 +148,19 @@
         return NULL;
     n = ui64_len(x);
     i = 0;
-        do {
-                x = ui64_divn(x, base, &r);
-                str[i++] = map[r];
-                while (n > 1 && x.x[n-1] == 0)
-                        n--;
-        } while (i < ((int)len-1) && (n > 1 || x.x[0] != 0));
-        str[i] = '\0';
+    do {
+        x = ui64_divn(x, base, &r);
+        str[i++] = map[r];
+        while (n > 1 && x.x[n-1] == 0)
+            n--;
+    } while (i < ((int)len-1) && (n > 1 || x.x[0] != 0));
+    str[i] = '\0';
     for (j = 0; j < --i; j++) {
         c = str[j];
         str[j] = str[i];
         str[i] = c;
     }
-        return str;
+    return str;
 }
 
 /* addition of two ui64_t */
@@ -469,7 +473,7 @@
 {
     UIXX_T(UI64_DIGITS+UI64_DIGITS) zx;
     ui64_t z;
-        int i;
+    int i;
     int carry;
 
     if (s <= 0) {
@@ -517,7 +521,7 @@
 {
     UIXX_T(UI64_DIGITS+UI64_DIGITS) zx;
     ui64_t z;
-        int i;
+    int i;
     int carry;
 
     if (s <= 0) {

CVSTrac 2.0.1