aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_compat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_compat.c')
-rw-r--r--src/microhttpd/mhd_compat.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/microhttpd/mhd_compat.c b/src/microhttpd/mhd_compat.c
new file mode 100644
index 00000000..4911a1c6
--- /dev/null
+++ b/src/microhttpd/mhd_compat.c
@@ -0,0 +1,95 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2014-2016 Karlson2k (Evgeny Grin)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19*/
20
21/**
22 * @file microhttpd/mhd_compat.c
23 * @brief Implementation of platform missing functions.
24 * @author Karlson2k (Evgeny Grin)
25 */
26
27#include "mhd_compat.h"
28#if defined(_WIN32) && !defined(__CYGWIN__)
29#include <stdint.h>
30#include <time.h>
31#ifndef HAVE_SNPRINTF
32#include <stdio.h>
33#include <stdarg.h>
34#endif /* HAVE_SNPRINTF */
35#endif /* _WIN32 && !__CYGWIN__ */
36
37
38/**
39 * Dummy function to silent compiler warning on empty file
40 * @return zero
41 */
42static int
43static_dummy_func(void)
44{
45 return 0;
46}
47
48#if defined(_WIN32) && !defined(__CYGWIN__)
49/**
50 * Static variable used by pseudo random number generator
51 */
52static 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 */
59int 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
70#ifndef HAVE_SNPRINTF
71/* Emulate snprintf function on W32 */
72int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ...)
73{
74 int ret;
75 va_list args;
76 if (0 != n && NULL != s )
77 {
78 va_start(args, format);
79 ret = _vsnprintf(s, n, format, args);
80 va_end(args);
81 if ((int)n == ret)
82 s[n - 1] = 0;
83 if (ret >= 0)
84 return ret;
85 }
86 va_start(args, format);
87 ret = _vscprintf(format, args);
88 va_end(args);
89 if (0 <= ret && 0 != n && NULL == s)
90 return -1;
91
92 return ret;
93}
94#endif /* HAVE_SNPRINTF */
95#endif /* _WIN32 && !__CYGWIN__ */