From a6240e129a714de0ec5e5cbc8421465926528d9e Mon Sep 17 00:00:00 2001 From: millert <> Date: Sat, 7 Feb 1998 02:16:25 +0000 Subject: More XPG4.2 -- setstate takes a const parameter don't ever spew to stderr, just return NULL --- src/lib/libc/stdlib/random.3 | 18 ++++++++++++++---- src/lib/libc/stdlib/random.c | 14 +++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/lib/libc/stdlib/random.3 b/src/lib/libc/stdlib/random.3 index 87a4fe253f..b57dcd15e3 100644 --- a/src/lib/libc/stdlib/random.3 +++ b/src/lib/libc/stdlib/random.3 @@ -29,7 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: random.3,v 1.4 1998/02/06 01:49:08 deraadt Exp $ +.\" $OpenBSD: random.3,v 1.5 1998/02/07 02:16:25 millert Exp $ .\" .Dd April 19, 1991 .Dt RANDOM 3 @@ -45,11 +45,11 @@ .Ft long .Fn random void .Ft void -.Fn srandom "unsigned seed" +.Fn srandom "unsigned int seed" .Ft char * -.Fn initstate "unsigned seed" "char *state" "size_t n" +.Fn initstate "unsigned int seed" "char *state" "size_t n" .Ft char * -.Fn setstate "char *state" +.Fn setstate "const char *state" .Sh DESCRIPTION The .Fn random @@ -162,7 +162,17 @@ is called with less than 8 bytes of state information, or if detects that the state information has been garbled, error messages are printed on the standard error output. .Sh SEE ALSO +.Xr drand48 3 , .Xr rand 3 +.Sh STANDARDS +The +.Fn random , +.Fn srandom , +.Fn initstate , +and +.Fn setstate +functions conform to +.St -xpg4.2 . .Sh HISTORY These functions appeared in diff --git a/src/lib/libc/stdlib/random.c b/src/lib/libc/stdlib/random.c index 1ac61f2cec..79344f30f1 100644 --- a/src/lib/libc/stdlib/random.c +++ b/src/lib/libc/stdlib/random.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: random.c,v 1.5 1998/02/06 01:49:08 deraadt Exp $"; +static char *rcsid = "$OpenBSD: random.c,v 1.6 1998/02/07 02:16:25 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -250,11 +250,8 @@ initstate(seed, arg_state, n) state[-1] = rand_type; else state[-1] = MAX_TYPES * (rptr - state) + rand_type; - if (n < BREAK_0) { - (void)fprintf(stderr, - "random: not enough state (%d bytes); ignored.\n", n); - return(0); - } + if (n < BREAK_0) + return(NULL); if (n < BREAK_1) { rand_type = TYPE_0; rand_deg = DEG_0; @@ -303,7 +300,7 @@ initstate(seed, arg_state, n) */ char * setstate(arg_state) - char *arg_state; + const char *arg_state; { register long *new_state = (long *)arg_state; register int type = new_state[0] % MAX_TYPES; @@ -325,8 +322,7 @@ setstate(arg_state) rand_sep = seps[type]; break; default: - (void)fprintf(stderr, - "random: state info corrupted; not changed.\n"); + return(NULL); } state = &new_state[1]; if (rand_type != TYPE_0) { -- cgit v1.2.3-55-g6feb