summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormillert <>1998-02-07 02:16:25 +0000
committermillert <>1998-02-07 02:16:25 +0000
commita6240e129a714de0ec5e5cbc8421465926528d9e (patch)
tree28fb4f77ad25b8c8f7ebf4db8b5b2ab9fddc8aac
parent3e1f199d9076db124c95fd0475b1ce73e079ac21 (diff)
downloadopenbsd-a6240e129a714de0ec5e5cbc8421465926528d9e.tar.gz
openbsd-a6240e129a714de0ec5e5cbc8421465926528d9e.tar.bz2
openbsd-a6240e129a714de0ec5e5cbc8421465926528d9e.zip
More XPG4.2 --
setstate takes a const parameter don't ever spew to stderr, just return NULL
-rw-r--r--src/lib/libc/stdlib/random.318
-rw-r--r--src/lib/libc/stdlib/random.c14
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 @@
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 30.\" SUCH DAMAGE.
31.\" 31.\"
32.\" $OpenBSD: random.3,v 1.4 1998/02/06 01:49:08 deraadt Exp $ 32.\" $OpenBSD: random.3,v 1.5 1998/02/07 02:16:25 millert Exp $
33.\" 33.\"
34.Dd April 19, 1991 34.Dd April 19, 1991
35.Dt RANDOM 3 35.Dt RANDOM 3
@@ -45,11 +45,11 @@
45.Ft long 45.Ft long
46.Fn random void 46.Fn random void
47.Ft void 47.Ft void
48.Fn srandom "unsigned seed" 48.Fn srandom "unsigned int seed"
49.Ft char * 49.Ft char *
50.Fn initstate "unsigned seed" "char *state" "size_t n" 50.Fn initstate "unsigned int seed" "char *state" "size_t n"
51.Ft char * 51.Ft char *
52.Fn setstate "char *state" 52.Fn setstate "const char *state"
53.Sh DESCRIPTION 53.Sh DESCRIPTION
54The 54The
55.Fn random 55.Fn random
@@ -162,7 +162,17 @@ is called with less than 8 bytes of state information, or if
162detects that the state information has been garbled, error 162detects that the state information has been garbled, error
163messages are printed on the standard error output. 163messages are printed on the standard error output.
164.Sh SEE ALSO 164.Sh SEE ALSO
165.Xr drand48 3 ,
165.Xr rand 3 166.Xr rand 3
167.Sh STANDARDS
168The
169.Fn random ,
170.Fn srandom ,
171.Fn initstate ,
172and
173.Fn setstate
174functions conform to
175.St -xpg4.2 .
166.Sh HISTORY 176.Sh HISTORY
167These 177These
168functions appeared in 178functions 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 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: random.c,v 1.5 1998/02/06 01:49:08 deraadt Exp $"; 35static char *rcsid = "$OpenBSD: random.c,v 1.6 1998/02/07 02:16:25 millert Exp $";
36#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
37 37
38#include <stdio.h> 38#include <stdio.h>
@@ -250,11 +250,8 @@ initstate(seed, arg_state, n)
250 state[-1] = rand_type; 250 state[-1] = rand_type;
251 else 251 else
252 state[-1] = MAX_TYPES * (rptr - state) + rand_type; 252 state[-1] = MAX_TYPES * (rptr - state) + rand_type;
253 if (n < BREAK_0) { 253 if (n < BREAK_0)
254 (void)fprintf(stderr, 254 return(NULL);
255 "random: not enough state (%d bytes); ignored.\n", n);
256 return(0);
257 }
258 if (n < BREAK_1) { 255 if (n < BREAK_1) {
259 rand_type = TYPE_0; 256 rand_type = TYPE_0;
260 rand_deg = DEG_0; 257 rand_deg = DEG_0;
@@ -303,7 +300,7 @@ initstate(seed, arg_state, n)
303 */ 300 */
304char * 301char *
305setstate(arg_state) 302setstate(arg_state)
306 char *arg_state; 303 const char *arg_state;
307{ 304{
308 register long *new_state = (long *)arg_state; 305 register long *new_state = (long *)arg_state;
309 register int type = new_state[0] % MAX_TYPES; 306 register int type = new_state[0] % MAX_TYPES;
@@ -325,8 +322,7 @@ setstate(arg_state)
325 rand_sep = seps[type]; 322 rand_sep = seps[type];
326 break; 323 break;
327 default: 324 default:
328 (void)fprintf(stderr, 325 return(NULL);
329 "random: state info corrupted; not changed.\n");
330 } 326 }
331 state = &new_state[1]; 327 state = &new_state[1];
332 if (rand_type != TYPE_0) { 328 if (rand_type != TYPE_0) {