[Midnightbsd-cvs] src [11888] trunk/games/random: reformat
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Tue Jul 17 20:54:47 EDT 2018
Revision: 11888
http://svnweb.midnightbsd.org/src/?rev=11888
Author: laffer1
Date: 2018-07-17 20:54:46 -0400 (Tue, 17 Jul 2018)
Log Message:
-----------
reformat
Modified Paths:
--------------
trunk/games/random/Makefile
trunk/games/random/random.6
trunk/games/random/random.c
trunk/games/random/randomize_fd.c
trunk/games/random/randomize_fd.h
Property Changed:
----------------
trunk/games/random/random.6
Modified: trunk/games/random/Makefile
===================================================================
--- trunk/games/random/Makefile 2018-07-18 00:53:10 UTC (rev 11887)
+++ trunk/games/random/Makefile 2018-07-18 00:54:46 UTC (rev 11888)
@@ -1,10 +1,9 @@
+# $MidnightBSD$
# @(#)Makefile 8.1 (Berkeley) 3/31/94
-# $FreeBSD: src/games/random/Makefile,v 1.5 2003/02/15 10:26:10 seanc Exp $
-# $MidnightBSD$
+# $FreeBSD: stable/10/games/random/Makefile 203923 2010-02-15 14:32:00Z uqs $
PROG= random
MAN= random.6
SRCS= random.c randomize_fd.c
-WARNS?= 5
.include <bsd.prog.mk>
Modified: trunk/games/random/random.6
===================================================================
--- trunk/games/random/random.6 2018-07-18 00:53:10 UTC (rev 11887)
+++ trunk/games/random/random.6 2018-07-18 00:54:46 UTC (rev 11888)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1994
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -9,11 +10,7 @@
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgment:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
+.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
@@ -30,10 +27,9 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)random.6 8.2 (Berkeley) 3/31/94
-.\" $FreeBSD: src/games/random/random.6,v 1.8 2005/01/18 08:57:18 ru Exp $
-.\" $MidnightBSD: src/games/random/random.6,v 1.3 2007/08/08 02:20:32 laffer1 Exp $
+.\" $FreeBSD: stable/10/games/random/random.6 307403 2016-10-16 22:02:50Z sevan $
.\"
-.Dd November 27, 2006
+.Dd February 8, 2003
.Dt RANDOM 6
.Os
.Sh NAME
@@ -122,8 +118,9 @@
.Sh HISTORY
The
functionality to randomizing lines and words was added in 2003 by
-.An "Sean Chittenden" Aq seanc at FreeBSD.org .
-
-The patch which solved the problem of slowliness when working with
-files larger than 10MB+ was added in 2006 by
-.An "Victor Loureiro Lima"
+.An Sean Chittenden Aq Mt seanc at FreeBSD.org .
+.Sh BUGS
+No index is used when printing out tokens from the list which
+makes it rather slow for large files (10MB+).
+For smaller
+files, however, it should still be quite fast and efficient.
Property changes on: trunk/games/random/random.6
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/games/random/random.c
===================================================================
--- trunk/games/random/random.c 2018-07-18 00:53:10 UTC (rev 11887)
+++ trunk/games/random/random.c 2018-07-18 00:54:46 UTC (rev 11888)
@@ -1,43 +1,41 @@
+/* $MidnightBSD$ */
/*
-* Copyright (c) 1994
-* The Regents of the University of California. All rights reserved.
-*
-* This code is derived from software contributed to Berkeley by
-* Guy Harris at Network Appliance Corp.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* 3. All advertising materials mentioning features or use of this software
-* must display the following acknowledgement:
-* This product includes software developed by the University of
-* California, Berkeley and its contributors.
-* 4. Neither the name of the University nor the names of its contributors
-* may be used to endorse or promote products derived from this software
-* without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-* SUCH DAMAGE.
-*/
+ * Copyright (c) 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Guy Harris at Network Appliance Corp.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
#if 0
#ifndef lint
static const char copyright[] =
-"@(#) Copyright (c) 1994n The Regents of the University of California. All rights reserved.n";
+"@(#) Copyright (c) 1994\n\
+ The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
@@ -45,8 +43,7 @@
#endif /* not lint */
#endif
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/games/random/random.c,v 1.19 2005/06/22 15:24:00 jhb Exp $");
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/games/random/random.c 209157 2010-06-14 13:03:25Z uqs $");
#include <sys/types.h>
@@ -54,6 +51,7 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -62,138 +60,136 @@
#include "randomize_fd.h"
-/*
-* The random() function is defined to return values between 0 and
-* 2^31 - 1 inclusive in random(3).
-*/
-#define RANDOM_MAX 0x7fffffffL
-
static void usage(void);
int
main(int argc, char *argv[])
{
-double denom;
-int ch, fd, random_exit, randomize_lines, random_type, ret,
-selected, unique_output, unbuffer_output;
-char *ep;
-const char *filename;
+ double denom;
+ int ch, fd, random_exit, randomize_lines, random_type, ret,
+ selected, unique_output, unbuffer_output;
+ char *ep;
+ const char *filename;
-denom = 0;
-filename = "/dev/fd/0";
-random_type = RANDOM_TYPE_UNSET;
-random_exit = randomize_lines = random_type = unbuffer_output = 0;
-unique_output = 1;
-while ((ch = getopt(argc, argv, "ef:hlruUw")) != -1)
-switch (ch) {
-case 'e':
-random_exit = 1;
-break;
-case 'f':
-randomize_lines = 1;
-if (strcmp(optarg, "-") != 0)
-filename = optarg;
-break;
-case 'l':
-randomize_lines = 1;
-random_type = RANDOM_TYPE_LINES;
-break;
-case 'r':
-unbuffer_output = 1;
-break;
-case 'u':
-randomize_lines = 1;
-unique_output = 1;
-break;
-case 'U':
-randomize_lines = 1;
-unique_output = 0;
-break;
-case 'w':
-randomize_lines = 1;
-random_type = RANDOM_TYPE_WORDS;
-break;
-default:
-case '?':
-usage();
-/* NOTREACHED */
-}
+ denom = 0;
+ filename = "/dev/fd/0";
+ random_type = RANDOM_TYPE_UNSET;
+ random_exit = randomize_lines = unbuffer_output = 0;
+ unique_output = 1;
-argc -= optind;
-argv += optind;
+ (void)setlocale(LC_CTYPE, "");
-switch (argc) {
-case 0:
-denom = (randomize_lines ? 1 : 2);
-break;
-case 1:
-errno = 0;
-denom = strtod(*argv, &ep);
-if (errno == ERANGE)
-err(1, "%s", *argv);
-if (denom <= 0 || *ep != '0')
-errx(1, "denominator is not valid.");
-if (random_exit && denom > 255)
-errx(1, "denominator must be <= 255 for random exit.");
-break;
-default:
-usage();
-/* NOTREACHED */
-}
+ while ((ch = getopt(argc, argv, "ef:hlruUw")) != -1)
+ switch (ch) {
+ case 'e':
+ random_exit = 1;
+ break;
+ case 'f':
+ randomize_lines = 1;
+ if (strcmp(optarg, "-") != 0)
+ filename = optarg;
+ break;
+ case 'l':
+ randomize_lines = 1;
+ random_type = RANDOM_TYPE_LINES;
+ break;
+ case 'r':
+ unbuffer_output = 1;
+ break;
+ case 'u':
+ randomize_lines = 1;
+ unique_output = 1;
+ break;
+ case 'U':
+ randomize_lines = 1;
+ unique_output = 0;
+ break;
+ case 'w':
+ randomize_lines = 1;
+ random_type = RANDOM_TYPE_WORDS;
+ break;
+ default:
+ case '?':
+ usage();
+ /* NOTREACHED */
+ }
-srandomdev();
+ argc -= optind;
+ argv += optind;
-/*
-* Act as a filter, randomly choosing lines of the standard input
-* to write to the standard output.
-*/
-if (unbuffer_output)
-setbuf(stdout, NULL);
+ switch (argc) {
+ case 0:
+ denom = (randomize_lines ? 1 : 2);
+ break;
+ case 1:
+ errno = 0;
+ denom = strtod(*argv, &ep);
+ if (errno == ERANGE)
+ err(1, "%s", *argv);
+ if (denom <= 0 || *ep != '\0')
+ errx(1, "denominator is not valid.");
+ if (random_exit && denom > 256)
+ errx(1, "denominator must be <= 256 for random exit.");
+ break;
+ default:
+ usage();
+ /* NOTREACHED */
+ }
-/*
-* Act as a filter, randomizing lines read in from a given file
-* descriptor and write the output to standard output.
-*/
-if (randomize_lines) {
-if ((fd = open(filename, O_RDONLY, 0)) < 0)
-err(1, "%s", filename);
-ret = randomize_fd(fd, random_type, unique_output, denom);
-if (!random_exit)
-return(ret);
-}
+ srandomdev();
-/* Compute a random exit status between 0 and denom - 1. */
-if (random_exit)
-return (int)((denom * random()) / RANDOM_MAX);
+ /*
+ * Act as a filter, randomly choosing lines of the standard input
+ * to write to the standard output.
+ */
+ if (unbuffer_output)
+ setbuf(stdout, NULL);
-/*
-* Select whether to print the first line. (Prime the pump.)
-* We find a random number between 0 and denom - 1 and, if it's
-* 0 (which has a 1 / denom chance of being true), we select the
-* line.
-*/
-selected = (int)(denom * random() / RANDOM_MAX) == 0;
-while ((ch = getchar()) != EOF) {
-if (selected)
-(void)putchar(ch);
-if (ch == 'n') {
-/* End of that line. See if we got an error. */
-if (ferror(stdout))
-err(2, "stdout");
+ /*
+ * Act as a filter, randomizing lines read in from a given file
+ * descriptor and write the output to standard output.
+ */
+ if (randomize_lines) {
+ if ((fd = open(filename, O_RDONLY, 0)) < 0)
+ err(1, "%s", filename);
+ ret = randomize_fd(fd, random_type, unique_output, denom);
+ if (!random_exit)
+ return(ret);
+ }
-/* Now see if the next line is to be printed. */
-selected = (int)(denom * random() / RANDOM_MAX) == 0;
+ /* Compute a random exit status between 0 and denom - 1. */
+ if (random_exit)
+ return (int)(denom * random() / RANDOM_MAX_PLUS1);
+
+ /*
+ * Select whether to print the first line. (Prime the pump.)
+ * We find a random number between 0 and denom - 1 and, if it's
+ * 0 (which has a 1 / denom chance of being true), we select the
+ * line.
+ */
+ selected = (int)(denom * random() / RANDOM_MAX_PLUS1) == 0;
+ while ((ch = getchar()) != EOF) {
+ if (selected)
+ (void)putchar(ch);
+ if (ch == '\n') {
+ /* End of that line. See if we got an error. */
+ if (ferror(stdout))
+ err(2, "stdout");
+
+ /* Now see if the next line is to be printed. */
+ selected = (int)(denom * random() /
+ RANDOM_MAX_PLUS1) == 0;
+ }
+ }
+ if (ferror(stdin))
+ err(2, "stdin");
+ exit (0);
}
-}
-if (ferror(stdin))
-err(2, "stdin");
-exit (0);
-}
static void
usage(void)
{
-fprintf(stderr, "usage: random [-elrUuw] [-f filename] [denominator]n");
-exit(1);
+ fprintf(stderr, "usage: random [-elrUuw] [-f filename] [denominator]\n");
+ exit(1);
}
Modified: trunk/games/random/randomize_fd.c
===================================================================
--- trunk/games/random/randomize_fd.c 2018-07-18 00:53:10 UTC (rev 11887)
+++ trunk/games/random/randomize_fd.c 2018-07-18 00:54:46 UTC (rev 11888)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (C) 2003 Sean Chittenden <seanc at FreeBSD.org>
* All rights reserved.
@@ -22,12 +23,10 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $MidnightBSD$
- * $FreeBSD: src/games/random/randomize_fd.c,v 1.2 2003/02/15 10:26:10 seanc Exp $
*/
#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/games/random/randomize_fd.c 301917 2016-06-15 06:27:43Z truckman $");
#include <sys/types.h>
#include <sys/param.h>
@@ -34,6 +33,7 @@
#include <ctype.h>
#include <err.h>
+#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -43,7 +43,6 @@
static struct rand_node *rand_root;
static struct rand_node *rand_tail;
-static struct rand_node **rand_node_table;
static struct rand_node *
rand_node_allocate(void)
@@ -96,16 +95,17 @@
int
randomize_fd(int fd, int type, int unique, double denom)
{
- u_char *buf, *p;
- u_int numnode, selected, slen;
- struct rand_node *n;
+ u_char *buf;
+ u_int slen;
+ u_long i, j, numnode, selected;
+ struct rand_node *n, *prev;
int bufleft, eof, fndstr, ret;
- size_t bufc, buflen, i;
+ size_t bufc, buflen;
ssize_t len;
rand_root = rand_tail = NULL;
bufc = i = 0;
- bufleft = eof = fndstr = numnode = ret = 0;
+ bufleft = eof = fndstr = numnode = 0;
if (type == RANDOM_TYPE_UNSET)
type = RANDOM_TYPE_LINES;
@@ -151,13 +151,13 @@
fndstr = 0;
}
} else {
- p = (u_char *)realloc(buf, buflen * 2);
- if (p == NULL)
+ buflen *= 2;
+ buf = (u_char *)realloc(buf, buflen);
+ if (buf == NULL)
err(1, "realloc");
- buf = p;
if (!eof) {
- len = read(fd, &buf[i], buflen);
+ len = read(fd, &buf[i], buflen - i);
if (len == -1)
err(1, "read");
else if (len == 0) {
@@ -164,19 +164,23 @@
eof++;
break;
} else if (len < (ssize_t)(buflen - i))
- buflen = (size_t)len;
+ buflen = i + (size_t)len;
bufleft = (int)len;
}
- buflen *= 2;
}
}
if ((type == RANDOM_TYPE_LINES && buf[i] == '\n') ||
- (type == RANDOM_TYPE_WORDS && isspace((int)buf[i])) ||
+ (type == RANDOM_TYPE_WORDS && isspace(buf[i])) ||
(eof && i == buflen - 1)) {
- make_token:
+make_token:
+ if (numnode == RANDOM_MAX_PLUS1) {
+ errno = EFBIG;
+ err(1, "too many delimiters");
+ }
+ numnode++;
n = rand_node_allocate();
if (-1 != (int)i) {
slen = i - (u_long)bufc;
@@ -192,13 +196,10 @@
}
rand_node_append(n);
fndstr = 1;
- numnode++;
}
}
}
- (void)close(fd);
-
/* Necessary evil to compensate for files that don't end with a newline */
if (bufc != i) {
i--;
@@ -205,35 +206,44 @@
goto make_token;
}
- rand_node_table = ( struct rand_node ** ) malloc( numnode * sizeof( struct rand_node * ));
- if( rand_node_table == NULL ) {
- perror("malloc");
- exit( EXIT_FAILURE );
- }
+ (void)close(fd);
- for( i = 0, n = rand_root; n != NULL; n = n->next, i++ )
- rand_node_table[i] = n;
-
free(buf);
for (i = numnode; i > 0; i--) {
-again:
- selected = ((int)denom * random())/(((double)RAND_MAX + 1) / numnode);
- n = rand_node_table[selected];
- if( unique )
- rand_node_table[selected] = NULL;
+ selected = random() % numnode;
- if( n == NULL )
- goto again;
+ for (j = 0, prev = n = rand_root; n != NULL; j++, prev = n, n = n->next) {
+ if (j == selected) {
+ if (n->cp == NULL)
+ break;
- ret = printf("%.*s", ( int ) n->len - 1, n->cp );
- if( ret < 0 )
- err(1, "printf");
+ if ((int)(denom * random() /
+ RANDOM_MAX_PLUS1) == 0) {
+ ret = printf("%.*s",
+ (int)n->len - 1, n->cp);
+ if (ret < 0)
+ err(1, "printf");
+ }
+ if (unique) {
+ if (n == rand_root)
+ rand_root = n->next;
+ if (n == rand_tail)
+ rand_tail = prev;
+
+ prev->next = n->next;
+ rand_node_free(n);
+ numnode--;
+ }
+ break;
+ }
+ }
}
fflush(stdout);
- rand_node_free_rec(rand_root);
- free(rand_node_table);
+ if (!unique)
+ rand_node_free_rec(rand_root);
+
return(0);
}
Modified: trunk/games/random/randomize_fd.h
===================================================================
--- trunk/games/random/randomize_fd.h 2018-07-18 00:53:10 UTC (rev 11887)
+++ trunk/games/random/randomize_fd.h 2018-07-18 00:54:46 UTC (rev 11888)
@@ -1,35 +1,41 @@
+/* $MidnightBSD$ */
/*
-* Copyright (C) 2003 Sean Chittenden <seanc at FreeBSD.org>
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-*
-* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
-* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
-* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-* SUCH DAMAGE.
-*
-* $FreeBSD: src/games/random/randomize_fd.h,v 1.2 2003/02/15 10:26:10 seanc Exp $
-* $MidnightBSD$
-*/
+ * Copyright (C) 2003 Sean Chittenden <seanc at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/games/random/randomize_fd.h 181527 2008-08-10 11:31:56Z ache $
+ */
#ifndef __RANDOMIZE_FD__
#define __RANDOMIZE_FD__
+/*
+ * The random() function is defined to return values between 0 and
+ * 2^31 - 1 inclusive in random(3).
+ */
+#define RANDOM_MAX_PLUS1 0x80000000UL
+
#define RANDOM_TYPE_UNSET 0
#define RANDOM_TYPE_LINES 1
#define RANDOM_TYPE_WORDS 2
@@ -36,9 +42,9 @@
/* The multiple instance single integer key */
struct rand_node {
-u_char *cp;
-u_int len;
-struct rand_node *next;
+ u_char *cp;
+ u_int len;
+ struct rand_node *next;
};
int randomize_fd(int fd, int type, int unique, double denom);
More information about the Midnightbsd-cvs
mailing list