aboutsummaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/platform_interface.h6
-rw-r--r--src/platform/w32functions.c21
-rw-r--r--src/platform/w32functions.h7
3 files changed, 34 insertions, 0 deletions
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 */
627static 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 */
633int 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 */
179int MHD_W32_pair_of_sockets_(SOCKET sockets_pair[2]); 179int 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}