Browse Source

More XPG4.2 --

setstate takes a const parameter
don't ever spew to stderr, just return NULL
OPENBSD_2_3
millert 27 years ago
parent
commit
d919ab04d0
3 changed files with 23 additions and 17 deletions
  1. +4
    -4
      src/include/stdlib.h
  2. +14
    -4
      src/lib/libc/stdlib/random.3
  3. +5
    -9
      src/lib/libc/stdlib/random.c

+ 4
- 4
src/include/stdlib.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: stdlib.h,v 1.6 1998/02/06 01:49:06 deraadt Exp $ */
/* $OpenBSD: stdlib.h,v 1.7 1998/02/07 02:16:26 millert Exp $ */
/* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */ /* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */
/*- /*-
@ -166,11 +166,11 @@ int radixsort __P((const unsigned char **, int, const unsigned char *,
int sradixsort __P((const unsigned char **, int, const unsigned char *, int sradixsort __P((const unsigned char **, int, const unsigned char *,
unsigned)); unsigned));
char *initstate __P((unsigned, char *, size_t));
char *initstate __P((unsigned int, char *, size_t));
long random __P((void)); long random __P((void));
char *realpath __P((const char *, char *)); char *realpath __P((const char *, char *));
char *setstate __P((char *));
void srandom __P((unsigned));
char *setstate __P((const char *));
void srandom __P((unsigned int));
int putenv __P((const char *)); int putenv __P((const char *));
int setenv __P((const char *, const char *, int)); int setenv __P((const char *, const char *, int));


+ 14
- 4
src/lib/libc/stdlib/random.3 View File

@ -29,7 +29,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" 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 .Dd April 19, 1991
.Dt RANDOM 3 .Dt RANDOM 3
@ -45,11 +45,11 @@
.Ft long .Ft long
.Fn random void .Fn random void
.Ft void .Ft void
.Fn srandom "unsigned seed"
.Fn srandom "unsigned int seed"
.Ft char * .Ft char *
.Fn initstate "unsigned seed" "char *state" "size_t n"
.Fn initstate "unsigned int seed" "char *state" "size_t n"
.Ft char * .Ft char *
.Fn setstate "char *state"
.Fn setstate "const char *state"
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Fn random .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 detects that the state information has been garbled, error
messages are printed on the standard error output. messages are printed on the standard error output.
.Sh SEE ALSO .Sh SEE ALSO
.Xr drand48 3 ,
.Xr rand 3 .Xr rand 3
.Sh STANDARDS
The
.Fn random ,
.Fn srandom ,
.Fn initstate ,
and
.Fn setstate
functions conform to
.St -xpg4.2 .
.Sh HISTORY .Sh HISTORY
These These
functions appeared in functions appeared in


+ 5
- 9
src/lib/libc/stdlib/random.c View File

@ -32,7 +32,7 @@
*/ */
#if defined(LIBC_SCCS) && !defined(lint) #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 */ #endif /* LIBC_SCCS and not lint */
#include <stdio.h> #include <stdio.h>
@ -250,11 +250,8 @@ initstate(seed, arg_state, n)
state[-1] = rand_type; state[-1] = rand_type;
else else
state[-1] = MAX_TYPES * (rptr - state) + rand_type; 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) { if (n < BREAK_1) {
rand_type = TYPE_0; rand_type = TYPE_0;
rand_deg = DEG_0; rand_deg = DEG_0;
@ -303,7 +300,7 @@ initstate(seed, arg_state, n)
*/ */
char * char *
setstate(arg_state) setstate(arg_state)
char *arg_state;
const char *arg_state;
{ {
register long *new_state = (long *)arg_state; register long *new_state = (long *)arg_state;
register int type = new_state[0] % MAX_TYPES; register int type = new_state[0] % MAX_TYPES;
@ -325,8 +322,7 @@ setstate(arg_state)
rand_sep = seps[type]; rand_sep = seps[type];
break; break;
default: default:
(void)fprintf(stderr,
"random: state info corrupted; not changed.\n");
return(NULL);
} }
state = &new_state[1]; state = &new_state[1];
if (rand_type != TYPE_0) { if (rand_type != TYPE_0) {


Loading…
Cancel
Save