From d44819ae9c55f4d3c0f347b2640f58a2deddebb4 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 22 Jul 2019 13:58:11 +0000 Subject: Factor all the BSD complaints into one new header --- src/headers/bits-template | 6 ++--- src/include/skalibs/bsdsnowflake.h | 48 ++++++++++++++++++++++++++++++++++ src/include/skalibs/error.h | 12 +++------ src/include/skalibs/posixishard.h | 10 ------- src/libbiguint/bu_addc.c | 6 +---- src/libbiguint/bu_copy.c | 6 +---- src/libbiguint/bu_scan.c | 6 +---- src/libbiguint/bu_subc.c | 6 +---- src/libposixplz/setgroups.c | 1 + src/libstddjb/cdb_init_map.c | 5 +--- src/libstddjb/error_isalready.c | 14 ++++++++++ src/libstddjb/iopause_ppoll.c | 11 +------- src/libstddjb/iopause_select.c | 6 +---- src/libstddjb/localtm_from_ltm64.c | 6 +---- src/libstddjb/tai_u64.c | 6 +---- src/libstddjb/time_from_tai.c | 6 +---- src/libstddjb/time_from_tai_relative.c | 6 +---- src/libstddjb/time_sysclock_from_tai.c | 6 +---- 18 files changed, 81 insertions(+), 86 deletions(-) create mode 100644 src/include/skalibs/bsdsnowflake.h create mode 100644 src/libstddjb/error_isalready.c (limited to 'src') diff --git a/src/headers/bits-template b/src/headers/bits-template index fa08dd9..f6cde95 100644 --- a/src/headers/bits-template +++ b/src/headers/bits-template @@ -10,8 +10,8 @@ extern uint@BITS@_t uint@BITS@_bswap (uint@BITS@_t) ; #define UINT@BITS@_XFMT @XFMT@ #define UINT@BITS@_BFMT @BFMT@ -#define uint@BITS@_fmt_base(s, u, base) uint64_fmt_generic(s, u, base) -#define uint@BITS@0_fmt_base(s, u, n, base) uint640_fmt_generic(s, u, n, base) +#define uint@BITS@_fmt_base uint64_fmt_generic +#define uint@BITS@0_fmt_base uint640_fmt_generic #define uint@BITS@_fmt(s, u) uint@BITS@_fmt_base(s, (u), 10) #define uint@BITS@0_fmt(s, u, n) uint@BITS@0_fmt_base(s, u, (n), 10) #define uint@BITS@_ofmt(s, o) uint@BITS@_fmt_base(s, (o), 8) @@ -37,7 +37,7 @@ extern size_t uint@BITS@0_scan_base (char const *, uint@BITS@_t *, uint8_t) ; extern size_t uint@BITS@_scanlist (uint@BITS@_t *, size_t, char const *, size_t *) ; -#define int@BITS@_fmt_base(s, u, base) int64_fmt_generic(s, u, base) +#define int@BITS@_fmt_base int64_fmt_generic #define int@BITS@_fmt(s, u) int@BITS@_fmt_base(s, (u), 10) #define int@BITS@_ofmt(s, o) int@BITS@_fmt_base(s, (o), 8) #define int@BITS@_xfmt(s, x) int@BITS@_fmt_base(s, (x), 16) diff --git a/src/include/skalibs/bsdsnowflake.h b/src/include/skalibs/bsdsnowflake.h new file mode 100644 index 0000000..97186d2 --- /dev/null +++ b/src/include/skalibs/bsdsnowflake.h @@ -0,0 +1,48 @@ +/* ISC license. */ + +#ifndef SKALIBS_BSDSNOWFLAKE_H +#define SKALIBS_BSDSNOWFLAKE_H + + /* + Like skalibs/nonposix.h, this header is supposed to be included + *before* system headers. + Unlike skalibs/nonposix.h, though, it does not define ftms that + enable non-portable behaviour; it just attempts to work around + blatant brokenness, things that actually ARE defined by POSIX + but where OSes just ignore the spec. + The BSDs are experts at this, hence the name. + */ + + +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__) || defined(__DragonFly__) + + /* BSDs: the eponym. + Sometimes you just need to recognize who they are and what they do. */ + +#ifndef SKALIBS_BSD_SUCKS +#define SKALIBS_BSD_SUCKS +#endif + + /* Other times you just need to say you're a BSD so they deign + to define symbols like EOVERFLOW. Give me my POSIX symbols, + pretty please? */ + +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif + +#endif + + +#if defined(__APPLE__) && defined(__MACH__) + + /* MacOS: needs this for full SUSv3 conformance. That's how you + can tell it's really a BSD inside. With additional layers of crap. */ + +#ifndef _DARWIN_C_SOURCE +#define _DARWIN_C_SOURCE +#endif + +#endif /* __APPLE__ && __MACH__ */ + +#endif /* SKALIBS_BSDSNOWFLAKE_H */ diff --git a/src/include/skalibs/error.h b/src/include/skalibs/error.h index 353e879..5431eb9 100644 --- a/src/include/skalibs/error.h +++ b/src/include/skalibs/error.h @@ -1,18 +1,12 @@ /* ISC license. */ -#ifndef ERROR_H -#define ERROR_H +#ifndef SKALIBS_ERROR_H +#define SKALIBS_ERROR_H -#include #include extern int error_temp (int) gccattr_const ; +extern int error_isalready (int) gccattr_const ; #define error_isagain(e) (((e) == EAGAIN) || ((e) == EWOULDBLOCK)) -#ifdef SKALIBS_BSD_SUCKS -# define error_isalready(e) (((e) == EALREADY) || ((e) == EINPROGRESS) || ((e) == EADDRINUSE)) -#else -# define error_isalready(e) (((e) == EALREADY) || ((e) == EINPROGRESS)) -#endif - #endif diff --git a/src/include/skalibs/posixishard.h b/src/include/skalibs/posixishard.h index b813494..b5da077 100644 --- a/src/include/skalibs/posixishard.h +++ b/src/include/skalibs/posixishard.h @@ -27,14 +27,4 @@ extern size_t strnlen (char const *, size_t) gccattr_pure ; #define MSG_NOSIGNAL 0 #endif -#if defined(__APPLE__) && defined(__MACH__) - - /* MacOS: needs this for full SUSv3 conformance. */ - -#ifndef _DARWIN_C_SOURCE -#define _DARWIN_C_SOURCE -#endif - -#endif /* __APPLE__ && __MACH__ */ - #endif diff --git a/src/libbiguint/bu_addc.c b/src/libbiguint/bu_addc.c index a9c6dce..b6d1ccb 100644 --- a/src/libbiguint/bu_addc.c +++ b/src/libbiguint/bu_addc.c @@ -1,10 +1,6 @@ /* ISC license. */ -/* OpenBSD needs that for EOVERFLOW. wtfbsdseriously */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - +#include #include #include diff --git a/src/libbiguint/bu_copy.c b/src/libbiguint/bu_copy.c index 10f59b9..0c64417 100644 --- a/src/libbiguint/bu_copy.c +++ b/src/libbiguint/bu_copy.c @@ -1,10 +1,6 @@ /* ISC license. */ -/* OpenBSD needs that for EOVERFLOW. wtfbsdseriously */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - +#include #include #include diff --git a/src/libbiguint/bu_scan.c b/src/libbiguint/bu_scan.c index 44aa315..8d4ecd0 100644 --- a/src/libbiguint/bu_scan.c +++ b/src/libbiguint/bu_scan.c @@ -1,10 +1,6 @@ /* ISC license. */ -/* OpenBSD needs that for EOVERFLOW. wtfbsdseriously */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - +#include #include #include #include diff --git a/src/libbiguint/bu_subc.c b/src/libbiguint/bu_subc.c index 69aa6ab..63147b0 100644 --- a/src/libbiguint/bu_subc.c +++ b/src/libbiguint/bu_subc.c @@ -1,10 +1,6 @@ /* ISC license. */ -/* OpenBSD needs that for EOVERFLOW. wtfbsdseriously */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - +#include #include #include diff --git a/src/libposixplz/setgroups.c b/src/libposixplz/setgroups.c index d064ed2..fff507f 100644 --- a/src/libposixplz/setgroups.c +++ b/src/libposixplz/setgroups.c @@ -5,6 +5,7 @@ #ifdef SKALIBS_HASSETGROUPS #include +#include #include #include #include diff --git a/src/libstddjb/cdb_init_map.c b/src/libstddjb/cdb_init_map.c index 9851faa..55fb02a 100644 --- a/src/libstddjb/cdb_init_map.c +++ b/src/libstddjb/cdb_init_map.c @@ -1,9 +1,6 @@ /* ISC license. */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - +#include #include #include #include diff --git a/src/libstddjb/error_isalready.c b/src/libstddjb/error_isalready.c new file mode 100644 index 0000000..db63932 --- /dev/null +++ b/src/libstddjb/error_isalready.c @@ -0,0 +1,14 @@ +/* ISC license. */ + +#include +#include +#include + +int error_isalready (int e) +{ + return e == EALREADY || e == EINPROGRESS +#ifdef SKALIBS_BSD_SUCKS + || e == ADDRINUSE +#endif + ; +} diff --git a/src/libstddjb/iopause_ppoll.c b/src/libstddjb/iopause_ppoll.c index 960a464..0c571e1 100644 --- a/src/libstddjb/iopause_ppoll.c +++ b/src/libstddjb/iopause_ppoll.c @@ -4,16 +4,7 @@ #ifdef SKALIBS_HASPPOLL -/* Just in case OpenBSD implements ppoll before fixing EOVERFLOW. - Stranger things have happened in the wonderful world of OpenBSD. */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - +#include #include #include #include diff --git a/src/libstddjb/iopause_select.c b/src/libstddjb/iopause_select.c index b6bdd2d..8b8479b 100644 --- a/src/libstddjb/iopause_select.c +++ b/src/libstddjb/iopause_select.c @@ -1,10 +1,6 @@ /* ISC license. */ -/* OpenBSD needs that for EOVERFLOW. wtfbsdseriously */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - +#include #include /* Solaris... */ #include #include diff --git a/src/libstddjb/localtm_from_ltm64.c b/src/libstddjb/localtm_from_ltm64.c index 8eba409..74d2fb3 100644 --- a/src/libstddjb/localtm_from_ltm64.c +++ b/src/libstddjb/localtm_from_ltm64.c @@ -1,11 +1,7 @@ /* ISC license. */ -/* OpenBSD needs that for EOVERFLOW. wtfbsdseriously */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - #include +#include #include #include #include diff --git a/src/libstddjb/tai_u64.c b/src/libstddjb/tai_u64.c index 624f2cb..1d7eabe 100644 --- a/src/libstddjb/tai_u64.c +++ b/src/libstddjb/tai_u64.c @@ -1,10 +1,6 @@ /* ISC license. */ -/* OpenBSD needs that for EOVERFLOW. wtfbsdseriously */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - +#include #include #include #include diff --git a/src/libstddjb/time_from_tai.c b/src/libstddjb/time_from_tai.c index 1f4ff2a..f3f9538 100644 --- a/src/libstddjb/time_from_tai.c +++ b/src/libstddjb/time_from_tai.c @@ -1,11 +1,7 @@ /* ISC license. */ -/* OpenBSD needs that for EOVERFLOW. wtfbsdseriously */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - #include +#include #include #include #include diff --git a/src/libstddjb/time_from_tai_relative.c b/src/libstddjb/time_from_tai_relative.c index 1d11e2e..598d80b 100644 --- a/src/libstddjb/time_from_tai_relative.c +++ b/src/libstddjb/time_from_tai_relative.c @@ -1,11 +1,7 @@ /* ISC license. */ -/* OpenBSD needs that for EOVERFLOW. wtfbsdseriously */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - #include +#include #include #include #include diff --git a/src/libstddjb/time_sysclock_from_tai.c b/src/libstddjb/time_sysclock_from_tai.c index 3e8322b..b0fd689 100644 --- a/src/libstddjb/time_sysclock_from_tai.c +++ b/src/libstddjb/time_sysclock_from_tai.c @@ -1,11 +1,7 @@ /* ISC license. */ -/* OpenBSD needs that for EOVERFLOW. wtfbsdseriously */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - #include +#include #include #include #include -- cgit v1.2.3