mailing list of musl libc
 help / color / mirror / code / Atom feed
* proposed default-features patch
@ 2012-09-08  0:46 Rich Felker
  2012-09-08  3:18 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Rich Felker @ 2012-09-08  0:46 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 380 bytes --]

Hi all,

Here is my first try at implementing "default features". In the
interest of efficiency/laziness, #include <features.h> is only added
to headers which inspect at least one feature test macro. Some of the
places it's added may actually be unnecessary, for example if the only
feature test macro tested is _GNU_SOURCE, but I don't think it
matters.

Comments welcome.

Rich

[-- Attachment #2: default-features-try1.diff --]
[-- Type: text/plain, Size: 15053 bytes --]

diff --git a/include/aio.h b/include/aio.h
index 3e35134..d9330eb 100644
--- a/include/aio.h
+++ b/include/aio.h
@@ -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>
 
diff --git a/include/assert.h b/include/assert.h
index 30a43d6..b0dc692 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -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
diff --git a/include/ctype.h b/include/ctype.h
index 8ceaa9f..8f0d168 100644
--- a/include/ctype.h
+++ b/include/ctype.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 int   isalnum(int);
 int   isalpha(int);
 int   isblank(int);
diff --git a/include/dirent.h b/include/dirent.h
index b626159..726067f 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -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
diff --git a/include/dlfcn.h b/include/dlfcn.h
index 53871ee..46c4e18 100644
--- a/include/dlfcn.h
+++ b/include/dlfcn.h
@@ -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
diff --git a/include/endian.h b/include/endian.h
index 528cef3..1bd4445 100644
--- a/include/endian.h
+++ b/include/endian.h
@@ -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
diff --git a/include/fcntl.h b/include/fcntl.h
index 87ecf59..4123d01 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_off_t
 #define __NEED_pid_t
 #define __NEED_mode_t
diff --git a/include/features.h b/include/features.h
index 851afb6..a7919f3 100644
--- a/include/features.h
+++ b/include/features.h
@@ -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
diff --git a/include/fnmatch.h b/include/fnmatch.h
index 0731e23..72345b8 100644
--- a/include/fnmatch.h
+++ b/include/fnmatch.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define	FNM_PATHNAME 0x1
 #define	FNM_NOESCAPE 0x2
 #define	FNM_PERIOD   0x4
diff --git a/include/ftw.h b/include/ftw.h
index e7e8fde..f5eb9f6 100644
--- a/include/ftw.h
+++ b/include/ftw.h
@@ -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. */
diff --git a/include/glob.h b/include/glob.h
index c49a2de..9fbbaa6 100644
--- a/include/glob.h
+++ b/include/glob.h
@@ -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
 
diff --git a/include/grp.h b/include/grp.h
index 0a55c62..030d7f8 100644
--- a/include/grp.h
+++ b/include/grp.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_size_t
 #define __NEED_gid_t
 
diff --git a/include/limits.h b/include/limits.h
index e354ee7..e12618a 100644
--- a/include/limits.h
+++ b/include/limits.h
@@ -1,6 +1,8 @@
 #ifndef _LIMITS_H
 #define _LIMITS_H
 
+#include <features.h>
+
 /* Most limits are system-specific */
 
 #include <bits/limits.h>
diff --git a/include/locale.h b/include/locale.h
index 9da4726..c6cc1ec 100644
--- a/include/locale.h
+++ b/include/locale.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #undef NULL
 #ifdef __cplusplus
 #define NULL 0
diff --git a/include/math.h b/include/math.h
index f808be6..9069140 100644
--- a/include/math.h
+++ b/include/math.h
@@ -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
diff --git a/include/net/if.h b/include/net/if.h
index e862c7c..5813976 100644
--- a/include/net/if.h
+++ b/include/net/if.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define IF_NAMESIZE 16
 
 struct if_nameindex
diff --git a/include/netdb.h b/include/netdb.h
index d915d9d..ff691e0 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -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
diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h
index 797ce68..5049dd9 100644
--- a/include/netinet/tcp.h
+++ b/include/netinet/tcp.h
@@ -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>
diff --git a/include/pwd.h b/include/pwd.h
index 37ca520..91fe426 100644
--- a/include/pwd.h
+++ b/include/pwd.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_size_t
 #define __NEED_uid_t
 #define __NEED_gid_t
diff --git a/include/sched.h b/include/sched.h
index e411c92..9062772 100644
--- a/include/sched.h
+++ b/include/sched.h
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_struct_timespec
 #define __NEED_pid_t
 #define __NEED_time_t
diff --git a/include/search.h b/include/search.h
index 680eee7..ebfe08a 100644
--- a/include/search.h
+++ b/include/search.h
@@ -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>
diff --git a/include/setjmp.h b/include/setjmp.h
index e5877b4..abc7423 100644
--- a/include/setjmp.h
+++ b/include/setjmp.h
@@ -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>
 
diff --git a/include/signal.h b/include/signal.h
index e0dae19..1014440 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -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) \
diff --git a/include/stdio.h b/include/stdio.h
index 7d3130e..9a20937 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -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
diff --git a/include/stdlib.h b/include/stdlib.h
index 86cf017..f7c5971 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -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
diff --git a/include/string.h b/include/string.h
index f96f71e..5587c88 100644
--- a/include/string.h
+++ b/include/string.h
@@ -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
diff --git a/include/sys/ipc.h b/include/sys/ipc.h
index 8e2f717..3f896b8 100644
--- a/include/sys/ipc.h
+++ b/include/sys/ipc.h
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_uid_t
 #define __NEED_gid_t
 #define __NEED_mode_t
diff --git a/include/sys/mman.h b/include/sys/mman.h
index 5cfafbe..0fa32e6 100644
--- a/include/sys/mman.h
+++ b/include/sys/mman.h
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_mode_t
 #define __NEED_size_t
 #define __NEED_off_t
diff --git a/include/sys/resource.h b/include/sys/resource.h
index bf59d1c..9536ba3 100644
--- a/include/sys/resource.h
+++ b/include/sys/resource.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_id_t
 #define __NEED_time_t
 #define __NEED_struct_timeval
diff --git a/include/sys/sem.h b/include/sys/sem.h
index add3f1c..cc3a3e6 100644
--- a/include/sys/sem.h
+++ b/include/sys/sem.h
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_size_t
 #define __NEED_pid_t
 #define __NEED_time_t
diff --git a/include/sys/sendfile.h b/include/sys/sendfile.h
index 1f2b523..e7570d8 100644
--- a/include/sys/sendfile.h
+++ b/include/sys/sendfile.h
@@ -5,6 +5,7 @@
 extern "C" {
 #endif
 
+#include <features.h>
 #include <unistd.h>
 
 ssize_t sendfile(int, int, off_t *, size_t);
diff --git a/include/sys/shm.h b/include/sys/shm.h
index 34117cc..ce3029f 100644
--- a/include/sys/shm.h
+++ b/include/sys/shm.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_time_t
 #define __NEED_size_t
 #define __NEED_pid_t
diff --git a/include/sys/stat.h b/include/sys/stat.h
index e16a968..c63c6b8 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -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
diff --git a/include/sys/statfs.h b/include/sys/statfs.h
index a5a4db9..d8128a2 100644
--- a/include/sys/statfs.h
+++ b/include/sys/statfs.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #include <sys/statvfs.h>
 
 typedef struct {
diff --git a/include/sys/statvfs.h b/include/sys/statvfs.h
index be41c28..e0839ec 100644
--- a/include/sys/statvfs.h
+++ b/include/sys/statvfs.h
@@ -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
diff --git a/include/sys/time.h b/include/sys/time.h
index bf02643..a0ed8e0 100644
--- a/include/sys/time.h
+++ b/include/sys/time.h
@@ -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>
 
diff --git a/include/sys/types.h b/include/sys/types.h
index f5b6487..7378b60 100644
--- a/include/sys/types.h
+++ b/include/sys/types.h
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_ino_t
 #define __NEED_dev_t
 #define __NEED_uid_t
diff --git a/include/sys/uio.h b/include/sys/uio.h
index 7a75a54..624ff42 100644
--- a/include/sys/uio.h
+++ b/include/sys/uio.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_size_t
 #define __NEED_ssize_t
 #define __NEED_struct_iovec
diff --git a/include/sys/utsname.h b/include/sys/utsname.h
index 4c36960..6b9ea97 100644
--- a/include/sys/utsname.h
+++ b/include/sys/utsname.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 struct utsname
 {
 	char sysname[65];
diff --git a/include/sys/wait.h b/include/sys/wait.h
index 5e3012b..8bcac8a 100644
--- a/include/sys/wait.h
+++ b/include/sys/wait.h
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #include <signal.h>
 
 #define __NEED_pid_t
diff --git a/include/syslog.h b/include/syslog.h
index c0fde11..a9468d4 100644
--- a/include/syslog.h
+++ b/include/syslog.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define LOG_EMERG   0
 #define LOG_ALERT   1
 #define LOG_CRIT    2
diff --git a/include/termios.h b/include/termios.h
index 1041759..d73c780 100644
--- a/include/termios.h
+++ b/include/termios.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_pid_t
 
 #include <bits/alltypes.h>
diff --git a/include/time.h b/include/time.h
index f24789e..2f4c74f 100644
--- a/include/time.h
+++ b/include/time.h
@@ -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
diff --git a/include/ucontext.h b/include/ucontext.h
index 1121761..28d04ea 100644
--- a/include/ucontext.h
+++ b/include/ucontext.h
@@ -4,6 +4,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #include <signal.h>
 
 #ifdef _GNU_SOURCE
diff --git a/include/unistd.h b/include/unistd.h
index 20ba6cc..b5206a6 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -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
diff --git a/include/wchar.h b/include/wchar.h
index b1c6b7f..35706c7 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -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
diff --git a/include/wctype.h b/include/wctype.h
index f7be2cb..abc7d36 100644
--- a/include/wctype.h
+++ b/include/wctype.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_wint_t
 #define __NEED_wctrans_t
 #define __NEED_wctype_t

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: proposed default-features patch
  2012-09-08  0:46 proposed default-features patch Rich Felker
@ 2012-09-08  3:18 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2012-09-08  3:18 UTC (permalink / raw)
  To: musl

On Fri, Sep 07, 2012 at 08:46:49PM -0400, Rich Felker wrote:
> Hi all,
> 
> Here is my first try at implementing "default features". In the

Committed, along with corresponding docs changes. If anything needs
tweaking, it can be done in a separate commit.

As stated before, gcc -std=c99 (or c89 or c11, etc.) or an explicit
-D__STRICT_ANSI__ will yield the old behavior.

Rich


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-09-08  3:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-08  0:46 proposed default-features patch Rich Felker
2012-09-08  3:18 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).