diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-08-23 20:13:07 +0000 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-08-23 20:13:07 +0000 |
commit | a3fc78c87acc9a411959115c071f60adf54a2e11 (patch) | |
tree | fe7b9954ef4c3d2aba9be1eb1430f5adee8a8e2c | |
parent | 47bfec25d8fabfa4cc118e094a08101655d63d65 (diff) |
Emulate random() on platforms without random(), but with rand() function.
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | src/microhttpd/Makefile.am | 4 | ||||
-rw-r--r-- | src/microhttpd/mhd_compat.c | 20 | ||||
-rw-r--r-- | src/microhttpd/mhd_compat.h | 24 |
4 files changed, 18 insertions, 33 deletions
diff --git a/configure.ac b/configure.ac index f66540ec..2fbdc538 100644 --- a/configure.ac +++ b/configure.ac @@ -551,6 +551,9 @@ AC_CHECK_HEADERS([sys/types.h sys/time.h sys/msg.h netdb.h netinet/in.h netinet/ sockLib.h inetLib.h net/if.h]) AM_CONDITIONAL([HAVE_TSEARCH], [test "x$ac_cv_header_search_h" = "xyes"]) +# Check for generic functions +AC_CHECK_FUNCS([rand random]) + AC_CHECK_MEMBER([struct sockaddr_in.sin_len], [ AC_DEFINE(HAVE_SOCKADDR_IN_SIN_LEN, 1, [Do we have sockaddr_in.sin_len?]) ], diff --git a/src/microhttpd/Makefile.am b/src/microhttpd/Makefile.am index 1e555c18..cfd4799f 100644 --- a/src/microhttpd/Makefile.am +++ b/src/microhttpd/Makefile.am @@ -167,7 +167,7 @@ test_daemon_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la test_postprocessor_SOURCES = \ - test_postprocessor.c mhd_compat.c + test_postprocessor.c test_postprocessor_CPPFLAGS = \ $(AM_CPPFLAGS) $(GNUTLS_CPPFLAGS) test_postprocessor_LDADD = \ @@ -181,7 +181,7 @@ test_postprocessor_amp_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la test_postprocessor_large_SOURCES = \ - test_postprocessor_large.c mhd_compat.c + test_postprocessor_large.c test_postprocessor_large_CPPFLAGS = \ $(AM_CPPFLAGS) $(GNUTLS_CPPFLAGS) test_postprocessor_large_LDADD = \ diff --git a/src/microhttpd/mhd_compat.c b/src/microhttpd/mhd_compat.c index 4911a1c6..c0a6e362 100644 --- a/src/microhttpd/mhd_compat.c +++ b/src/microhttpd/mhd_compat.c @@ -46,26 +46,6 @@ static_dummy_func(void) } #if defined(_WIN32) && !defined(__CYGWIN__) -/** - * Static variable used by pseudo random number generator - */ -static int32_t rnd_val = 0; - -/** - * Generate 31-bit pseudo random number. - * Function initialize itself at first call to current time. - * @return 31-bit pseudo random number. - */ -int MHD_W32_random_(void) -{ - if (0 == rnd_val) - rnd_val = (int32_t)time(NULL); - /* stolen from winsup\cygwin\random.cc */ - rnd_val = (16807 * (rnd_val % 127773) - 2836 * (rnd_val / 127773)) - & 0x7fffffff; - return (int)rnd_val; -} - #ifndef HAVE_SNPRINTF /* Emulate snprintf function on W32 */ diff --git a/src/microhttpd/mhd_compat.h b/src/microhttpd/mhd_compat.h index 7fe3c735..3f88055f 100644 --- a/src/microhttpd/mhd_compat.h +++ b/src/microhttpd/mhd_compat.h @@ -35,6 +35,7 @@ #define MHD_COMPAT_H 1 #include "mhd_options.h" +#include <stdlib.h> /* Platform-independent snprintf name */ #if defined(HAVE_SNPRINTF) @@ -49,19 +50,20 @@ int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, .. #endif /* ! _WIN32*/ #endif /* ! HAVE_SNPRINTF */ -#if !defined(_WIN32) || defined(__CYGWIN__) +#ifdef HAVE_RANDOM +/** + * Generate pseudo random number at least 30-bit wide. + * @return pseudo random number at least 30-bit wide. + */ #define MHD_random_() random() -#else /* _WIN32 && !__CYGWIN__ */ -#define MHD_random_() MHD_W32_random_() - +#else /* HAVE_RANDOM */ +#ifdef HAVE_RAND /** - * Generate 31-bit pseudo random number. - * Function initialize itself at first call to current time. - * @return 31-bit pseudo random number. + * Generate pseudo random number at least 30-bit wide. + * @return pseudo random number at least 30-bit wide. */ -int MHD_W32_random_(void); -#endif /* _WIN32 && !__CYGWIN__ */ - - +#define MHD_random_() ( (((long)rand()) << 15) + (long)rand() ) +#endif /* HAVE_RAND */ +#endif /* HAVE_RANDOM */ #endif /* MHD_COMPAT_H */ |