Loading...
stdlib/FreeBSD/random.c Libc-1725.40.4 Libc-391
--- Libc/Libc-1725.40.4/stdlib/FreeBSD/random.c
+++ Libc/Libc-391/stdlib/FreeBSD/random.c
@@ -10,6 +10,10 @@
  * 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -31,17 +35,8 @@
 static char sccsid[] = "@(#)random.c	8.2 (Berkeley) 5/19/95";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#ifdef __APPLE__
-// Always compile with __DARWIN_UNIX03=1 prototypes.
-// Applications using legacy interfaces (i386 only) use types of the same size:
-//   sizeof(int) == sizeof(long) == sizeof(size_t)
-#undef 	__DARWIN_UNIX03
-#define	__DARWIN_UNIX03	1
-#endif // __APPLE__
-
-#include "namespace.h"
+__FBSDID("$FreeBSD: src/lib/libc/stdlib/random.c,v 1.24 2004/01/20 03:02:18 das Exp $");
+
 #include "namespace.h"
 #include <sys/time.h>          /* for srandomdev() */
 #include <fcntl.h>             /* for srandomdev() */
@@ -225,8 +220,10 @@
 static int rand_sep = SEP_3;
 static uint32_t *end_ptr = &randtbl[DEG_3 + 1];
 
-static inline uint32_t
-good_rand(int32_t x)
+static inline uint32_t good_rand(int32_t);
+
+static inline uint32_t good_rand (x)
+	int32_t x;
 {
 #ifdef  USE_WEAK_SEEDING
 /*
@@ -271,11 +268,8 @@
  * for default usage relies on values produced by this routine.
  */
 void
-#ifdef __APPLE__
-srandom(unsigned int x)
-#else
-srandom(unsigned long x)
-#endif
+srandom(x)
+	unsigned long x;
 {
 	int i, lim;
 
@@ -305,7 +299,7 @@
  * a fixed seed.
  */
 void
-srandomdev(void)
+srandomdev()
 {
 	int fd, done;
 	size_t len;
@@ -316,7 +310,7 @@
 		len = rand_deg * sizeof state[0];
 
 	done = 0;
-	fd = _open("/dev/random", O_RDONLY | O_CLOEXEC, 0);
+	fd = _open("/dev/random", O_RDONLY, 0);
 	if (fd >= 0) {
 		if (_read(fd, (void *) state, len) == (ssize_t) len)
 			done = 1;
@@ -325,9 +319,10 @@
 
 	if (!done) {
 		struct timeval tv;
+		unsigned long junk;
 
 		gettimeofday(&tv, NULL);
-		srandom((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec);
+		srandom((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk);
 		return;
 	}
 
@@ -361,11 +356,10 @@
  * complain about mis-alignment, but you should disregard these messages.
  */
 char *
-#ifdef __APPLE__
-initstate(unsigned int seed, char *arg_state, size_t n)
-#else
-initstate(unsigned long seed, char *arg_state, long n)
-#endif
+initstate(seed, arg_state, n)
+	unsigned long seed;		/* seed for R.N.G. */
+	char *arg_state;		/* pointer to state array */
+	long n;				/* # bytes of state info */
 {
 	char *ostate = (char *)(&state[-1]);
 	uint32_t *int_arg_state = (uint32_t *)arg_state;
@@ -377,7 +371,7 @@
 	if (n < BREAK_0) {
 		(void)fprintf(stderr,
 		    "random: not enough state (%ld bytes); ignored.\n", n);
-		return (0);
+		return(0);
 	}
 	if (n < BREAK_1) {
 		rand_type = TYPE_0;
@@ -407,7 +401,7 @@
 		int_arg_state[0] = rand_type;
 	else
 		int_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type;
-	return (ostate);
+	return(ostate);
 }
 
 /*
@@ -430,7 +424,8 @@
  * complain about mis-alignment, but you should disregard these messages.
  */
 char *
-setstate(const char *arg_state)
+setstate(arg_state)
+	char *arg_state;		/* pointer to state array */
 {
 	uint32_t *new_state = (uint32_t *)arg_state;
 	uint32_t type = new_state[0] % MAX_TYPES;
@@ -461,7 +456,7 @@
 		fptr = &state[(rear + rand_sep) % rand_deg];
 	}
 	end_ptr = &state[rand_deg];		/* set end_ptr too */
-	return (ostate);
+	return(ostate);
 }
 
 /*
@@ -482,7 +477,7 @@
  * Returns a 31-bit random number.
  */
 long
-random(void)
+random()
 {
 	uint32_t i;
 	uint32_t *f, *r;
@@ -507,5 +502,5 @@
 
 		fptr = f; rptr = r;
 	}
-	return ((long)i);
+	return((long)i);
 }