summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2019-02-19 16:23:24 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2019-02-19 16:23:24 +0000
commitff9333d473adb4ae1de2d9323394073793627823 (patch)
tree24780fca6ab8c57e5d8c5d98b61362af33bef4b8 /src/include
parent15eda3d33f9e1160d438d370acd442ef3dbba63f (diff)
downloadskalibs-ff9333d473adb4ae1de2d9323394073793627823.tar.xz
Add skalibs/posixishard.h
This will break things. It's a known issue. Patches to other packages will come later, to adapt them to the new API. To work around brokenness, there needs to be *two* different headers: 1. one to be used before including system headers, that maximizes visibility by enabling system-dependent feature test macros (that will be tested by system headers) 2. one to be used after including system headers, that performs preprocessor tests and defines. skalibs/nonposix.h is the first one. Previously, there was no second one, and the tests were scattered all over. There was a strnlen declaration in skalibs/posixplz.h (which serves a totally different function: declaring things that should be in POSIX, but *are not*, i.e. working around problems in the standard, instead of problems in systems failing to respect the standard), a build-time sysdep for error.h, #defines for MSG_NOSIGNAL, etc. etc. skalibs/posixishard.h now is the second one, and centralizes all the tests. As a result, the eproto sysdep is unnecessary and has been removed. skalibs/error.h is now a static header, it is not built anymore.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/skalibs/bytestr.h2
-rw-r--r--src/include/skalibs/error.h18
-rw-r--r--src/include/skalibs/nonposix.h26
-rw-r--r--src/include/skalibs/posixishard.h30
-rw-r--r--src/include/skalibs/posixplz.h11
-rw-r--r--src/include/skalibs/skalibs.h7
-rw-r--r--src/include/skalibs/stddjb.h1
7 files changed, 69 insertions, 26 deletions
diff --git a/src/include/skalibs/bytestr.h b/src/include/skalibs/bytestr.h
index b20a34d..a0dc027 100644
--- a/src/include/skalibs/bytestr.h
+++ b/src/include/skalibs/bytestr.h
@@ -10,7 +10,7 @@
#include <string.h>
#include <strings.h>
-#include <skalibs/posixplz.h>
+#include <skalibs/posixishard.h>
#define byte_copy(to, n, from) memmove(to, (from), n)
#define byte_copyr(to, n, from) memmove(to, (from), n)
diff --git a/src/include/skalibs/error.h b/src/include/skalibs/error.h
new file mode 100644
index 0000000..353e879
--- /dev/null
+++ b/src/include/skalibs/error.h
@@ -0,0 +1,18 @@
+/* ISC license. */
+
+#ifndef ERROR_H
+#define ERROR_H
+
+#include <skalibs/sysdeps.h>
+#include <skalibs/gccattributes.h>
+
+extern int error_temp (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/nonposix.h b/src/include/skalibs/nonposix.h
index 4ce165c..cf87674 100644
--- a/src/include/skalibs/nonposix.h
+++ b/src/include/skalibs/nonposix.h
@@ -35,12 +35,25 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
+
+
+ /* BSD and Linux libcs that are not glibc: _BSD_SOURCE opens up a
+ lot of extensions. Of course, glibc insisted on changing to a
+ different macro, because coordination and consistency would make
+ developers' life too easy. */
+
+#ifdef __GLIBC__
#ifndef _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#endif
+#else
+#ifndef _BSD_SOURCE
+#define _BSD_SOURCE
+#endif
+#endif
- /* NetBSD: of course they had to have their own macros. */
+ /* NetBSD: of course they had to have their own macro too. */
#ifndef _NETBSD_SOURCE
#define _NETBSD_SOURCE
@@ -50,22 +63,13 @@
#endif
- /* MacOS: needs this for full SUSv3 conformance. Don't ask. */
+ /* MacOS: needs this for full SUSv3 conformance. Standards are hard. */
#ifndef _DARWIN_C_SOURCE
#define _DARWIN_C_SOURCE
#endif
- /* Unfortunately we can't fully avoid #ifdef forests,
- because the BSDs are bloody snowflakes. See: setgroups(). */
-
-#undef SKALIBS_BSD_SUCKS
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__) || defined(__DragonFly__)
-# define SKALIBS_BSD_SUCKS
-#endif
-
-
/* old versions of BSD and some broken GNU toolchains:
system headers are not self-contained,
starting with sys/types.h normally always works. */
diff --git a/src/include/skalibs/posixishard.h b/src/include/skalibs/posixishard.h
new file mode 100644
index 0000000..b5da077
--- /dev/null
+++ b/src/include/skalibs/posixishard.h
@@ -0,0 +1,30 @@
+/* ISC license. */
+
+#ifndef SKALIBS_POSIXISHARD_H
+#define SKALIBS_POSIXISHARD_H
+
+#include <stddef.h>
+
+#include <skalibs/gccattributes.h>
+
+ /*
+ This header must be used with some broken OSes who have
+ serious trouble implementing even easy parts of POSIX.
+ It's supposed to be included *after* system headers, so
+ it won't catch behaviour such as "this macro must be defined
+ prior to including system headers in order to define that
+ symbol". If that's what you need, include skalibs/nonposix.h
+ instead, which must happen *before* system headers.
+ */
+
+extern size_t strnlen (char const *, size_t) gccattr_pure ;
+
+#ifndef EPROTO
+#define EPROTO EPROTOTYPE
+#endif
+
+#ifndef MSG_NOSIGNAL
+#define MSG_NOSIGNAL 0
+#endif
+
+#endif
diff --git a/src/include/skalibs/posixplz.h b/src/include/skalibs/posixplz.h
index dda66ee..639a7c4 100644
--- a/src/include/skalibs/posixplz.h
+++ b/src/include/skalibs/posixplz.h
@@ -18,17 +18,6 @@ extern char **environ ;
/*
- Stuff that _is_ POSIX, but some OSes still don't have it.
- openat() et al. should be here, but they're impossible to
- emulate correctly, and I don't want an app using openat()
- to think it has safe POSIX semantics when it doesn't :/
- EPROTO et al. should be here, but ugh ifdef forests.
- */
-
-extern size_t strnlen (char const *, size_t) gccattr_pure ;
-
-
- /*
Non-POSIX functions that some OSes provide and others don't.
setgroups() isn't included because it's its own kind of broken.
*/
diff --git a/src/include/skalibs/skalibs.h b/src/include/skalibs/skalibs.h
index 2924e1c..ceaad27 100644
--- a/src/include/skalibs/skalibs.h
+++ b/src/include/skalibs/skalibs.h
@@ -4,8 +4,11 @@
#define SKALIBS_H
/*
- This header includes everything in skalibs except skalibs/config.h
- It's heavy!
+ This header is heavy! It includes everything in skalibs except:
+ - skalibs/config.h: package configuration
+ - skalibs/sysdeps.h: system-dependent feature test macros
+ - skalibs/nonposix.h: pre-system headers definitions for POSIX extensions
+ - skalibs/posixishard.h: workarounds for failures to respect POSIX
*/
#include <skalibs/posixplz.h>
diff --git a/src/include/skalibs/stddjb.h b/src/include/skalibs/stddjb.h
index aa90f6a..232b5f3 100644
--- a/src/include/skalibs/stddjb.h
+++ b/src/include/skalibs/stddjb.h
@@ -3,7 +3,6 @@
#ifndef STDDJB_H
#define STDDJB_H
-#include <skalibs/config.h>
#include <skalibs/uint16.h>
#include <skalibs/uint32.h>
#include <skalibs/uint64.h>