always use rand(3) on platforms without arc4random(3) and seed it

This commit is contained in:
tg
2005-05-23 14:22:03 +00:00
parent 8266c126ac
commit 820f4b1de1
2 changed files with 13 additions and 4 deletions

10
var.c
View File

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/var.c,v 1.1 2005/05/23 03:06:10 tg Exp $ */
/** $MirOS: src/bin/mksh/var.c,v 1.2 2005/05/23 14:22:03 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.1 2005/05/23 03:06:10 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.2 2005/05/23 14:22:03 tg Exp $");
/*
* Variables
@ -855,7 +855,11 @@ 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)
int use_rand = 0;
#else
int use_rand = 1;
#endif
/*
* Called after a fork in parent to bump the random number generator.
@ -915,8 +919,10 @@ getspec(struct tbl *vp)
vp->flag &= ~SPECIAL;
if (use_rand)
setint(vp, (long) (rand() & 0x7fff));
#if !defined(__gnu_linux__) && !defined(__INTERIX)
else
setint(vp, (long) (arc4random() & 0x7fff));
#endif
vp->flag |= SPECIAL;
break;
case V_HISTSIZE: