GNU libmicrohttpd  0.9.29
mhd_compat.c
Go to the documentation of this file.
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 
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 #if defined(_WIN32) && !defined(__CYGWIN__)
39 
40 #ifndef HAVE_SNPRINTF
41 /* Emulate snprintf function on W32 */
42 int
43 W32_snprintf (char *__restrict s,
44  size_t n,
45  const char *__restrict format,
46  ...)
47 {
48  int ret;
49  va_list args;
50 
51  if ( (0 != n) &&
52  (NULL != s) )
53  {
54  va_start (args,
55  format);
56  ret = _vsnprintf (s,
57  n,
58  format,
59  args);
60  va_end (args);
61  if ((int)n == ret)
62  s[n - 1] = 0;
63  if (ret >= 0)
64  return ret;
65  }
66  va_start(args,
67  format);
68  ret = _vscprintf (format,
69  args);
70  va_end(args);
71  if ( (0 <= ret) &&
72  (0 != n) &&
73  (NULL == s) )
74  return -1;
75 
76  return ret;
77 }
78 
79 #endif /* HAVE_SNPRINTF */
80 #endif /* _WIN32 && !__CYGWIN__ */
#define NULL
Definition: reason_phrase.c:30
Header for platform missing functions.