* fix logic for srand() I got reversed

* introduce HAVE_ARC4RANDOM tristate (0/1/undef) and fill it appropriately
* NetBSD(R) joins the list of OSes which don't have arc4random
This commit is contained in:
tg
2005-05-26 23:01:30 +00:00
parent 7f4297f3d0
commit dc22f4da3a
3 changed files with 16 additions and 12 deletions

12
var.c
View File

@@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/var.c,v 1.4 2005/05/25 13:46:02 tg Exp $ */
/** $MirOS: src/bin/mksh/var.c,v 1.5 2005/05/26 23:01:30 tg Exp $ */
/* $OpenBSD: var.c,v 1.26 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h"
@@ -6,7 +6,7 @@
#include <ctype.h>
#include <time.h>
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.4 2005/05/25 13:46:02 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.5 2005/05/26 23:01:30 tg Exp $");
/*
* Variables
@@ -855,11 +855,7 @@ makenv(void)
* Someone has set the srand() value, therefore from now on
* we return values from rand() instead of arc4random()
*/
#if !defined(__gnu_linux__) && !defined(__INTERIX) && !defined(__sun__)
int use_rand = 0;
#else
int use_rand = 1;
#endif
int use_rand = !HAVE_ARC4RANDOM;
/*
* Called after a fork in parent to bump the random number generator.
@@ -919,7 +915,7 @@ getspec(struct tbl *vp)
vp->flag &= ~SPECIAL;
if (use_rand)
setint(vp, (long) (rand() & 0x7fff));
#if !defined(__gnu_linux__) && !defined(__INTERIX) && !defined(__sun__)
#if HAVE_ARC4RANDOM
else
setint(vp, (long) (arc4random() & 0x7fff));
#endif