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
@ -17,7 +16,7 @@
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>
@ -29,3 +28,4 @@
/* 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,18 +1,19 @@
// 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
/* 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).
*/
#ifndef ssize_t
/* POSIX and MinGW (which also has <sys/types.h> that defines ssize_t). /* POSIX and MinGW (which also has <sys/types.h> that defines ssize_t).
*/ */
# 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(__MINGW32__) || \ defined(__MINGW32__) || \
(defined(__sun) && defined(__SVR4)) || \ (defined(__sun) && defined(__SVR4)) || \
defined(__CYGWIN__) defined(__CYGWIN__)
@ -26,3 +27,4 @@
/* 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