Improve ssize_t and socklen_t checks

This commit is contained in:
Boris Kolpackov 2022-09-04 12:57:24 +02:00
parent a9d13e2519
commit 04b6d354b1
3 changed files with 55 additions and 48 deletions

View File

@ -32,11 +32,16 @@
* #if defined(__OpenBSD__) * #if defined(__OpenBSD__)
* #if defined(__NetBSD__) * #if defined(__NetBSD__)
* *
* Except for MacOS, which we detect using our own macro (for the sake of * Except for MacOS specifically, which we detect using our own macro (for
* simplicity): * the sake of simplicity):
* *
* #if defined(BUILD2_AUTOCONF_MACOS) * #if defined(BUILD2_AUTOCONF_MACOS)
* *
* If, however, you want to cover the entire Apple operation systems family,
* then use:
*
* #if defined(__APPLE__)
*
* Macros for detecting platforms and their versions: * Macros for detecting platforms and their versions:
* *
* __GLIBC__: The glibc major version number. * __GLIBC__: The glibc major version number.

View File

@ -1,10 +1,9 @@
// socklen_t : BUILD2_AUTOCONF_LIBC_VERSION // socklen_t!
#ifndef BUILD2_AUTOCONF_LIBC_VERSION /* If socklen_t is already defined, assume it's correct and use it as-is (see
# error BUILD2_AUTOCONF_LIBC_VERSION appears to be conditionally included * ssize_t for details).
#endif */
#ifndef socklen_t
#undef socklen_t
/* Since 4.xBSD, SunOS /* Since 4.xBSD, SunOS
* The Single UNIX Specification, Version 2 * The Single UNIX Specification, Version 2
@ -13,19 +12,20 @@
* To forestall portability problems, it is recommended that * To forestall portability problems, it is recommended that
* applications should not use values larger than 232 - 1. * applications should not use values larger than 232 - 1.
*/ */
#if defined(__linux__) || \ # if defined(__linux__) || \
defined(__FreeBSD__) || \ defined(__FreeBSD__) || \
defined(__OpenBSD__) || \ defined(__OpenBSD__) || \
defined(__NetBSD__) || \ defined(__NetBSD__) || \
defined(BUILD2_AUTOCONF_MACOS) || \ defined(__APPLE__) || \
(defined(__sun) && defined(__SVR4)) || \ (defined(__sun) && defined(__SVR4)) || \
defined(__CYGWIN__) defined(__CYGWIN__)
# include <sys/socket.h> # include <sys/socket.h>
/* If available, we do nothing. */ /* If available, we do nothing. */
#elif defined(_WIN32) # elif defined(_WIN32)
# include <ws2tcpip.h> # include <ws2tcpip.h>
/* If available, we do nothing. */ /* If available, we do nothing. */
#else # else
/* Else define it to unsigned int (suggested fallback by libevent). */ /* Else define it to unsigned int (suggested fallback by libevent). */
# define socklen_t unsigned int # define socklen_t unsigned int
# endif
#endif #endif

View File

@ -1,28 +1,30 @@
// ssize_t : BUILD2_AUTOCONF_LIBC_VERSION // ssize_t!
#ifndef BUILD2_AUTOCONF_LIBC_VERSION /* If ssize_t is already defined, assume it's correct and use it as-is.
# error BUILD2_AUTOCONF_LIBC_VERSION appears to be conditionally included *
#endif * Note that we may not be able to redefine it because while we can undef the
* macro, there is no guarantee we will be able to re-include the header (due
#undef ssize_t * to include guards).
/* POSIX and MinGW (which also has <sys/types.h> that defines ssize_t).
*/ */
#if defined(__linux__) || \ #ifndef ssize_t
/* POSIX and MinGW (which also has <sys/types.h> that defines ssize_t).
*/
# if defined(__linux__) || \
defined(__FreeBSD__) || \ defined(__FreeBSD__) || \
defined(__OpenBSD__) || \ defined(__OpenBSD__) || \
defined(__NetBSD__) || \ defined(__NetBSD__) || \
defined(BUILD2_AUTOCONF_MACOS) || \ defined(__APPLE__) || \
defined(__MINGW32__) || \ defined(__MINGW32__) || \
(defined(__sun) && defined(__SVR4)) || \ (defined(__sun) && defined(__SVR4)) || \
defined(__CYGWIN__) defined(__CYGWIN__)
# include <sys/types.h> # include <sys/types.h>
/* If available, we do nothing. */ /* If available, we do nothing. */
#elif defined(_WIN32) # elif defined(_WIN32)
# include <basetsd.h> # include <basetsd.h>
/* Use define instead of typedef to avoid conflicts. */ /* Use define instead of typedef to avoid conflicts. */
# define ssize_t SSIZE_T # define ssize_t SSIZE_T
#else # else
/* Else define it to int (suggested fallback by libevent). */ /* Else define it to int (suggested fallback by libevent). */
# define ssize_t int # define ssize_t int
# endif
#endif #endif