Commit Graph

33 Commits

Author SHA1 Message Date
Andrey A. Chernov
d77b331074 Suggections from bde@
1) Split too long source lines
2) Portable code should not assume that null pointer == all-bits-0,
so back out prev. calloc() change.

Submitted by:   bde
2008-08-11 23:24:42 +00:00
Andrey A. Chernov
2a3fabc4d3 All cosmetic.
1) Rename RANDOM_MAX to RANDOM_MAX_PLUS1 to not confuse with random()'s max
2) Use calloc() instead of zeroing fields explicitly
3) "too many lines" -> "too many delimiters" for err()
2008-08-10 11:31:56 +00:00
Andrey A. Chernov
2c38883d2a 1) Fix longstanding math bug with denominator > 1 (wrong probability).
Test case:
	random -f some_small_file 10000
(in most cases must be no output)
2) Prevent number of lines > RANDOM_MAX (overflow or nothing may be
choosed) with EFBIG err()
3) After line is found, terminate list loop for -U case too,
since nothing to do in the rest of the loop left.
2008-08-08 02:46:47 +00:00
Andrey A. Chernov
67cc8dbb1a I was confused a bit by the wrong construction with RAND_MAX
used in randomize_fd.c.
Although the max value is the same currently, RAND_MAX is for rand(),
not for random().
So move RANDOM_MAX const to the common file now, make it UL and
use in randomize_fd.c too.
(in any case its old value was 1 less then must be, as noted in
the prev. commit)
2008-08-08 01:42:17 +00:00
Andrey A. Chernov
5b6bf07632 1) Replace hardcoded RANDOM_MAX macro with wrong (1 less than must be)
value with ((double)RAND_MAX + 1)
2) For exit code increase valid denominator upper range from 255 to 256
since returned value is [0 .. denom - 1]
2008-08-08 01:02:30 +00:00
Andrey A. Chernov
1107d0af30 1) Fix hang at the end of line buffer (PR 95715)
2) Localize

PR:             95715
Submitted by:   Li-Lun Wang <llwang@infor.org> (slightly edited by me)
2006-04-14 17:32:27 +00:00
John Baldwin
59c2bcbae9 Correct an error in the previous revision. RAND_MAX is the maximum value
for rand(3), not random(3).  random(3) is defined to return values between
0 and 2^31-1, so add a local RANDOM_MAX constant to this file that is
defined as 2^31-1 and use that in place of RAND_MAX.

Reviewed by:	bde
Approved by:	re (dwhite)
MFC after:	1 week
2005-06-22 15:24:00 +00:00
John Baldwin
b0a7bd8e88 Fix for 64-bit platforms. random() returns values between 0 and RAND_MAX,
and RAND_MAX != LONG_MAX on 64-bit platforms.

PR:		amd64/81279
Submitted by:	Vivek Khera vivek at khera dot org
Submitted by:	Adriaan de Groot groot at kde dot org
MFC after:	1 week
2005-05-27 15:29:01 +00:00
Ruslan Ermilov
6324f7db72 Sync program's usage() with manpage's SYNOPSIS. 2005-02-09 18:22:15 +00:00
Ruslan Ermilov
70c55092de Sort sections. 2005-01-18 08:57:18 +00:00
Stefan Farfeleder
5618536d0b Properly initialise 'filename' so that random -l doesn't try to open NULL.
Const-qualify 'filename' to avoid a strdup() call due to -Wwrite-strings
silliness.
2004-10-03 15:34:15 +00:00
David E. O'Brien
e3c85e0226 Make the __FBSDID usage consistent
and protect copyright[] from Gcc 3.3's whining.
2003-05-05 09:52:25 +00:00
Ruslan Ermilov
2bee685c4a Fixed SYNOPSIS.
Expanded stdin/stdout definitions.
Ordered the SEE ALSO references.
Moved some chat from the BUGS section to freebsd-chat@.
Removed ``cvs log'' material from the HISTORY section.
2003-02-23 01:44:14 +00:00
Sean Chittenden
3f4b504568 flexlint rears its head as well as some style(9) fixes[1]. Fixed a
few bugs for a few corner cases and correctly handle the case where
read(2) is read()'ing from a non-file descriptor and could get fewer
bytes back than the buffer, but it isn't EOF[2].  random(6) extensively
tested and believed to be bug free (save performance for large files).

Submitted by:	mkm [1], tjr[2]
2003-02-15 10:26:10 +00:00
Sean Chittenden
a3b3a1cf6c Update random(6) to have the ability to randomize a file/stdin based
off of lines or words.  See the man page for details.

Reviewed by:	markm
MFC after:	3 days
2003-02-11 19:32:18 +00:00
Warner Losh
ad64363769 Remove __P
Remove __STDC__ (which means we now use stdarg rather than vararg)
Remove register
Remove main prototype
2002-02-18 05:15:19 +00:00
Ruslan Ermilov
63919764c2 mdoc(7) police: removed HISTORY info from the .Os call. 2001-07-10 10:42:19 +00:00
Ruslan Ermilov
e5b5c66bca - Backout botched attempt to intoduce MANSECT feature.
- MAN[1-9] -> MAN.
2001-03-26 14:22:12 +00:00
Ruslan Ermilov
1c011f20f6 Set the default manual section for games/ to 6. 2001-03-20 18:08:43 +00:00
Ruslan Ermilov
a00cb08bcb mdoc(7) police: use the new features of the Nm macro. 2000-11-20 12:06:19 +00:00
Bill Fumerola
c9914211a1 -Wall fixes. 1999-12-12 06:30:46 +00:00
Bill Fumerola
7b216475bf copyright/sccsid/rcsid cleanup. 1999-11-30 03:50:02 +00:00
Peter Wemm
9b7a44a60e $Id$ -> $FreeBSD$ 1999-08-27 23:37:10 +00:00
Nik Clayton
077e7b24bc Add $Id$, to make it simpler for members of the translation teams to
track.

The $Id$ line is normally at the bottom of the main comment block in the
man page, separated from the rest of the manpage by an empty comment,
like so;

     .\"    $Id$
     .\"

If the immediately preceding comment is a @(#) format ID marker than the
the $Id$ will line up underneath it with no intervening blank lines.
Otherwise, an additional blank line is inserted.

Approved by:            bde
1999-07-12 20:30:45 +00:00
Jordan K. Hubbard
01f228ffbe Wargh! Who went and changed all the getopt() comparisons from -1 to
EOF?  The getopt(3) manpage clearly states that the return value is *-1*,
not EOF!  Besides, getopt(3) isn't reading from a file. :)

Noticed-while:	merging to 2.2 (where this is correct).
1998-03-01 05:10:28 +00:00
Andrey A. Chernov
663d61b5eb Remove so-called revoke, this game never installed sguid 1997-09-01 11:40:18 +00:00
Eivind Eklund
34a13bf4cb Change games from setuid games to setgid games.
Reviewed by:	maybe@yes.no
Obtained from:	OpenBSD (mostly deraadt@openbsd.org)
1997-09-01 00:34:51 +00:00
Andrey A. Chernov
b5cee521b3 Remove srandomdev fallback code 1997-06-14 00:37:08 +00:00
Andrey A. Chernov
286fdb4a38 Use srandomdev() now
Add range checking for invalid denominator values
1997-03-30 23:33:29 +00:00
Andrey A. Chernov
1d98c12acc Fix srandom arg type accodring to Lite2
Use ^ getpid() instead of + getpid()
1997-03-11 14:08:34 +00:00
Rodney W. Grimes
010f5413b5 Remove trailing whitespace. 1995-05-30 03:37:36 +00:00
Bruce Evans
b0b1fe4f53 Include <limits.h> to get LONG_MAX - don't depend on namespace pollution
in <time.h>.
1995-02-03 20:55:37 +00:00
Jordan K. Hubbard
554eb505f8 Bring in the 4.4 Lite games directory, modulo man page changes and segregation
of the x11 based games.  I'm not going to tag the originals with bsd_44_lite
and do this in two stages since it's just not worth it for this collection,
and I've got directory renames to deal with that way.  Bleah.
Submitted by:	jkh
1994-09-04 04:03:31 +00:00