]> sjero.net Git - wget/commitdiff
[svn] Check for random.
authorhniksic <devnull@localhost>
Tue, 27 Nov 2001 10:11:13 +0000 (02:11 -0800)
committerhniksic <devnull@localhost>
Tue, 27 Nov 2001 10:11:13 +0000 (02:11 -0800)
Published in <sxs4rngh6t2.fsf@florida.arsdigita.de>.

ChangeLog
configure.in
src/ChangeLog
src/cmpt.c
src/config.h.in
src/sysdep.h

index a3d0db08faf9f86c67f1a16c127810e18c0003a4..526e02aa750624630e96d50ea78c513c39596833 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2001-11-27  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * configure.in: Check for random.
+
 2001-11-26  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * configure.in: Check for usleep.
index 1cc995a2000e24440fb7b7aa18c34e6d9c478744..e853b7706083b87c54aecd28516b0926225a1a06 100644 (file)
@@ -175,7 +175,7 @@ AC_FUNC_MMAP
 AC_CHECK_FUNCS(strdup strstr strcasecmp strncasecmp strpbrk)
 AC_CHECK_FUNCS(gettimeofday mktime strptime)
 AC_CHECK_FUNCS(strerror snprintf vsnprintf select signal symlink access isatty)
-AC_CHECK_FUNCS(uname gethostname usleep)
+AC_CHECK_FUNCS(uname gethostname random usleep)
 
 dnl
 dnl Check if we need to compile in getopt.c.
index 1bc8c0b857525f6e3fdee7345f307699d5a1acf6..e6c060dcec013ef0ac40deceb9e58f96aa55183c 100644 (file)
@@ -1,3 +1,8 @@
+2001-11-27  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * cmpt.c (random): New function, a simple-minded replacement for
+       random() on systems that don't have it.
+
 2001-11-26  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * config.h.in: Put a HAVE_USLEEP stub.
index 7a7add09bd607da57a3b908c5c73b3e1d8ea9d59..542151315174cd1d5b8c036e6840fc8532457116 100644 (file)
@@ -1222,3 +1222,38 @@ usleep (unsigned long usec)
   return 0;
 }
 #endif /* not HAVE_USLEEP */
+
+
+#ifndef HAVE_RANDOM
+/* For the systems without random: a really simple congruential RNG,
+   only good enough for what Wget uses it for.  Before you panic: this
+   is not used for any kind of cryptography.  */
+
+static long random_seed;
+
+#define RANDOM_A 9301
+#define RANDOM_C 49297
+#define RANDOM_M 233280
+
+static int
+random_1 (void)
+{
+  if (!random_seed)
+    random_seed = time (NULL);
+  random_seed = (random_seed * RANDOM_A + RANDOM_C) % RANDOM_M;
+  return random_seed;
+}
+
+long
+random (void)
+{
+  /* Upper bits of random() are a bit more random.  Compose random()
+     from higher bits of three call to random().  */
+  unsigned r1 = random_1 () >> 8;
+  unsigned r2 = random_1 () >> 4;
+  unsigned r3 = random_1 ();
+  long result = r1 ^ r2 ^ r3;
+
+  return result;
+}
+#endif /* not HAVE_RANDOM */
index 1364d27f7fd54efcabe5afbde8d4d3295e38fc40..62793c2c38e00fb2a3605a0743c2ddbd03368659 100644 (file)
@@ -168,6 +168,9 @@ char *alloca ();
 /* Define if you have the usleep function.  */
 #undef HAVE_USLEEP
 
+/* Define if you have the random function.  */
+#undef HAVE_RANDOM
+
 /* Define if you have the <string.h> header file.  */
 #undef HAVE_STRING_H
 
index 1c5deb1b8290c293e59b69a6b3da24b571ecd77e..d4430b2ba5134bea2b3c4428d84f04f57c9566c3 100644 (file)
@@ -166,6 +166,9 @@ int vsnprintf ();
 #ifndef HAVE_USLEEP
 int usleep ();
 #endif
+#ifndef HAVE_RANDOM
+long random ();
+#endif
 
 /* SunOS brain damage -- for some reason, SunOS header files fail to
    declare the functions below, which causes all kinds of problems