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) | |
download | libmicrohttpd-a3fc78c87acc9a411959115c071f60adf54a2e11.tar.gz libmicrohttpd-a3fc78c87acc9a411959115c071f60adf54a2e11.zip |
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/ | |||
551 | sockLib.h inetLib.h net/if.h]) | 551 | sockLib.h inetLib.h net/if.h]) |
552 | AM_CONDITIONAL([HAVE_TSEARCH], [test "x$ac_cv_header_search_h" = "xyes"]) | 552 | AM_CONDITIONAL([HAVE_TSEARCH], [test "x$ac_cv_header_search_h" = "xyes"]) |
553 | 553 | ||
554 | # Check for generic functions | ||
555 | AC_CHECK_FUNCS([rand random]) | ||
556 | |||
554 | AC_CHECK_MEMBER([struct sockaddr_in.sin_len], | 557 | AC_CHECK_MEMBER([struct sockaddr_in.sin_len], |
555 | [ AC_DEFINE(HAVE_SOCKADDR_IN_SIN_LEN, 1, [Do we have sockaddr_in.sin_len?]) | 558 | [ AC_DEFINE(HAVE_SOCKADDR_IN_SIN_LEN, 1, [Do we have sockaddr_in.sin_len?]) |
556 | ], | 559 | ], |
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 = \ | |||
167 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 167 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
168 | 168 | ||
169 | test_postprocessor_SOURCES = \ | 169 | test_postprocessor_SOURCES = \ |
170 | test_postprocessor.c mhd_compat.c | 170 | test_postprocessor.c |
171 | test_postprocessor_CPPFLAGS = \ | 171 | test_postprocessor_CPPFLAGS = \ |
172 | $(AM_CPPFLAGS) $(GNUTLS_CPPFLAGS) | 172 | $(AM_CPPFLAGS) $(GNUTLS_CPPFLAGS) |
173 | test_postprocessor_LDADD = \ | 173 | test_postprocessor_LDADD = \ |
@@ -181,7 +181,7 @@ test_postprocessor_amp_LDADD = \ | |||
181 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 181 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
182 | 182 | ||
183 | test_postprocessor_large_SOURCES = \ | 183 | test_postprocessor_large_SOURCES = \ |
184 | test_postprocessor_large.c mhd_compat.c | 184 | test_postprocessor_large.c |
185 | test_postprocessor_large_CPPFLAGS = \ | 185 | test_postprocessor_large_CPPFLAGS = \ |
186 | $(AM_CPPFLAGS) $(GNUTLS_CPPFLAGS) | 186 | $(AM_CPPFLAGS) $(GNUTLS_CPPFLAGS) |
187 | test_postprocessor_large_LDADD = \ | 187 | 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) | |||
46 | } | 46 | } |
47 | 47 | ||
48 | #if defined(_WIN32) && !defined(__CYGWIN__) | 48 | #if defined(_WIN32) && !defined(__CYGWIN__) |
49 | /** | ||
50 | * Static variable used by pseudo random number generator | ||
51 | */ | ||
52 | static int32_t rnd_val = 0; | ||
53 | |||
54 | /** | ||
55 | * Generate 31-bit pseudo random number. | ||
56 | * Function initialize itself at first call to current time. | ||
57 | * @return 31-bit pseudo random number. | ||
58 | */ | ||
59 | int MHD_W32_random_(void) | ||
60 | { | ||
61 | if (0 == rnd_val) | ||
62 | rnd_val = (int32_t)time(NULL); | ||
63 | /* stolen from winsup\cygwin\random.cc */ | ||
64 | rnd_val = (16807 * (rnd_val % 127773) - 2836 * (rnd_val / 127773)) | ||
65 | & 0x7fffffff; | ||
66 | return (int)rnd_val; | ||
67 | } | ||
68 | |||
69 | 49 | ||
70 | #ifndef HAVE_SNPRINTF | 50 | #ifndef HAVE_SNPRINTF |
71 | /* Emulate snprintf function on W32 */ | 51 | /* 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 @@ | |||
35 | #define MHD_COMPAT_H 1 | 35 | #define MHD_COMPAT_H 1 |
36 | 36 | ||
37 | #include "mhd_options.h" | 37 | #include "mhd_options.h" |
38 | #include <stdlib.h> | ||
38 | 39 | ||
39 | /* Platform-independent snprintf name */ | 40 | /* Platform-independent snprintf name */ |
40 | #if defined(HAVE_SNPRINTF) | 41 | #if defined(HAVE_SNPRINTF) |
@@ -49,19 +50,20 @@ int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, .. | |||
49 | #endif /* ! _WIN32*/ | 50 | #endif /* ! _WIN32*/ |
50 | #endif /* ! HAVE_SNPRINTF */ | 51 | #endif /* ! HAVE_SNPRINTF */ |
51 | 52 | ||
52 | #if !defined(_WIN32) || defined(__CYGWIN__) | 53 | #ifdef HAVE_RANDOM |
54 | /** | ||
55 | * Generate pseudo random number at least 30-bit wide. | ||
56 | * @return pseudo random number at least 30-bit wide. | ||
57 | */ | ||
53 | #define MHD_random_() random() | 58 | #define MHD_random_() random() |
54 | #else /* _WIN32 && !__CYGWIN__ */ | 59 | #else /* HAVE_RANDOM */ |
55 | #define MHD_random_() MHD_W32_random_() | 60 | #ifdef HAVE_RAND |
56 | |||
57 | /** | 61 | /** |
58 | * Generate 31-bit pseudo random number. | 62 | * Generate pseudo random number at least 30-bit wide. |
59 | * Function initialize itself at first call to current time. | 63 | * @return pseudo random number at least 30-bit wide. |
60 | * @return 31-bit pseudo random number. | ||
61 | */ | 64 | */ |
62 | int MHD_W32_random_(void); | 65 | #define MHD_random_() ( (((long)rand()) << 15) + (long)rand() ) |
63 | #endif /* _WIN32 && !__CYGWIN__ */ | 66 | #endif /* HAVE_RAND */ |
64 | 67 | #endif /* HAVE_RANDOM */ | |
65 | |||
66 | 68 | ||
67 | #endif /* MHD_COMPAT_H */ | 69 | #endif /* MHD_COMPAT_H */ |