diff options
author | seanc <seanc@FreeBSD.org> | 2003-02-15 10:26:10 +0000 |
---|---|---|
committer | seanc <seanc@FreeBSD.org> | 2003-02-15 10:26:10 +0000 |
commit | cb6083f9802291b208d0d70b2a356afb604bf3cf (patch) | |
tree | 3395f1c1eccf05868f2a82e467d2be10be8aeb18 /games/random/random.c | |
parent | c831929bbba4418d3580388349f25f7f5edebe49 (diff) | |
download | FreeBSD-src-cb6083f9802291b208d0d70b2a356afb604bf3cf.zip FreeBSD-src-cb6083f9802291b208d0d70b2a356afb604bf3cf.tar.gz |
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]
Diffstat (limited to 'games/random/random.c')
-rw-r--r-- | games/random/random.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/games/random/random.c b/games/random/random.c index f0d5df3..7b45f6e 100644 --- a/games/random/random.c +++ b/games/random/random.c @@ -42,12 +42,13 @@ static const char copyright[] = #ifndef lint #if 0 -static char sccsid[] = "@(#)random.c 8.5 (Berkeley) 4/5/94"; +static const char sccsid[] = "@(#)random.c 8.5 (Berkeley) 4/5/94"; #endif -static const char rcsid[] = - "$FreeBSD$"; #endif /* not lint */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #include <sys/types.h> #include <err.h> @@ -56,14 +57,16 @@ static const char rcsid[] = #include <limits.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <time.h> #include <unistd.h> + #include "randomize_fd.h" -void usage(void); +static void usage(void); int -main(int argc, char **argv) +main(int argc, char *argv[]) { double denom; int ch, fd, random_exit, randomize_lines, random_type, ret, @@ -149,7 +152,7 @@ main(int argc, char **argv) */ if (randomize_lines) { if ((fd = open(filename, O_RDONLY, 0)) < 0) - err(1, "%s", optarg); + err(1, "%s", filename); ret = randomize_fd(fd, random_type, unique_output, denom); if (!random_exit) return(ret); @@ -157,7 +160,7 @@ main(int argc, char **argv) /* Compute a random exit status between 0 and denom - 1. */ if (random_exit) - return ((denom * random()) / LONG_MAX); + return (int)((denom * random()) / LONG_MAX); /* * Select whether to print the first line. (Prime the pump.) @@ -183,10 +186,10 @@ main(int argc, char **argv) exit (0); } -void -usage() +static void +usage(void) { - (void)fprintf(stderr, "usage: random [-elruUw] [-f filename] [denominator]\n"); + fprintf(stderr, "usage: random [-elruUw] [-f filename] [denominator]\n"); exit(1); } |