Whamcloud - gitweb
ChangeLog, copy.c, gen_uuid.c, tst_uuid.c, uuid_time.c:
authorTheodore Ts'o <tytso@mit.edu>
Fri, 12 Jan 2001 18:30:54 +0000 (18:30 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 12 Jan 2001 18:30:54 +0000 (18:30 +0000)
  uuid_time.c (main), tst_uuid.c (main): Fix gcc -Wall complaints.
  copy.c (uuid_copy): Change arguments to make it clear which argument
   is the source and which is the destination.
  gen_uuid.c (get_random_fd): Use gettimeofday to seed the PRNG, so we
   can take advantage of tv_usec to do (slightly) better at seeding it.

lib/uuid/ChangeLog
lib/uuid/copy.c
lib/uuid/gen_uuid.c
lib/uuid/tst_uuid.c
lib/uuid/uuid_time.c

index 988e626..ac5255e 100644 (file)
@@ -1,3 +1,14 @@
+2001-01-12  Theodore Ts'o  <tytso@valinux.com>
+
+       * uuid_time.c (main), tst_uuid.c (main): Fix gcc -Wall complaints.
+
+       * copy.c (uuid_copy): Change arguments to make it clear which
+               argument is the source and which is the destination.
+
+       * gen_uuid.c (get_random_fd): Use gettimeofday to seed the PRNG,
+               so we can take advantage of tv_usec to do (slightly)
+               better at seeding it.
+
 2000-07-13    <tytso@valinux.com>
 
        * Release of E2fsprogs 1.19
index fcb08ab..213a9e5 100644 (file)
 
 #include "uuidP.h"
 
-void uuid_copy(uuid_t uu1, uuid_t uu2)
+void uuid_copy(uuid_t dst, uuid_t src)
 {
-       unsigned char   *cp1, *cp2;
+       unsigned char   *cp1, *cp2;
        int             i;
 
-       for (i=0, cp1 = uu1, cp2 = uu2; i < 16; i++)
+       for (i=0, cp1 = dst, cp2 = src; i < 16; i++)
                *cp1++ = *cp2++;
 }
index be1dbbb..fd55114 100644 (file)
 
 static int get_random_fd()
 {
-       static int fd = -2;
-       int     i;
+       struct timeval  tv;
+       static int      fd = -2;
+       int             i;
 
        if (fd == -2) {
+               gettimeofday(&tv, 0);
                fd = open("/dev/urandom", O_RDONLY);
                if (fd == -1)
                        fd = open("/dev/random", O_RDONLY | O_NONBLOCK);
-               srand((getpid() << 16) ^ getuid() ^ time(0));
+               srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
        }
        /* Crank the random number generator a few times */
-       for (i = time(0) & 0x1F; i > 0; i--)
+       gettimeofday(&tv, 0);
+       for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--)
                rand();
        return fd;
 }
@@ -85,14 +88,11 @@ static void get_random_bytes(void *buf, int nbytes)
                        lose_counter = 0;
                }
        }
-       if (nbytes == 0)
-               return;
 
        /* XXX put something better here if no /dev/random! */
-       for (i=0; i < nbytes; i++)
+       for (i = 0; i < nbytes; i++)
                *cp++ = rand() & 0xFF;
        return;
-       
 }
 
 /*
@@ -268,4 +268,3 @@ void uuid_generate(uuid_t out)
        else
                uuid_generate_time(out);
 }
-
index b9fc5f6..dac52b5 100644 (file)
@@ -85,7 +85,7 @@ main(int argc, char **argv)
        tv.tv_sec = 0;
        tv.tv_usec = 0;
        time_reg = uuid_time(buf, &tv);
-       printf("UUID time is: (%d, %d): %s\n", tv.tv_sec, tv.tv_usec,
+       printf("UUID time is: (%ld, %ld): %s\n", tv.tv_sec, tv.tv_usec,
               ctime(&time_reg));
        uuid_parse(str, tst);
        if (!uuid_compare(buf, tst))
index f2fddfa..ee9ce26 100644 (file)
@@ -131,7 +131,7 @@ main(int argc, char **argv)
                printf("Warning: not a time-based UUID, so UUID time "
                       "decoding will likely not work!\n");
        }
-       printf("UUID time is: (%d, %d): %s\n", tv.tv_sec, tv.tv_usec,
+       printf("UUID time is: (%ld, %ld): %s\n", tv.tv_sec, tv.tv_usec,
               ctime(&time_reg));
        
        return 0;