summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/rand.c
diff options
context:
space:
mode:
authord <>1998-11-20 11:18:51 +0000
committerd <>1998-11-20 11:18:51 +0000
commitc1f295aa8666eb1c08a1edf944ac5617659a066c (patch)
treeefe0a5dfb4f9767f96ab03ce9c00dc5bcc98074c /src/lib/libc/stdlib/rand.c
parent5a11336d3f08469f2747ebcf26ae777dba46fd22 (diff)
downloadopenbsd-c1f295aa8666eb1c08a1edf944ac5617659a066c.tar.gz
openbsd-c1f295aa8666eb1c08a1edf944ac5617659a066c.tar.bz2
openbsd-c1f295aa8666eb1c08a1edf944ac5617659a066c.zip
Add thread-safety to libc, so that libc_r will build (on i386 at least).
All POSIX libc api now there (to P1003.1c/D10) (more md stuff is needed for other libc/arch/*) (setlogin is no longer a special syscall) Add -pthread option to gcc (that makes it use -lc_r and -D_POSIX_THREADS). Doc some re-entrant routines Add libc_r to intro(3) dig() uses some libc srcs and an extra -I was needed there. Add more md stuff to libc_r. Update includes for the pthreads api Update libc_r TODO
Diffstat (limited to 'src/lib/libc/stdlib/rand.c')
-rw-r--r--src/lib/libc/stdlib/rand.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/lib/libc/stdlib/rand.c b/src/lib/libc/stdlib/rand.c
index f270ffd986..61fb66e5ec 100644
--- a/src/lib/libc/stdlib/rand.c
+++ b/src/lib/libc/stdlib/rand.c
@@ -32,7 +32,7 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: rand.c,v 1.2 1996/08/19 08:33:44 tholo Exp $"; 35static char *rcsid = "$OpenBSD: rand.c,v 1.3 1998/11/20 11:18:50 d Exp $";
36#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
37 37
38#include <sys/types.h> 38#include <sys/types.h>
@@ -41,9 +41,17 @@ static char *rcsid = "$OpenBSD: rand.c,v 1.2 1996/08/19 08:33:44 tholo Exp $";
41static u_long next = 1; 41static u_long next = 1;
42 42
43int 43int
44rand_r(seed)
45u_int *seed;
46{
47 *seed = *seed * 1103515245 + 12345;
48 return (u_int)(*seed / 65536) % ((u_int)RAND_MAX + 1);
49}
50
51int
44rand() 52rand()
45{ 53{
46 return ((next = next * 1103515245 + 12345) % ((u_int)RAND_MAX + 1)); 54 return rand_r(&next);
47} 55}
48 56
49void 57void