aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_compat.h
blob: 19ebac5f2661db3f5a83549f5adb710a0b3d46e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
  This file is part of libmicrohttpd
  Copyright (C) 2014-2016 Karlson2k (Evgeny Grin)

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

*/

/**
 * @file microhttpd/mhd_compat.h
 * @brief  Header for platform missing functions.
 * @author Karlson2k (Evgeny Grin)
 *
 * Provides compatibility for platforms with some missing
 * functionality.
 * Any functions can be implemented as macro on some platforms
 * unless explicitly marked otherwise.
 * Any function argument can be skipped in macro, so avoid
 * variable modification in function parameters.
 */

#ifndef MHD_COMPAT_H
#define MHD_COMPAT_H 1

#include "mhd_options.h"
#include <stdlib.h>
#ifdef HAVE_STRING_H /* for strerror() */
#include <string.h>
#endif /* HAVE_STRING_H */

 /* MHD_strerror_ is strerror */
#define MHD_strerror_(errnum) strerror((errnum))

/* Platform-independent snprintf name */
#if defined(HAVE_SNPRINTF)
#define MHD_snprintf_ snprintf
#else  /* ! HAVE_SNPRINTF */
#if defined(_WIN32)
/* Emulate snprintf function on W32 */
int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ...);
#define MHD_snprintf_ W32_snprintf
#else  /* ! _WIN32*/
#error Your platform does not support snprintf() and MHD does not know how to emulate it on your platform.
#endif /* ! _WIN32*/
#endif /* ! HAVE_SNPRINTF */

#ifdef HAVE_RANDOM
/**
 * Generate pseudo random number at least 30-bit wide.
 * @return pseudo random number at least 30-bit wide.
 */
#define MHD_random_() random()
#else  /* HAVE_RANDOM */
#ifdef HAVE_RAND
/**
 * Generate pseudo random number at least 30-bit wide.
 * @return pseudo random number at least 30-bit wide.
 */
#define MHD_random_() ( (((long)rand()) << 15) + (long)rand() )
#endif /* HAVE_RAND */
#endif /* HAVE_RANDOM */

#endif /* MHD_COMPAT_H */