Rationalize visibility.
If it's C or POSIX, it's in. If it's BSD or GNU, it's guarded by __USE_BSD
or __USE_GNU.
Bug: https://code.google.com/p/android/issues/detail?id=194631
Change-Id: Ife51a21c2b37b060db56780d29c929805b199cb6
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 120c29d..5369e30 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -162,20 +162,6 @@
#define __scanflike(x, y) __attribute__((__format__(scanf, x, y))) __nonnull((x))
/*
- * C99 defines the restrict type qualifier keyword.
- */
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#endif
-
-/*
- * C99 defines the __func__ predefined identifier.
- */
-#if !defined(__STDC_VERSION__) || !(__STDC_VERSION__ >= 199901L)
-#define __func__ __PRETTY_FUNCTION__
-#endif
-
-/*
* GNU C version 2.96 added explicit branch prediction so that
* the CPU back-end can hint the processor and also so that
* code blocks can be reordered such that the predicted path
@@ -230,151 +216,49 @@
#define __SCCSID(_s) /* nothing */
/*
- * _BSD_SOURCE and _GNU_SOURCE are expected to be defined by callers before
- * any standard header file is included. In those header files we test
- * against __USE_BSD and __USE_GNU. glibc does this in <features.h> but we
- * do it in <sys/cdefs.h> instead because that's where our existing
- * _POSIX_C_SOURCE tests were, and we're already confident that <sys/cdefs.h>
- * is included everywhere it should be.
+ * With bionic, you always get all C and POSIX API.
*
- * The _GNU_SOURCE test needs to come before any _BSD_SOURCE or _POSIX* tests
- * because _GNU_SOURCE implies everything else.
+ * If you want BSD and/or GNU extensions, _BSD_SOURCE and/or _GNU_SOURCE are
+ * expected to be defined by callers before *any* standard header file is
+ * included.
+ *
+ * In our header files we test against __USE_BSD and __USE_GNU.
*/
#if defined(_GNU_SOURCE)
+# define __USE_BSD 1
# define __USE_GNU 1
-# undef _POSIX_SOURCE
-# define _POSIX_SOURCE 1
-# undef _POSIX_C_SOURCE
-# define _POSIX_C_SOURCE 200809L
-# undef _BSD_SOURCE
-# define _BSD_SOURCE 1
#endif
#if defined(_BSD_SOURCE)
# define __USE_BSD 1
#endif
-/*
- * _FILE_OFFSET_BITS 64 support.
- */
+/* Historically there was no way to turn off the BSD stuff, so we're probably stuck with that. */
+#if !defined(__USE_BSD)
+# define __USE_BSD 1
+#endif
+
+/* _FILE_OFFSET_BITS 64 support. */
#if !defined(__LP64__) && defined(_FILE_OFFSET_BITS)
#if _FILE_OFFSET_BITS == 64
#define __USE_FILE_OFFSET64 1
#endif
#endif
-/*-
- * POSIX.1 requires that the macros we test be defined before any standard
- * header file is included.
- *
- * Here's a quick run-down of the versions:
- * defined(_POSIX_SOURCE) 1003.1-1988
- * _POSIX_C_SOURCE == 1 1003.1-1990
- * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option
- * _POSIX_C_SOURCE == 199309 1003.1b-1993
- * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995,
- * and the omnibus ISO/IEC 9945-1: 1996
- * _POSIX_C_SOURCE == 200112 1003.1-2001
- * _POSIX_C_SOURCE == 200809 1003.1-2008
- *
- * In addition, the X/Open Portability Guide, which is now the Single UNIX
- * Specification, defines a feature-test macro which indicates the version of
- * that specification, and which subsumes _POSIX_C_SOURCE.
- *
- * Our macros begin with two underscores to avoid namespace screwage.
- */
-
-/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
-#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
-#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */
-#define _POSIX_C_SOURCE 199009
+/* C99 added the `restrict` type qualifier keyword. Before then, `__restrict` is a GNU extension. */
+#if __STDC_VERSION__ >= 199901L
+#define __restrict restrict
#endif
-/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
-#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2
-#undef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 199209
-#endif
-
-/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
-#ifdef _XOPEN_SOURCE
-#if _XOPEN_SOURCE - 0 >= 700
-#define __XSI_VISIBLE 700
-#undef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 200809
-#elif _XOPEN_SOURCE - 0 >= 600
-#define __XSI_VISIBLE 600
-#undef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 200112
-#elif _XOPEN_SOURCE - 0 >= 500
-#define __XSI_VISIBLE 500
-#undef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 199506
-#endif
-#endif
-
-/*
- * Deal with all versions of POSIX. The ordering relative to the tests above is
- * important.
- */
-#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
-#define _POSIX_C_SOURCE 198808
-#endif
-#ifdef _POSIX_C_SOURCE
-#if _POSIX_C_SOURCE >= 200809
-#define __POSIX_VISIBLE 200809
-#define __ISO_C_VISIBLE 1999
-#elif _POSIX_C_SOURCE >= 200112
-#define __POSIX_VISIBLE 200112
-#define __ISO_C_VISIBLE 1999
-#elif _POSIX_C_SOURCE >= 199506
-#define __POSIX_VISIBLE 199506
-#define __ISO_C_VISIBLE 1990
-#elif _POSIX_C_SOURCE >= 199309
-#define __POSIX_VISIBLE 199309
-#define __ISO_C_VISIBLE 1990
-#elif _POSIX_C_SOURCE >= 199209
-#define __POSIX_VISIBLE 199209
-#define __ISO_C_VISIBLE 1990
-#elif _POSIX_C_SOURCE >= 199009
-#define __POSIX_VISIBLE 199009
-#define __ISO_C_VISIBLE 1990
-#else
-#define __POSIX_VISIBLE 198808
-#define __ISO_C_VISIBLE 0
-#endif /* _POSIX_C_SOURCE */
-#else /* Default environment: show everything. */
-#define __POSIX_VISIBLE 200809
-#define __XSI_VISIBLE 700
-#define __BSD_VISIBLE 1
-#define __ISO_C_VISIBLE 1999
-#endif
-
-/*
- * Default values.
- */
-#ifndef __XPG_VISIBLE
-# define __XPG_VISIBLE 700
-#endif
-#ifndef __POSIX_VISIBLE
-# define __POSIX_VISIBLE 200809
-#endif
-#ifndef __ISO_C_VISIBLE
-# define __ISO_C_VISIBLE 1999
-#endif
-#ifndef __BSD_VISIBLE
-# define __BSD_VISIBLE 1
+/* C99 added the `__func__` predefined identifier. */
+#if __STDC_VERSION__ < 199901L
+#define __func__ __PRETTY_FUNCTION__
#endif
#define __BIONIC__ 1
#include <android/api-level.h>
/* glibc compatibility. */
-#if __POSIX_VISIBLE >= 200809
-#define __USE_ISOC99 1
-#define __USE_XOPEN2K 1
-#define __USE_XOPEN2K8 1
-#endif
#if __LP64__
#define __WORDSIZE 64
#else
@@ -427,7 +311,7 @@
#define __AVAILABILITY(...) __attribute__((availability(android,__VA_ARGS__)))
#else
#define __AVAILABILITY(...)
-#endif // __clang__
+#endif
#define __INTRODUCED_IN(api_level) __AVAILABILITY(introduced=api_level)
#define __DEPRECATED_IN(api_level) __AVAILABILITY(deprecated=api_level)
diff --git a/libc/include/sys/endian.h b/libc/include/sys/endian.h
index 449e0d7..99d5ff1 100644
--- a/libc/include/sys/endian.h
+++ b/libc/include/sys/endian.h
@@ -64,7 +64,7 @@
#define htonq(x) __swap64(x)
#define ntohq(x) __swap64(x)
-#if __BSD_VISIBLE
+#if defined(__USE_BSD)
#define LITTLE_ENDIAN _LITTLE_ENDIAN
#define BIG_ENDIAN _BIG_ENDIAN
#define PDP_ENDIAN _PDP_ENDIAN
@@ -101,6 +101,6 @@
#define le16toh(x) htole16(x)
#define le32toh(x) htole32(x)
#define le64toh(x) htole64(x)
-#endif /* __BSD_VISIBLE */
+#endif /* __USE_BSD */
#endif /* _SYS_ENDIAN_H_ */
diff --git a/libc/include/sys/limits.h b/libc/include/sys/limits.h
index f84253e..b7d899b 100644
--- a/libc/include/sys/limits.h
+++ b/libc/include/sys/limits.h
@@ -66,16 +66,14 @@
# define LONG_MIN (-0x7fffffffL-1)/* min value for a long */
#endif
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
# define ULLONG_MAX 0xffffffffffffffffULL
/* max value for unsigned long long */
# define LLONG_MAX 0x7fffffffffffffffLL
/* max value for a signed long long */
# define LLONG_MIN (-0x7fffffffffffffffLL-1)
/* min value for a signed long long */
-#endif
-#if __BSD_VISIBLE
+#if defined(__USE_BSD)
# define UID_MAX UINT_MAX /* max value for a uid_t */
# define GID_MAX UINT_MAX /* max value for a gid_t */
#endif
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index f26a492..0a999e4 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -128,7 +128,7 @@
#define st_mtimensec st_mtim.tv_nsec
#define st_ctimensec st_ctim.tv_nsec
-#ifdef __USE_BSD
+#if defined(__USE_BSD)
/* Permission macros provided by glibc for compatibility with BSDs. */
#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
#define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
diff --git a/libc/include/sys/types.h b/libc/include/sys/types.h
index a422261..469842d 100644
--- a/libc/include/sys/types.h
+++ b/libc/include/sys/types.h
@@ -141,7 +141,7 @@
typedef unsigned int uint_t;
typedef unsigned int uint;
-#ifdef __BSD_VISIBLE
+#if defined(__USE_BSD)
#include <sys/sysmacros.h>
typedef unsigned char u_char;
diff --git a/libc/include/sys/ucontext.h b/libc/include/sys/ucontext.h
index 9e3c653..f252a37 100644
--- a/libc/include/sys/ucontext.h
+++ b/libc/include/sys/ucontext.h
@@ -70,9 +70,9 @@
stack_t uc_stack;
mcontext_t uc_mcontext;
sigset_t uc_sigmask;
- // Android has a wrong (smaller) sigset_t on ARM.
+ /* Android has a wrong (smaller) sigset_t on ARM. */
uint32_t __padding_rt_sigset;
- // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM.
+ /* The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM. */
char __padding[120];
unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
} ucontext_t;
@@ -92,7 +92,7 @@
struct ucontext *uc_link;
stack_t uc_stack;
sigset_t uc_sigmask;
- // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64.
+ /* The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64. */
char __padding[128 - sizeof(sigset_t)];
mcontext_t uc_mcontext;
} ucontext_t;
@@ -157,7 +157,7 @@
stack_t uc_stack;
mcontext_t uc_mcontext;
sigset_t uc_sigmask;
- // Android has a wrong (smaller) sigset_t on x86.
+ /* Android has a wrong (smaller) sigset_t on x86. */
uint32_t __padding_rt_sigset;
struct _libc_fpstate __fpregs_mem;
} ucontext_t;