diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2014-02-18 18:39:43 +0000 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2014-02-18 18:39:43 +0000 |
commit | 93ed5e5d6665a8f7c5a442b21cc057b89fa26128 (patch) | |
tree | 912a7f2d9854d6b03267bc634c34952f8f71c26d | |
parent | 8b28e693b25992174be3e865ea444414713b27ec (diff) | |
download | libmicrohttpd-93ed5e5d6665a8f7c5a442b21cc057b89fa26128.tar.gz libmicrohttpd-93ed5e5d6665a8f7c5a442b21cc057b89fa26128.zip |
Implement MHD_W32_random(), replace RANDOM() -> MHD_random_()
-rw-r--r-- | src/microhttpd/test_postprocessor.c | 8 | ||||
-rw-r--r-- | src/microhttpd/test_postprocessor_large.c | 2 | ||||
-rw-r--r-- | src/platform/platform_interface.h | 6 | ||||
-rw-r--r-- | src/platform/w32functions.c | 21 | ||||
-rw-r--r-- | src/platform/w32functions.h | 7 |
5 files changed, 39 insertions, 5 deletions
diff --git a/src/microhttpd/test_postprocessor.c b/src/microhttpd/test_postprocessor.c index ac3e2b91..ab309090 100644 --- a/src/microhttpd/test_postprocessor.c +++ b/src/microhttpd/test_postprocessor.c | |||
@@ -141,7 +141,7 @@ test_urlencoding () | |||
141 | size = strlen (URL_DATA); | 141 | size = strlen (URL_DATA); |
142 | while (i < size) | 142 | while (i < size) |
143 | { | 143 | { |
144 | delta = 1 + RANDOM () % (size - i); | 144 | delta = 1 + MHD_random_ () % (size - i); |
145 | MHD_post_process (pp, &URL_DATA[i], delta); | 145 | MHD_post_process (pp, &URL_DATA[i], delta); |
146 | i += delta; | 146 | i += delta; |
147 | } | 147 | } |
@@ -250,7 +250,7 @@ test_multipart () | |||
250 | size = strlen (FORM_DATA); | 250 | size = strlen (FORM_DATA); |
251 | while (i < size) | 251 | while (i < size) |
252 | { | 252 | { |
253 | delta = 1 + RANDOM () % (size - i); | 253 | delta = 1 + MHD_random_ () % (size - i); |
254 | MHD_post_process (pp, &FORM_DATA[i], delta); | 254 | MHD_post_process (pp, &FORM_DATA[i], delta); |
255 | i += delta; | 255 | i += delta; |
256 | } | 256 | } |
@@ -285,7 +285,7 @@ test_nested_multipart () | |||
285 | size = strlen (FORM_NESTED_DATA); | 285 | size = strlen (FORM_NESTED_DATA); |
286 | while (i < size) | 286 | while (i < size) |
287 | { | 287 | { |
288 | delta = 1 + RANDOM () % (size - i); | 288 | delta = 1 + MHD_random_ () % (size - i); |
289 | MHD_post_process (pp, &FORM_NESTED_DATA[i], delta); | 289 | MHD_post_process (pp, &FORM_NESTED_DATA[i], delta); |
290 | i += delta; | 290 | i += delta; |
291 | } | 291 | } |
@@ -319,7 +319,7 @@ test_empty_value () | |||
319 | size = strlen (URL_EMPTY_VALUE_DATA); | 319 | size = strlen (URL_EMPTY_VALUE_DATA); |
320 | while (i < size) | 320 | while (i < size) |
321 | { | 321 | { |
322 | delta = 1 + RANDOM () % (size - i); | 322 | delta = 1 + MHD_random_ () % (size - i); |
323 | MHD_post_process (pp, &URL_EMPTY_VALUE_DATA[i], delta); | 323 | MHD_post_process (pp, &URL_EMPTY_VALUE_DATA[i], delta); |
324 | i += delta; | 324 | i += delta; |
325 | } | 325 | } |
diff --git a/src/microhttpd/test_postprocessor_large.c b/src/microhttpd/test_postprocessor_large.c index 2af84dcc..e798c80b 100644 --- a/src/microhttpd/test_postprocessor_large.c +++ b/src/microhttpd/test_postprocessor_large.c | |||
@@ -83,7 +83,7 @@ test_simple_large () | |||
83 | size = strlen (data); | 83 | size = strlen (data); |
84 | while (i < size) | 84 | while (i < size) |
85 | { | 85 | { |
86 | delta = 1 + RANDOM () % (size - i); | 86 | delta = 1 + MHD_random_ () % (size - i); |
87 | MHD_post_process (pp, &data[i], delta); | 87 | MHD_post_process (pp, &data[i], delta); |
88 | i += delta; | 88 | i += delta; |
89 | } | 89 | } |
diff --git a/src/platform/platform_interface.h b/src/platform/platform_interface.h index 42cfae23..22f78166 100644 --- a/src/platform/platform_interface.h +++ b/src/platform/platform_interface.h | |||
@@ -133,4 +133,10 @@ | |||
133 | #define MHD_INVALID_PIPE_ MHD_INVALID_SOCKET | 133 | #define MHD_INVALID_PIPE_ MHD_INVALID_SOCKET |
134 | #endif | 134 | #endif |
135 | 135 | ||
136 | #if !defined(_WIN32) || defined(__CYGWIN__) | ||
137 | #define MHD_random_() random() | ||
138 | #else | ||
139 | #define MHD_random_() MHD_W32_random() | ||
140 | #endif | ||
141 | |||
136 | #endif // MHD_PLATFORM_INTERFACE_H | 142 | #endif // MHD_PLATFORM_INTERFACE_H |
diff --git a/src/platform/w32functions.c b/src/platform/w32functions.c index 34c5d73d..3c25e2b2 100644 --- a/src/platform/w32functions.c +++ b/src/platform/w32functions.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include <errno.h> | 27 | #include <errno.h> |
28 | #include <winsock2.h> | 28 | #include <winsock2.h> |
29 | #include <string.h> | 29 | #include <string.h> |
30 | #include <stdint.h> | ||
31 | #include <time.h> | ||
30 | 32 | ||
31 | /** | 33 | /** |
32 | * Return errno equivalent of last winsock error | 34 | * Return errno equivalent of last winsock error |
@@ -618,3 +620,22 @@ int MHD_W32_pair_of_sockets_(SOCKET sockets_pair[2]) | |||
618 | sockets_pair[1] = INVALID_SOCKET; | 620 | sockets_pair[1] = INVALID_SOCKET; |
619 | return -1; | 621 | return -1; |
620 | } | 622 | } |
623 | |||
624 | /** | ||
625 | * Static variable used by pseudo random number generator | ||
626 | */ | ||
627 | static int32_t rnd_val = 0; | ||
628 | /** | ||
629 | * Generate 31-bit pseudo random number. | ||
630 | * Function initialize itself at first call to current time. | ||
631 | * @return 31-bit pseudo random number. | ||
632 | */ | ||
633 | int MHD_W32_random(void) | ||
634 | { | ||
635 | if (0 == rnd_val) | ||
636 | rnd_val = (int32_t)time(NULL); | ||
637 | /* stolen from winsup\cygwin\random.cc */ | ||
638 | rnd_val = (16807 * (rnd_val % 127773) - 2836 * (rnd_val / 127773)) | ||
639 | & 0x7fffffff; | ||
640 | return (int)rnd_val; | ||
641 | } | ||
diff --git a/src/platform/w32functions.h b/src/platform/w32functions.h index 2c0cdcff..7a25803b 100644 --- a/src/platform/w32functions.h +++ b/src/platform/w32functions.h | |||
@@ -177,6 +177,13 @@ void MHD_W32_set_last_winsock_error_(int errnum); | |||
177 | * @return zero on success, -1 otherwise | 177 | * @return zero on success, -1 otherwise |
178 | */ | 178 | */ |
179 | int MHD_W32_pair_of_sockets_(SOCKET sockets_pair[2]); | 179 | int MHD_W32_pair_of_sockets_(SOCKET sockets_pair[2]); |
180 | /** | ||
181 | * Generate 31-bit pseudo random number. | ||
182 | * Function initialize itself at first call to current time. | ||
183 | * @return 31-bit pseudo random number. | ||
184 | */ | ||
185 | _MHD_EXTERN int MHD_W32_random(void); /* must be exported for "make check" tests */ | ||
186 | /* TODO: exclude from exports */ | ||
180 | 187 | ||
181 | #ifdef __cplusplus | 188 | #ifdef __cplusplus |
182 | } | 189 | } |