We use a couple of functions not part of the ISO C standard, but instead
part of POSIX.1-2008. There are ancient platforms like SunOS that do not
support this standard, but which _do_ have the required functions hidden
away behind some other macros.
The feature test macros are a bit of a mess. The following functions are
what we require as non-standard extensions:
strdup():
_XOPEN_SOURCE >= 500
|| /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
snprintf(), vsnprintf():
_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L;
or cc -std=c99
mkdtemp():
_BSD_SOURCE
|| /* Since glibc 2.10: */
(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
lstat():
/* Since glibc 2.20 */ _DEFAULT_SOURCE
|| _XOPEN_SOURCE >= 500
|| /* Since glibc 2.10: */ _POSIX_C_SOURCE >= 200112L
|| /* glibc 2.19 and earlier */ _BSD_SOURCE
A few observations:
- We cannot set _POSIX_C_SOURCE to 200809L because it will cause
errors on platforms that do not support POSIX.1-2008.
- We cannot easily set _XOPEN_SOURCE because on SunOS, we would have
to set it conditionally depending on the current C standard used by
the compiler.
What is common to all though is _BSD_SOURCE, even though it has been
deprecated in glibc 2.20. Quoting feature-test-macros(7):
Since glibc 2.20, this macro is deprecated. It now has the same
effect as defining _DEFAULT_SOURCE, but generates a compile-time
warning (unless _DEFAULT_SOURCE is also defined). Use _DEFAULT_SOURCE
instead. To allow code that requires _BSD_SOURCE in glibc 2.19 and
earlier and _DEFAULT_SOURCE in glibc 2.20 and later to compile without
warnings, define both _BSD_SOURCE and _DEFAULT_SOURCE.
So even though _BSD_SOURCE is deprecated, we can set it in tandem with
_DEFAULT_SOURCE. Furthermore, _DEFAULT_SOURCE is defined to be roughly
equivalent to "-D_BSD_SOURCE -D_SVID_SOURCE -D_POSIX_C_SOURCE=200809",
which should thus enables all features required by us.
Replace our use of _POSIX_C_SOURCE with _BSD_SOURCE plus _DEFAULT_SOURCE
to make things work on SunOS.