default features: make musl usable without feature test macros
authorRich Felker <dalias@aerifal.cx>
Sat, 8 Sep 2012 03:13:55 +0000 (23:13 -0400)
committerRich Felker <dalias@aerifal.cx>
Sat, 8 Sep 2012 03:13:55 +0000 (23:13 -0400)
the old behavior of exposing nothing except plain ISO C can be
obtained by defining __STRICT_ANSI__ or using a compiler option (such
as -std=c99) that predefines it. the new default featureset is POSIX
with XSI plus _BSD_SOURCE. any explicit feature test macros will
inhibit the default.

installation docs have also been updated to reflect this change.

48 files changed:
INSTALL
include/aio.h
include/assert.h
include/ctype.h
include/dirent.h
include/dlfcn.h
include/endian.h
include/fcntl.h
include/features.h
include/fnmatch.h
include/ftw.h
include/glob.h
include/grp.h
include/limits.h
include/locale.h
include/math.h
include/net/if.h
include/netdb.h
include/netinet/tcp.h
include/pwd.h
include/sched.h
include/search.h
include/setjmp.h
include/signal.h
include/stdio.h
include/stdlib.h
include/string.h
include/sys/ipc.h
include/sys/mman.h
include/sys/resource.h
include/sys/sem.h
include/sys/sendfile.h
include/sys/shm.h
include/sys/stat.h
include/sys/statfs.h
include/sys/statvfs.h
include/sys/time.h
include/sys/types.h
include/sys/uio.h
include/sys/utsname.h
include/sys/wait.h
include/syslog.h
include/termios.h
include/time.h
include/ucontext.h
include/unistd.h
include/wchar.h
include/wctype.h

diff --git a/INSTALL b/INSTALL
index 720c94e..5c923ee 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -76,14 +76,9 @@ musl-gcc hello.c
 ./a.out
 
 To configure autoconf-based program to compile and link against musl,
-you may wish to use:
+set the CC variable to musl-gcc when running configure, as in:
 
-CC="musl-gcc -D_GNU_SOURCE" ./configure ...
-
-Correctly-written build systems should not need -D_GNU_SOURCE as part
-of $CC, but many programs do not use feature-test macros correctly and
-simply assume the compiler will automatically give them the kitchen
-sink, so the above command is an easy workaround.
+CC=musl-gcc ./configure ...
 
 You will probably also want to use --prefix when building libraries to
 ensure that they are installed under the musl prefix and not in the
@@ -140,9 +135,3 @@ dynamic linker (program interpreter) is /lib/ld-musl-$ARCH.so.1. If
 you're using static linking only, you might instead check the symbols
 and look for anything suspicious that would indicate your old glibc or
 uClibc was used.
-
-When building programs against musl, you may still want to ensure the
-appropriate feature test macros get defined, as in:
-
-CC="gcc -D_GNU_SOURCE" ./configure ...
-
index 3e35134..d9330eb 100644 (file)
@@ -5,12 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
-
+#include <features.h>
 #include <signal.h>
 #include <time.h>
 
index 30a43d6..b0dc692 100644 (file)
@@ -1,11 +1,6 @@
-#undef assert
+#include <features.h>
 
-#if __STDC_VERSION__ >= 201112L
-#elif defined(__GNUC__)
-#define _Noreturn __attribute__((__noreturn__))
-#else
-#define _Noreturn
-#endif
+#undef assert
 
 #ifdef NDEBUG
 #define        assert(x) (void)0
index 8ceaa9f..8f0d168 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 int   isalnum(int);
 int   isalpha(int);
 int   isblank(int);
index b626159..726067f 100644 (file)
@@ -5,11 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
+#include <features.h>
 
 #define __NEED_ino_t
 #define __NEED_off_t
index 53871ee..46c4e18 100644 (file)
@@ -5,11 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
+#include <features.h>
 
 #define RTLD_LAZY   1
 #define RTLD_NOW    2
index 528cef3..1bd4445 100644 (file)
@@ -1,9 +1,7 @@
 #ifndef _ENDIAN_H
 #define _ENDIAN_H
 
-#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
-#define __inline inline
-#endif
+#include <features.h>
 
 #define __LITTLE_ENDIAN 1234
 #define __BIG_ENDIAN 4321
index 87ecf59..4123d01 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_off_t
 #define __NEED_pid_t
 #define __NEED_mode_t
index 851afb6..a7919f3 100644 (file)
@@ -1 +1,28 @@
-#warning "features.h is bogus"
+#ifndef _FEATURES_H
+#define _FEATURES_H
+
+#if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) \
+ && !defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) \
+ && !defined(_BSD_SOURCE) && !defined(__STRICT_ANSI__)
+#define _BSD_SOURCE 1
+#define _XOPEN_SOURCE 700
+#endif
+
+#if __STDC_VERSION__ >= 199901L
+#define __restrict restrict
+#elif !defined(__GNUC__)
+#define __restrict
+#endif
+
+#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
+#define __inline inline
+#endif
+
+#if __STDC_VERSION__ >= 201112L
+#elif defined(__GNUC__)
+#define _Noreturn __attribute__((__noreturn__))
+#else
+#define _Noreturn
+#endif
+
+#endif
index 0731e23..72345b8 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define        FNM_PATHNAME 0x1
 #define        FNM_NOESCAPE 0x2
 #define        FNM_PERIOD   0x4
index e7e8fde..f5eb9f6 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 /* Normally we do not nest header includes. However useless bloat
  * like ftw may be treated as a special case. Otherwise we would
  * have to deal with duplicating all the stat.h mess. */
index c49a2de..9fbbaa6 100644 (file)
@@ -5,11 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
+#include <features.h>
 
 #define __NEED_size_t
 
index 0a55c62..030d7f8 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_size_t
 #define __NEED_gid_t
 
index e354ee7..e12618a 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef _LIMITS_H
 #define _LIMITS_H
 
+#include <features.h>
+
 /* Most limits are system-specific */
 
 #include <bits/limits.h>
index 9da4726..c6cc1ec 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #undef NULL
 #ifdef __cplusplus
 #define NULL 0
index f808be6..9069140 100644 (file)
@@ -5,9 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
-#define __inline inline
-#endif
+#include <features.h>
 
 #define __NEED_float_t
 #define __NEED_double_t
index e862c7c..5813976 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define IF_NAMESIZE 16
 
 struct if_nameindex
index d915d9d..ff691e0 100644 (file)
@@ -5,11 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
+#include <features.h>
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define __NEED_size_t
index 797ce68..5049dd9 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef _NETINET_TCP_H
 #define _NETINET_TCP_H
 
+#include <features.h>
+
 #define TCP_NODELAY 1
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #include <sys/types.h>
index 37ca520..91fe426 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_size_t
 #define __NEED_uid_t
 #define __NEED_gid_t
index e411c92..9062772 100644 (file)
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_struct_timespec
 #define __NEED_pid_t
 #define __NEED_time_t
index 680eee7..ebfe08a 100644 (file)
@@ -5,12 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
-
+#include <features.h>
 
 #define __NEED_size_t
 #include <bits/alltypes.h>
index e5877b4..abc7423 100644 (file)
@@ -5,12 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 201112L
-#elif defined(__GNUC__)
-#define _Noreturn __attribute__((__noreturn__))
-#else
-#define _Noreturn
-#endif
+#include <features.h>
 
 #include <bits/setjmp.h>
 
index e0dae19..1014440 100644 (file)
@@ -5,11 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
+#include <features.h>
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
index 7d3130e..9a20937 100644 (file)
@@ -5,11 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
+#include <features.h>
 
 #define __NEED_FILE
 #define __NEED_va_list
index 86cf017..f7c5971 100644 (file)
@@ -5,18 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
-
-#if __STDC_VERSION__ >= 201112L
-#elif defined(__GNUC__)
-#define _Noreturn __attribute__((__noreturn__))
-#else
-#define _Noreturn
-#endif
+#include <features.h>
 
 #undef NULL
 #ifdef __cplusplus
index f96f71e..5587c88 100644 (file)
@@ -5,11 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
+#include <features.h>
 
 #undef NULL
 #ifdef __cplusplus
index 8e2f717..3f896b8 100644 (file)
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_uid_t
 #define __NEED_gid_t
 #define __NEED_mode_t
index 5cfafbe..0fa32e6 100644 (file)
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_mode_t
 #define __NEED_size_t
 #define __NEED_off_t
index bf59d1c..9536ba3 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_id_t
 #define __NEED_time_t
 #define __NEED_struct_timeval
index add3f1c..cc3a3e6 100644 (file)
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_size_t
 #define __NEED_pid_t
 #define __NEED_time_t
index 1f2b523..e7570d8 100644 (file)
@@ -5,6 +5,7 @@
 extern "C" {
 #endif
 
+#include <features.h>
 #include <unistd.h>
 
 ssize_t sendfile(int, int, off_t *, size_t);
index 34117cc..ce3029f 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_time_t
 #define __NEED_size_t
 #define __NEED_pid_t
index e16a968..c63c6b8 100644 (file)
@@ -4,11 +4,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
+#include <features.h>
 
 #define __NEED_dev_t
 #define __NEED_ino_t
index a5a4db9..d8128a2 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #include <sys/statvfs.h>
 
 typedef struct {
index be41c28..e0839ec 100644 (file)
@@ -5,11 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
+#include <features.h>
 
 #define __NEED_fsblkcnt_t
 #define __NEED_fsfilcnt_t
index bf02643..a0ed8e0 100644 (file)
@@ -4,11 +4,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
+#include <features.h>
 
 #include <sys/select.h>
 
index f5b6487..7378b60 100644 (file)
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_ino_t
 #define __NEED_dev_t
 #define __NEED_uid_t
index 7a75a54..624ff42 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_size_t
 #define __NEED_ssize_t
 #define __NEED_struct_iovec
index 4c36960..6b9ea97 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 struct utsname
 {
        char sysname[65];
index 5e3012b..8bcac8a 100644 (file)
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #include <signal.h>
 
 #define __NEED_pid_t
index c0fde11..a9468d4 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define LOG_EMERG   0
 #define LOG_ALERT   1
 #define LOG_CRIT    2
index 1041759..d73c780 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_pid_t
 
 #include <bits/alltypes.h>
index f24789e..2f4c74f 100644 (file)
@@ -5,11 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
+#include <features.h>
 
 #undef NULL
 #ifdef __cplusplus
index 1121761..28d04ea 100644 (file)
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #include <signal.h>
 
 #ifdef _GNU_SOURCE
index 20ba6cc..b5206a6 100644 (file)
@@ -5,18 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
-
-#if __STDC_VERSION__ >= 201112L
-#elif defined(__GNUC__)
-#define _Noreturn __attribute__((__noreturn__))
-#else
-#define _Noreturn
-#endif
+#include <features.h>
 
 #define STDIN_FILENO  0
 #define STDOUT_FILENO 1
index b1c6b7f..35706c7 100644 (file)
@@ -5,11 +5,7 @@
 extern "C" {
 #endif
 
-#if __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#elif !defined(__GNUC__)
-#define __restrict
-#endif
+#include <features.h>
 
 #define __NEED_FILE
 #define __NEED_va_list
index f7be2cb..abc7d36 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_wint_t
 #define __NEED_wctrans_t
 #define __NEED_wctype_t