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

View File

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