Sun Jul 26 15:14:09 2020 UTC ()
Revert arc4random usage for now

this is a host tool and needs to be portable

future plans: add arc4random to libnbcompat


(nia)
diff -r1.41 -r1.42 src/games/fortune/strfile/strfile.c

cvs diff -r1.41 -r1.42 src/games/fortune/strfile/strfile.c (expand / switch to unified diff)

--- src/games/fortune/strfile/strfile.c 2020/07/21 03:05:40 1.41
+++ src/games/fortune/strfile/strfile.c 2020/07/26 15:14:09 1.42
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: strfile.c,v 1.41 2020/07/21 03:05:40 nia Exp $ */ 1/* $NetBSD: strfile.c,v 1.42 2020/07/26 15:14:09 nia Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1989, 1993 4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Ken Arnold. 8 * Ken Arnold.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -37,27 +37,27 @@ @@ -37,27 +37,27 @@
37#endif 37#endif
38 38
39#ifdef __NetBSD__ 39#ifdef __NetBSD__
40#include <sys/cdefs.h> 40#include <sys/cdefs.h>
41#ifndef lint 41#ifndef lint
42__COPYRIGHT("@(#) Copyright (c) 1989, 1993\ 42__COPYRIGHT("@(#) Copyright (c) 1989, 1993\
43 The Regents of the University of California. All rights reserved."); 43 The Regents of the University of California. All rights reserved.");
44#endif /* not lint */ 44#endif /* not lint */
45 45
46#ifndef lint 46#ifndef lint
47#if 0 47#if 0
48static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93"; 48static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93";
49#else 49#else
50__RCSID("$NetBSD: strfile.c,v 1.41 2020/07/21 03:05:40 nia Exp $"); 50__RCSID("$NetBSD: strfile.c,v 1.42 2020/07/26 15:14:09 nia Exp $");
51#endif 51#endif
52#endif /* not lint */ 52#endif /* not lint */
53#endif /* __NetBSD__ */ 53#endif /* __NetBSD__ */
54 54
55#include <sys/types.h> 55#include <sys/types.h>
56#include <sys/param.h> 56#include <sys/param.h>
57#include <ctype.h> 57#include <ctype.h>
58#include <stdarg.h> 58#include <stdarg.h>
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <string.h> 61#include <string.h>
62#include <time.h> 62#include <time.h>
63#include <unistd.h> 63#include <unistd.h>
@@ -428,35 +428,37 @@ cmp_str(const void *vp1, const void *vp2 @@ -428,35 +428,37 @@ cmp_str(const void *vp1, const void *vp2
428/* 428/*
429 * randomize: 429 * randomize:
430 * Randomize the order of the string table. We must be careful 430 * Randomize the order of the string table. We must be careful
431 * not to randomize across delimiter boundaries. All 431 * not to randomize across delimiter boundaries. All
432 * randomization is done within each block. 432 * randomization is done within each block.
433 */ 433 */
434static void 434static void
435randomize(void) 435randomize(void)
436{ 436{
437 int cnt, i; 437 int cnt, i;
438 off_t tmp; 438 off_t tmp;
439 off_t *sp; 439 off_t *sp;
440 440
 441 srandom((int)(time(NULL) + getpid()));
 442
441 Tbl.str_flags |= STR_RANDOM; 443 Tbl.str_flags |= STR_RANDOM;
442 cnt = Tbl.str_numstr; 444 cnt = Tbl.str_numstr;
443 445
444 /* 446 /*
445 * move things around randomly 447 * move things around randomly
446 */ 448 */
447 449
448 for (sp = Seekpts; cnt > 0; cnt--, sp++) { 450 for (sp = Seekpts; cnt > 0; cnt--, sp++) {
449 i = arc4random_uniform(cnt); 451 i = random() % cnt;
450 tmp = sp[0]; 452 tmp = sp[0];
451 sp[0] = sp[i]; 453 sp[0] = sp[i];
452 sp[i] = tmp; 454 sp[i] = tmp;
453 } 455 }
454} 456}
455 457
456/* 458/*
457 * fwrite_be_offt: 459 * fwrite_be_offt:
458 * Write out the off paramater as a 64 bit big endian number 460 * Write out the off paramater as a 64 bit big endian number
459 */ 461 */
460 462
461static void 463static void
462fwrite_be_offt(off_t off, FILE *f) 464fwrite_be_offt(off_t off, FILE *f)