freebsd-5x-20030715
[openafs.git] / src / util / uuid.c
index d7f11e5..a6a1b05 100644 (file)
@@ -7,9 +7,44 @@
  * directory or online at http://www.openafs.org/dl/license10.html
  */
 
+/* String conversion routines have the following copyright */
+
+/*
+ * Copyright (c) 2002 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS 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 INSTITUTE OR 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.
+ */
+
 #include <afsconfig.h>
 #ifdef KERNEL
-#include "../afs/param.h"
+#include "afs/param.h"
 #else
 #include <afs/param.h>
 #endif
@@ -17,8 +52,8 @@
 RCSID("$Header$");
 
 #ifdef KERNEL
-#include "../afs/sysincludes.h"
-#include "../afs/afsincludes.h"
+#include "afs/sysincludes.h"
+#include "afsincludes.h"
 #define uuid_memcmp(A,B,C)     memcmp(A, B, C)
 #define uuid_memcpy(A,B,C)     memcpy(A, B, C)
 #else /* KERNEL */
@@ -98,28 +133,34 @@ static u_short uuid_time_adjust, clock_seq;
 static afs_uint32 rand_m, rand_ia, rand_ib, rand_irand, uuid_init_done = 0;
 
 #define        uuid_create_nil(uuid) memset(uuid, 0, sizeof(afsUUID))
-afs_int32 afs_uuid_equal(u1, u2) afsUUID *u1, *u2;  { return(uuid_memcmp((void *)u1, (void *)u2, sizeof (afsUUID)) == 0); }
-afs_int32 afs_uuid_is_nil(u1) afsUUID *u1; { 
+
+afs_int32 afs_uuid_equal(afsUUID *u1, afsUUID *u2)
+{
+       return(uuid_memcmp((void *)u1, (void *)u2, sizeof (afsUUID)) == 0);
+}
+
+afs_int32 afs_uuid_is_nil(afsUUID *u1)
+{
     if (!u1) return 1;
     return(uuid_memcmp((void *)u1, (void *)&afs_uuid_g_nil_uuid, sizeof (afsUUID)) == 0); 
 }
 
-
-void afs_htonuuid(uuidp)
-afsUUID *uuidp; {
+void afs_htonuuid(afsUUID *uuidp)
+{
     uuidp->time_low = htonl(uuidp->time_low);
     uuidp->time_mid = htons(uuidp->time_mid);
     uuidp->time_hi_and_version = htons(uuidp->time_hi_and_version);
 }
 
-void afs_ntohuuid(uuidp)
-afsUUID *uuidp; {
+void afs_ntohuuid(afsUUID *uuidp)
+{
     uuidp->time_low = ntohl(uuidp->time_low);
     uuidp->time_mid = ntohs(uuidp->time_mid);
     uuidp->time_hi_and_version = ntohs(uuidp->time_hi_and_version);
 }
  
-static u_short true_random () {
+static u_short true_random (void)
+{
     rand_m += 7;
     rand_ia += 1907;
     rand_ib += 73939;
@@ -131,9 +172,8 @@ static u_short true_random () {
 }
 
 
-static afs_int32 time_cmp (time1, time2)
-uuid_time_p_t           time1;
-uuid_time_p_t           time2; {
+static afs_int32 time_cmp (uuid_time_p_t time1, uuid_time_p_t time2)
+{
     if (time1->hi < time2->hi) return (-1);
     if (time1->hi > time2->hi) return (1);
     if (time1->lo < time2->lo) return (-1);
@@ -145,6 +185,7 @@ uuid_time_p_t           time2; {
  *    Converts a string UUID to binary representation.
  */
 
+#if !defined(KERNEL) && !defined(UKERNEL)
 int
 afsUUID_from_string(const char *str, afsUUID *uuid)
 {
@@ -198,9 +239,10 @@ afsUUID_to_string(const afsUUID *uuid, char *str, size_t strsz)
 
     return 0;
 }
+#endif
 
-afs_int32 afs_uuid_create (uuid)
-afsUUID *uuid; {
+afs_int32 afs_uuid_create (afsUUID *uuid)
+{
     uuid_address_t eaddr;
     afs_int32 got_no_time = 0, code;
 
@@ -228,7 +270,11 @@ afsUUID *uuid; {
        seed ^= *seedp++;
        seed ^= *seedp++;
        seed ^= *seedp++;
-       rand_irand += seed + (afs_uint32)getpid();
+#if defined(KERNEL) && defined(AFS_XBSD_ENV)
+       rand_irand += seed + (afs_uint32) curproc->p_pid;
+#else
+       rand_irand += seed + (afs_uint32) getpid();
+#endif
        uuid__get_os_time (&time_last);
        clock_seq = true_random();
 #ifdef AFS_NT40_ENV
@@ -285,8 +331,8 @@ afsUUID *uuid; {
     return 0;
 }
 
-u_short afs_uuid_hash (uuid)
-afsUUID *uuid; {
+u_short afs_uuid_hash (afsUUID *uuid)
+{
     short               c0=0, c1=0, x, y;
     char             *next_uuid = (char *) uuid;
 
@@ -410,7 +456,7 @@ void uuid__get_os_time (uuid_time_t *os_time)
 {
     struct timeval      tp;
 
-    if (gettimeofday (&tp, (struct timezone *) 0)) {
+    if (gettimeofday (&tp, NULL)) {
         perror ("uuid__get_time");
         exit (-1);
     }