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.
+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
#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++;
}
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;
}
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;
-
}
/*
else
uuid_generate_time(out);
}
-
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))
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;