libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 8b10b7801c17f9d589cdb4b5131e5621ee088827
parent 29a91f5ddb1e0e5e45a66c2bd628a5573139236e
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sun,  6 Nov 2016 16:52:07 +0300

Stick to C99 standard 'bool' for internals, fallback to 'int' when 'bool' is not available

Diffstat:
Mconfigure.ac | 47+++++++++++++++++++++++++++++++++++------------
Msrc/microhttpd/daemon.c | 10+++-------
Msrc/microhttpd/internal.h | 6+++++-
Msrc/microhttpd/mhd_str.c | 12++++++------
Msrc/microhttpd/test_shutdown_select.c | 6+++---
5 files changed, 52 insertions(+), 29 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -89,19 +89,42 @@ MHD_LIBDEPS="" MHD_REQ_PRIVATE='' MHD_LIBDEPS_PKGCFG='' -AC_CHECK_TYPE([_Bool], - [ AC_DEFINE([_MHD_bool],[_Bool],[Define to type which will be used as boolean type.]) ], +AH_TEMPLATE([[HAVE_STDBOOL_H]], [Define to 1 if you have the <stdbool.h> header file and <stdbool.h> defines 'bool' type.]) +AH_TEMPLATE([[HAVE_REAL_BOOL]], [Define to 1 if you have the real boolean type.]) +AH_TEMPLATE([[bool]], [Define to type name which will be used as boolean type.]) +AC_CHECK_HEADER([stdbool.h], [ - AC_CHECK_HEADER([stdbool.h], [ AC_DEFINE([HAVE_STDBOOL_H],[1],[Define to 1 if you have the <stdbool.h> header file and it's required for _MHD_bool.]) ], [], [AC_INCLUDES_DEFAULT]) - AC_CHECK_TYPE([bool], - [ AC_DEFINE([_MHD_bool],[bool]) ], - [ AC_DEFINE([_MHD_bool],[int]) ], - [[ -#ifdef HAVE_STDBOOL_H + AC_CHECK_TYPE([bool], + [ + AC_DEFINE([[HAVE_STDBOOL_H]], [[1]]) + AC_DEFINE([[HAVE_REAL_BOOL]], [[1]]) + ], + [ + AC_MSG_WARN([[Header <stdbool.h> is present, but "bool" type cannot be detected. Check compiler flags.]]) + AC_DEFINE([[bool]], [[int]]) + ], [ #include <stdbool.h> -#endif - ]]) - ]) + ] + ) + ], + [ + AC_CHECK_TYPE([bool], + [AC_DEFINE([[HAVE_REAL_BOOL]], [[1]])], + [ + AC_CHECK_TYPE([_Bool], + [ + AC_DEFINE([[HAVE_REAL_BOOL]], [[1]]) + AC_DEFINE([[bool]], [[_Bool]]) + ], + [ + AC_DEFINE([[bool]], [[int]]) + ], [] + ) + ], [] + ) + ], + [AC_INCLUDES_DEFAULT] +) AX_CHECK_COMPILE_FLAG([[-Werror=attributes]], [[errattr_CFLAGS="-Werror=attributes"]], @@ -131,7 +154,7 @@ choke me #ifdef HAVE_STDBOOL_H #include <stdbool.h> #endif - static $inln_prfx_chk _MHD_bool cmpfn(int x, int y) + static $inln_prfx_chk bool cmpfn(int x, int y) { return x > y; } static $inln_prfx_chk int sumfn(int x, int y) { return x + y; } diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -39,10 +39,6 @@ #include "mhd_itc.h" #include "mhd_compat.h" -#ifdef HAVE_STDBOOL_H -#include <stdbool.h> -#endif - #if HAVE_SEARCH_H #include <search.h> #else @@ -5447,14 +5443,14 @@ static void close_all_connections (struct MHD_Daemon *daemon) { struct MHD_Connection *pos; - const _MHD_bool used_thr_p_c = (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)); + const bool used_thr_p_c = (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)); #ifdef UPGRADE_SUPPORT - const _MHD_bool upg_allowed = (0 != (daemon->options & MHD_USE_UPGRADE)); + const bool upg_allowed = (0 != (daemon->options & MHD_USE_UPGRADE)); #endif /* UPGRADE_SUPPORT */ #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) struct MHD_UpgradeResponseHandle *urh; struct MHD_UpgradeResponseHandle *urhn; - const _MHD_bool used_tls = (0 != (daemon->options & MHD_USE_TLS)); + const bool used_tls = (0 != (daemon->options & MHD_USE_TLS)); /* give upgraded HTTPS connections a chance to finish */ /* 'daemon->urh_head' is not used in thread-per-connection mode. */ diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -27,6 +27,7 @@ #ifndef INTERNAL_H #define INTERNAL_H +#include "mhd_options.h" #include "platform.h" #include "microhttpd.h" #ifdef HTTPS_SUPPORT @@ -35,7 +36,10 @@ #include <gnutls/abstract.h> #endif #endif /* HTTPS_SUPPORT */ -#include "mhd_options.h" + +#ifdef HAVE_STDBOOL_H +#include <stdbool.h> +#endif #ifdef MHD_PANIC diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c @@ -56,7 +56,7 @@ * @param c character to check * @return non-zero if character is lower case letter, zero otherwise */ -_MHD_inline _MHD_bool +_MHD_inline bool isasciilower (char c) { return (c >= 'a') && (c <= 'z'); @@ -69,7 +69,7 @@ isasciilower (char c) * @param c character to check * @return non-zero if character is upper case letter, zero otherwise */ -_MHD_inline _MHD_bool +_MHD_inline bool isasciiupper (char c) { return (c >= 'A') && (c <= 'Z'); @@ -82,7 +82,7 @@ isasciiupper (char c) * @param c character to check * @return non-zero if character is letter in US-ASCII, zero otherwise */ -_MHD_inline _MHD_bool +_MHD_inline bool isasciialpha (char c) { return isasciilower (c) || isasciiupper (c); @@ -95,7 +95,7 @@ isasciialpha (char c) * @param c character to check * @return non-zero if character is decimal digit, zero otherwise */ -_MHD_inline _MHD_bool +_MHD_inline bool isasciidigit (char c) { return (c >= '0') && (c <= '9'); @@ -108,7 +108,7 @@ isasciidigit (char c) * @param c character to check * @return non-zero if character is decimal digit, zero otherwise */ -_MHD_inline _MHD_bool +_MHD_inline bool isasciixdigit (char c) { return isasciidigit (c) || @@ -123,7 +123,7 @@ isasciixdigit (char c) * @param c character to check * @return non-zero if character is decimal digit or letter, zero otherwise */ -_MHD_inline _MHD_bool +_MHD_inline bool isasciialnum (char c) { return isasciialpha (c) || isasciidigit (c); diff --git a/src/microhttpd/test_shutdown_select.c b/src/microhttpd/test_shutdown_select.c @@ -87,10 +87,10 @@ #define SHUT_RDWR SD_BOTH #endif -static _MHD_bool check_err; +static bool check_err; -static _MHD_bool +static bool has_in_name(const char *prog_name, const char *marker) { size_t name_pos; @@ -284,7 +284,7 @@ main (int argc, char *const *argv) WSADATA wsa_data; int err; #endif /* MHD_WINSOCK_SOCKETS */ - _MHD_bool test_poll; + bool test_poll; test_poll = has_in_name(argv[0], "_poll"); if (!test_poll)