mhd_compat.h (2861B)
1 /* 2 This file is part of libmicrohttpd 3 Copyright (C) 2014-2021 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.h 23 * @brief Header for platform missing functions. 24 * @author Karlson2k (Evgeny Grin) 25 * 26 * Provides compatibility for platforms with some missing 27 * functionality. 28 * Any functions can be implemented as macro on some platforms 29 * unless explicitly marked otherwise. 30 * Any function argument can be skipped in macro, so avoid 31 * variable modification in function parameters. 32 */ 33 34 #ifndef MHD_COMPAT_H 35 #define MHD_COMPAT_H 1 36 37 #include "mhd_options.h" 38 #ifdef HAVE_STDLIB_H 39 #include <stdlib.h> 40 #endif /* HAVE_STDLIB_H */ 41 #ifdef HAVE_STRING_H /* for strerror() */ 42 #include <string.h> 43 #endif /* HAVE_STRING_H */ 44 45 /* MHD_strerror_ is strerror */ 46 #define MHD_strerror_(errnum) strerror ((errnum)) 47 48 /* Platform-independent snprintf name */ 49 #if defined(HAVE_SNPRINTF) 50 #define MHD_snprintf_ snprintf 51 #else /* ! HAVE_SNPRINTF */ 52 #if defined(_WIN32) && ! defined(__CYGWIN__) 53 /* Emulate snprintf function on W32 */ 54 int W32_snprintf (char *__restrict s, size_t n, const char *__restrict format, 55 ...); 56 57 #define MHD_snprintf_ W32_snprintf 58 #else /* ! _WIN32 || __CYGWIN__ */ 59 #error \ 60 Your platform does not support snprintf() and MHD does not know how to emulate it on your platform. 61 #endif /* ! _WIN32 || __CYGWIN__ */ 62 #endif /* ! HAVE_SNPRINTF */ 63 64 #ifdef HAVE_RANDOM 65 /** 66 * Generate pseudo random number at least 30-bit wide. 67 * @return pseudo random number at least 30-bit wide. 68 */ 69 #define MHD_random_() random () 70 #else /* HAVE_RANDOM */ 71 #ifdef HAVE_RAND 72 /** 73 * Generate pseudo random number at least 30-bit wide. 74 * @return pseudo random number at least 30-bit wide. 75 */ 76 #define MHD_random_() ( (((long) rand ()) << 15) + (long) rand () ) 77 #endif /* HAVE_RAND */ 78 #endif /* HAVE_RANDOM */ 79 80 #ifdef HAVE_CALLOC 81 /** 82 * MHD_calloc_ is platform-independent calloc() 83 */ 84 #define MHD_calloc_(n,s) calloc ((n),(s)) 85 #else /* ! HAVE_CALLOC */ 86 /** 87 * MHD_calloc_ is platform-independent calloc() 88 */ 89 void *MHD_calloc_ (size_t nelem, size_t elsize); 90 91 #endif /* ! HAVE_CALLOC */ 92 93 #endif /* MHD_COMPAT_H */