summaryrefslogtreecommitdiff
path: root/gl/lib/randread.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2009-04-06 08:42:15 +0100
committerPádraig Brady <P@draigBrady.com>2009-04-07 19:01:46 +0100
commitaf5723c71e3efbfe60266162ebb5d07b45d72725 (patch)
tree0e4d0dfce546753ff8c0e749da14a6ba3a26a3b4 /gl/lib/randread.c
parent9fdf5845fc87135c4f68bce79f72a25d07130240 (diff)
downloadcoreutils-af5723c71e3efbfe60266162ebb5d07b45d72725.tar.xz
shred,sort,shuf: don't use /dev/urandom by default
Suggestion from Steven Schveighoffer at: http://savannah.gnu.org/patch/?6797 to greatly speed up the random passes done by shred. * gl/lib/randread.c: Default to using the internal pseudorandom generator, rather than reading /dev/urandom * src/shred.c (usage): remove mention of /dev/urandom * src/shuf.c (usage); ditto * src/sort.c (usage): ditto * doc/coreutils.text: Document the new behaviour for aquiring random data.
Diffstat (limited to 'gl/lib/randread.c')
-rw-r--r--gl/lib/randread.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/gl/lib/randread.c b/gl/lib/randread.c
index b81a4510b..798d4e0a3 100644
--- a/gl/lib/randread.c
+++ b/gl/lib/randread.c
@@ -50,10 +50,6 @@
# define ALIGNED_POINTER(ptr, type) ((size_t) (ptr) % alignof (type) == 0)
#endif
-#ifndef DEFAULT_RANDOM_FILE
-# define DEFAULT_RANDOM_FILE "/dev/urandom"
-#endif
-
/* The maximum buffer size used for reads of random data. Using the
value 2 * ISAAC_BYTES makes this the largest power of two that
would not otherwise cause struct randread_source to grow. */
@@ -62,10 +58,8 @@
/* A source of random data for generating random buffers. */
struct randread_source
{
- /* Stream to read random bytes from. If null, the behavior is
- undefined; the current implementation uses ISAAC in this case,
- but this is for old-fashioned implementations that lack
- /dev/urandom and callers should not rely on this. */
+ /* Stream to read random bytes from. If null, the current
+ implementation uses an internal PRNG (ISAAC). */
FILE *source;
/* Function to call, and its argument, if there is an input error or
@@ -147,18 +141,14 @@ randread_new (char const *name, size_t bytes_bound)
return simple_new (NULL, NULL);
else
{
- char const *file_name = (name ? name : DEFAULT_RANDOM_FILE);
- FILE *source = fopen_safer (file_name, "rb");
+ FILE *source = NULL;
struct randread_source *s;
- if (! source)
- {
- if (name)
- return NULL;
- file_name = NULL;
- }
+ if (name)
+ if (! (source = fopen_safer (name, "rb")))
+ return NULL;
- s = simple_new (source, file_name);
+ s = simple_new (source, name);
if (source)
setvbuf (source, s->buf.c, _IOFBF, MIN (sizeof s->buf.c, bytes_bound));