Merge "Rationalize visibility."
diff --git a/libc/include/android/set_abort_message.h b/libc/include/android/set_abort_message.h
index aebedba..18881a3 100644
--- a/libc/include/android/set_abort_message.h
+++ b/libc/include/android/set_abort_message.h
@@ -37,4 +37,4 @@
 
 __END_DECLS
 
-#endif // _SET_ABORT_MESSAGE_H
+#endif
diff --git a/libc/include/assert.h b/libc/include/assert.h
index 0a9992d..dea8382 100644
--- a/libc/include/assert.h
+++ b/libc/include/assert.h
@@ -52,7 +52,7 @@
 # define	_assert(e)	((void)0)
 #else
 # define	_assert(e)	assert(e)
-# if __ISO_C_VISIBLE >= 1999
+# if __STDC_VERSION__ >= 199901L
 #  define	assert(e)	((e) ? (void)0 : __assert2(__FILE__, __LINE__, __func__, #e))
 # else
 #  define	assert(e)	((e) ? (void)0 : __assert(__FILE__, __LINE__, #e))
diff --git a/libc/include/complex.h b/libc/include/complex.h
index 66ea97e..e874e1c 100644
--- a/libc/include/complex.h
+++ b/libc/include/complex.h
@@ -43,7 +43,7 @@
 #define	complex		_Complex
 #define	I		_Complex_I
 
-#if __ISO_C_VISIBLE >= 2011
+#if __STDC_VERSION__ >= 201112L
 #ifdef __clang__
 #define	CMPLX(x, y)	((double complex){ x, y })
 #define	CMPLXF(x, y)	((float complex){ x, y })
@@ -53,7 +53,7 @@
 #define	CMPLXF(x, y)	__builtin_complex((float)(x), (float)(y))
 #define	CMPLXL(x, y)	__builtin_complex((long double)(x), (long double)(y))
 #endif
-#endif /* __ISO_C_VISIBLE >= 2011 */
+#endif
 
 __BEGIN_DECLS
 #pragma GCC visibility push(default)
diff --git a/libc/include/ctype.h b/libc/include/ctype.h
index 199f810..302a88e 100644
--- a/libc/include/ctype.h
+++ b/libc/include/ctype.h
@@ -56,11 +56,11 @@
 
 __BEGIN_DECLS
 
-extern const char	*_ctype_;
+extern const char* _ctype_;
 
-#if defined(__GNUC__) || defined(_ANSI_LIBRARY) || defined(lint)
 int isalnum(int);
 int isalpha(int);
+int isblank(int);
 int iscntrl(int);
 int isdigit(int);
 int isgraph(int);
@@ -87,20 +87,10 @@
 int isxdigit_l(int, locale_t) __INTRODUCED_IN(21);
 int tolower_l(int, locale_t) __INTRODUCED_IN(21);
 int toupper_l(int, locale_t) __INTRODUCED_IN(21);
-
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
-    || __XPG_VISIBLE > 600
-int isblank(int);
-#endif
-
-#if __BSD_VISIBLE || __XPG_VISIBLE
 int isascii(int);
 int toascii(int);
 int _tolower(int) __INTRODUCED_IN(21);
 int _toupper(int) __INTRODUCED_IN(21);
-#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
-
-#endif /* __GNUC__ || _ANSI_LIBRARY || lint */
 
 __END_DECLS
 
diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h
index ee4d5e2..4aa2ea0 100644
--- a/libc/include/fcntl.h
+++ b/libc/include/fcntl.h
@@ -106,12 +106,12 @@
 int open(const char* pathname, int flags, ...) {
     if (__builtin_constant_p(flags)) {
         if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
-            __creat_missing_mode();  // compile time error
+            __creat_missing_mode();  /* Compile time error. */
         }
     }
 
     if (__builtin_va_arg_pack_len() > 1) {
-        __creat_too_many_args();  // compile time error
+        __creat_too_many_args();  /* Compile time error. */
     }
 
     if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
@@ -125,12 +125,12 @@
 int openat(int dirfd, const char* pathname, int flags, ...) {
     if (__builtin_constant_p(flags)) {
         if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
-            __creat_missing_mode();  // compile time error
+            __creat_missing_mode();  /* Compile time error. */
         }
     }
 
     if (__builtin_va_arg_pack_len() > 1) {
-        __creat_too_many_args();  // compile time error
+        __creat_too_many_args();  /* Compile time error. */
     }
 
     if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
diff --git a/libc/include/grp.h b/libc/include/grp.h
index 373ca8f..498d1b8 100644
--- a/libc/include/grp.h
+++ b/libc/include/grp.h
@@ -47,20 +47,18 @@
 
 __BEGIN_DECLS
 struct group* getgrgid(gid_t);
-struct group* getgrnam(const char *);
-#if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE
-/* Android has thousands and thousands of ids to iterate through */
+struct group* getgrnam(const char*);
+
+/* Android has thousands and thousands of ids to iterate through. */
 struct group* getgrent(void)
   __attribute__((warning("getgrent is inefficient on Android"))) __INTRODUCED_IN_FUTURE;
+
 void setgrent(void) __INTRODUCED_IN_FUTURE;
 void endgrent(void) __INTRODUCED_IN_FUTURE;
 int getgrgid_r(gid_t, struct group*, char*, size_t, struct group**) __INTRODUCED_IN(24);
 int getgrnam_r(const char*, struct group*, char*, size_t, struct group**) __INTRODUCED_IN(24);
-#endif
-
-int getgrouplist (const char *user, gid_t group, gid_t *groups, int *ngroups);
-
-int initgroups (const char *user, gid_t group);
+int getgrouplist (const char*, gid_t, gid_t*, int*);
+int initgroups (const char*, gid_t);
 
 __END_DECLS
 
diff --git a/libc/include/limits.h b/libc/include/limits.h
index 7543567..84effa7 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -37,7 +37,6 @@
 
 #include <sys/cdefs.h>
 
-#if __XPG_VISIBLE
 #define PASS_MAX		128	/* _PASSWORD_LEN from <pwd.h> */
 
 #define NL_ARGMAX		9
@@ -48,7 +47,6 @@
 #define NL_TEXTMAX		255
 
 #define TMP_MAX                 308915776
-#endif /* __XPG_VISIBLE */
 
 #include <sys/limits.h>
 
@@ -68,14 +66,13 @@
 #define ULONG_LONG_MAX  ULLONG_MAX
 #endif
 
-/* BSD compatibility definitions. */
-#if __BSD_VISIBLE
+#if defined(__USE_BSD)
 #if defined(__LP64__)
 #define SIZE_T_MAX ULONG_MAX
 #else
 #define SIZE_T_MAX UINT_MAX
 #endif
-#endif /* __BSD_VISIBLE */
+#endif
 
 #if defined(__LP64__)
 #define SSIZE_MAX LONG_MAX
diff --git a/libc/include/math.h b/libc/include/math.h
index eae1d3b..c84d017 100644
--- a/libc/include/math.h
+++ b/libc/include/math.h
@@ -21,11 +21,9 @@
 #include <limits.h>
 
 __BEGIN_DECLS
-#pragma GCC visibility push(default)
 
 #define HUGE_VAL	__builtin_huge_val()
 
-#if __ISO_C_VISIBLE >= 1999
 #define FP_ILOGB0	(-INT_MAX)
 #define FP_ILOGBNAN	INT_MAX
 
@@ -78,80 +76,33 @@
 typedef __double_t double_t;
 typedef float __float_t;
 typedef __float_t float_t;
-#endif /* __ISO_C_VISIBLE >= 1999 */
 
-/*
- * XOPEN/SVID
- */
-#if __BSD_VISIBLE || __XSI_VISIBLE
-#define	M_E		2.7182818284590452354	/* e */
-#define	M_LOG2E		1.4426950408889634074	/* log 2e */
-#define	M_LOG10E	0.43429448190325182765	/* log 10e */
-#define	M_LN2		0.69314718055994530942	/* log e2 */
-#define	M_LN10		2.30258509299404568402	/* log e10 */
-#define	M_PI		3.14159265358979323846	/* pi */
-#define	M_PI_2		1.57079632679489661923	/* pi/2 */
-#define	M_PI_4		0.78539816339744830962	/* pi/4 */
-#define	M_1_PI		0.31830988618379067154	/* 1/pi */
-#define	M_2_PI		0.63661977236758134308	/* 2/pi */
-#define	M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
-#define	M_SQRT2		1.41421356237309504880	/* sqrt(2) */
-#define	M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
-
-#define	MAXFLOAT	((float)3.40282346638528860e+38)
-extern int signgam;
-#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
-
-#if __USE_GNU
-#define M_El            2.718281828459045235360287471352662498L /* e */
-#define M_LOG2El        1.442695040888963407359924681001892137L /* log 2e */
-#define M_LOG10El       0.434294481903251827651128918916605082L /* log 10e */
-#define M_LN2l          0.693147180559945309417232121458176568L /* log e2 */
-#define M_LN10l         2.302585092994045684017991454684364208L /* log e10 */
-#define M_PIl           3.141592653589793238462643383279502884L /* pi */
-#define M_PI_2l         1.570796326794896619231321691639751442L /* pi/2 */
-#define M_PI_4l         0.785398163397448309615660845819875721L /* pi/4 */
-#define M_1_PIl         0.318309886183790671537767526745028724L /* 1/pi */
-#define M_2_PIl         0.636619772367581343075535053490057448L /* 2/pi */
-#define M_2_SQRTPIl     1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
-#define M_SQRT2l        1.414213562373095048801688724209698079L /* sqrt(2) */
-#define M_SQRT1_2l      0.707106781186547524400844362104849039L /* 1/sqrt(2) */
+#if defined(__USE_BSD)
+#define HUGE MAXFLOAT
 #endif
 
-#if __BSD_VISIBLE
-#if 0
-/* Old value from 4.4BSD-Lite math.h; this is probably better. */
-#define	HUGE		HUGE_VAL
-#else
-#define	HUGE		MAXFLOAT
-#endif
-#endif /* __BSD_VISIBLE */
-
 /*
  * Most of these functions depend on the rounding mode and have the side
  * effect of raising floating-point exceptions, so they are not declared
  * as __pure2.  In C99, FENV_ACCESS affects the purity of these functions.
  */
 
-/*
- * ANSI/POSIX
- */
-int	__fpclassifyd(double) __pure2;
-int	__fpclassifyf(float) __pure2;
-int	__fpclassifyl(long double) __pure2;
-int	__isfinitef(float) __pure2;
-int	__isfinite(double) __pure2;
-int	__isfinitel(long double) __pure2;
-int	__isinff(float) __pure2;
-int	__isinfl(long double) __pure2;
+int __fpclassifyd(double) __pure2;
+int __fpclassifyf(float) __pure2;
+int __fpclassifyl(long double) __pure2;
+int __isfinitef(float) __pure2;
+int __isfinite(double) __pure2;
+int __isfinitel(long double) __pure2;
+int __isinff(float) __pure2;
+int __isinfl(long double) __pure2;
 int __isnanf(float) __pure2 __INTRODUCED_IN(21);
-int	__isnanl(long double) __pure2;
-int	__isnormalf(float) __pure2;
-int	__isnormal(double) __pure2;
-int	__isnormall(long double) __pure2;
-int	__signbit(double) __pure2;
-int	__signbitf(float) __pure2;
-int	__signbitl(long double) __pure2;
+int __isnanl(long double) __pure2;
+int __isnormalf(float) __pure2;
+int __isnormal(double) __pure2;
+int __isnormall(long double) __pure2;
+int __signbit(double) __pure2;
+int __signbitf(float) __pure2;
+int __signbitl(long double) __pure2;
 
 double	acos(double);
 double	asin(double);
@@ -180,10 +131,6 @@
 double	floor(double);
 double	fmod(double, double);
 
-/*
- * These functions are not in C90.
- */
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
 double	acosh(double);
 double	asinh(double);
 double	atanh(double);
@@ -211,28 +158,9 @@
 
 double	nextafter(double, double);
 double	remainder(double, double);
-double	remquo(double, double, int *);
+double	remquo(double, double, int*);
 double	rint(double);
-#endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
 
-#if __BSD_VISIBLE || __XSI_VISIBLE
-double	j0(double);
-double	j1(double);
-double	jn(int, double);
-double	y0(double);
-double	y1(double);
-double	yn(int, double);
-
-#if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
-double	gamma(double);
-#endif
-
-#if __XSI_VISIBLE <= 600 || __BSD_VISIBLE
-double	scalb(double, double);
-#endif
-#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
-
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
 double	copysign(double, double) __pure2;
 double	fdim(double, double);
 double	fmax(double, double) __pure2;
@@ -243,32 +171,7 @@
 double scalbn(double, int);
 double	tgamma(double);
 double	trunc(double);
-#endif
 
-/*
- * BSD math library entry points
- */
-#if __BSD_VISIBLE
-double	drem(double, double);
-int	finite(double) __pure2;
-int	isnanf(float) __pure2;
-long double significandl(long double) __INTRODUCED_IN(21);
-
-/*
- * Reentrant version of gamma & lgamma; passes signgam back by reference
- * as the second argument; user must allocate space for signgam.
- */
-double	gamma_r(double, int *);
-double	lgamma_r(double, int *);
-
-/*
- * IEEE Test Vector
- */
-double	significand(double);
-#endif /* __BSD_VISIBLE */
-
-/* float versions of ANSI/POSIX functions */
-#if __ISO_C_VISIBLE >= 1999
 float	acosf(float);
 float	asinf(float);
 float	atanf(float);
@@ -333,41 +236,7 @@
 float	fmaf(float, float, float);
 float	fmaxf(float, float) __pure2;
 float	fminf(float, float) __pure2;
-#endif
 
-/*
- * float versions of BSD math library entry points
- */
-#if __BSD_VISIBLE
-float	dremf(float, float);
-int	finitef(float) __pure2;
-float	gammaf(float);
-float	j0f(float);
-float	j1f(float);
-float	jnf(int, float);
-float	scalbf(float, float);
-float	y0f(float);
-float	y1f(float);
-float	ynf(int, float);
-
-/*
- * Float versions of reentrant version of gamma & lgamma; passes
- * signgam back by reference as the second argument; user must
- * allocate space for signgam.
- */
-float	gammaf_r(float, int *);
-float	lgammaf_r(float, int *);
-
-/*
- * float version of IEEE Test Vector
- */
-float	significandf(float);
-#endif	/* __BSD_VISIBLE */
-
-/*
- * long double versions of ISO/POSIX math functions
- */
-#if __ISO_C_VISIBLE >= 1999
 long double acoshl(long double) __INTRODUCED_IN(21);
 long double acosl(long double) __INTRODUCED_IN(21);
 long double asinhl(long double) __INTRODUCED_IN(21);
@@ -376,8 +245,8 @@
 long double atanhl(long double) __INTRODUCED_IN(21);
 long double atanl(long double) __INTRODUCED_IN(21);
 long double cbrtl(long double) __INTRODUCED_IN(21);
-long double	ceill(long double);
-long double	copysignl(long double, long double) __pure2;
+long double ceill(long double);
+long double copysignl(long double, long double) __pure2;
 long double coshl(long double) __INTRODUCED_IN(21);
 long double cosl(long double) __INTRODUCED_IN(21);
 long double erfcl(long double) __INTRODUCED_IN(21);
@@ -385,39 +254,39 @@
 long double exp2l(long double) __INTRODUCED_IN(21);
 long double expl(long double) __INTRODUCED_IN(21);
 long double expm1l(long double) __INTRODUCED_IN(21);
-long double	fabsl(long double) __pure2;
-long double	fdiml(long double, long double);
-long double	floorl(long double);
+long double fabsl(long double) __pure2;
+long double fdiml(long double, long double);
+long double floorl(long double);
 long double fmal(long double, long double, long double) __INTRODUCED_IN(21);
-long double	fmaxl(long double, long double) __pure2;
-long double	fminl(long double, long double) __pure2;
+long double fmaxl(long double, long double) __pure2;
+long double fminl(long double, long double) __pure2;
 long double fmodl(long double, long double) __INTRODUCED_IN(21);
 long double frexpl(long double value, int*) __INTRODUCED_IN(21); /* fundamentally !__pure2 */
 long double hypotl(long double, long double) __INTRODUCED_IN(21);
-int		ilogbl(long double) __pure2;
-long double	ldexpl(long double, int);
+int ilogbl(long double) __pure2;
+long double ldexpl(long double, int);
 long double lgammal(long double) __INTRODUCED_IN(21);
 long long llrintl(long double) __INTRODUCED_IN(21);
-long long	llroundl(long double);
+long long llroundl(long double);
 long double log10l(long double) __INTRODUCED_IN(21);
 long double log1pl(long double) __INTRODUCED_IN(21);
 long double log2l(long double) __INTRODUCED_IN(18);
 long double logbl(long double) __INTRODUCED_IN(18);
 long double logl(long double) __INTRODUCED_IN(21);
 long lrintl(long double) __INTRODUCED_IN(21);
-long		lroundl(long double);
+long lroundl(long double);
 long double modfl(long double, long double*) __INTRODUCED_IN(21); /* fundamentally !__pure2 */
 long double nanl(const char*) __pure2 __INTRODUCED_IN(13);
 long double nearbyintl(long double) __INTRODUCED_IN(21);
 long double nextafterl(long double, long double) __INTRODUCED_IN(21);
 double nexttoward(double, long double) __INTRODUCED_IN(18);
-float		nexttowardf(float, long double);
+float nexttowardf(float, long double);
 long double nexttowardl(long double, long double) __INTRODUCED_IN(18);
 long double powl(long double, long double) __INTRODUCED_IN(21);
 long double remainderl(long double, long double) __INTRODUCED_IN(21);
 long double remquol(long double, long double, int*) __INTRODUCED_IN(21);
 long double rintl(long double) __INTRODUCED_IN(21);
-long double	roundl(long double);
+long double roundl(long double);
 long double scalblnl(long double, long) __INTRODUCED_IN_X86(18);
 long double scalbnl(long double, int);
 long double sinhl(long double) __INTRODUCED_IN(21);
@@ -426,20 +295,74 @@
 long double tanhl(long double) __INTRODUCED_IN(21);
 long double tanl(long double) __INTRODUCED_IN(21);
 long double tgammal(long double) __INTRODUCED_IN(21);
-long double	truncl(long double);
-#endif /* __ISO_C_VISIBLE >= 1999 */
+long double truncl(long double);
 
-#if __BSD_VISIBLE
+#if defined(__USE_BSD) || defined(__USE_GNU)
+#define M_E		2.7182818284590452354	/* e */
+#define M_LOG2E		1.4426950408889634074	/* log 2e */
+#define M_LOG10E	0.43429448190325182765	/* log 10e */
+#define M_LN2		0.69314718055994530942	/* log e2 */
+#define M_LN10		2.30258509299404568402	/* log e10 */
+#define M_PI		3.14159265358979323846	/* pi */
+#define M_PI_2		1.57079632679489661923	/* pi/2 */
+#define M_PI_4		0.78539816339744830962	/* pi/4 */
+#define M_1_PI		0.31830988618379067154	/* 1/pi */
+#define M_2_PI		0.63661977236758134308	/* 2/pi */
+#define M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
+#define M_SQRT2		1.41421356237309504880	/* sqrt(2) */
+#define M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
+#define MAXFLOAT	((float)3.40282346638528860e+38)
+extern int signgam;
+double j0(double);
+double j1(double);
+double jn(int, double);
+double y0(double);
+double y1(double);
+double yn(int, double);
+double gamma(double);
+double scalb(double, double);
+double drem(double, double);
+int finite(double) __pure2;
+int isnanf(float) __pure2;
+double gamma_r(double, int*);
+double lgamma_r(double, int*);
+double significand(double);
 long double lgammal_r(long double, int*) __INTRODUCED_IN(23);
+long double significandl(long double) __INTRODUCED_IN(21);
+float dremf(float, float);
+int finitef(float) __pure2;
+float gammaf(float);
+float j0f(float);
+float j1f(float);
+float jnf(int, float);
+float scalbf(float, float);
+float y0f(float);
+float y1f(float);
+float ynf(int, float);
+float gammaf_r(float, int *);
+float lgammaf_r(float, int *);
+float significandf(float);
 #endif
 
 #if defined(__USE_GNU)
+#define M_El            2.718281828459045235360287471352662498L /* e */
+#define M_LOG2El        1.442695040888963407359924681001892137L /* log 2e */
+#define M_LOG10El       0.434294481903251827651128918916605082L /* log 10e */
+#define M_LN2l          0.693147180559945309417232121458176568L /* log e2 */
+#define M_LN10l         2.302585092994045684017991454684364208L /* log e10 */
+#define M_PIl           3.141592653589793238462643383279502884L /* pi */
+#define M_PI_2l         1.570796326794896619231321691639751442L /* pi/2 */
+#define M_PI_4l         0.785398163397448309615660845819875721L /* pi/4 */
+#define M_1_PIl         0.318309886183790671537767526745028724L /* 1/pi */
+#define M_2_PIl         0.636619772367581343075535053490057448L /* 2/pi */
+#define M_2_SQRTPIl     1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
+#define M_SQRT2l        1.414213562373095048801688724209698079L /* sqrt(2) */
+#define M_SQRT1_2l      0.707106781186547524400844362104849039L /* 1/sqrt(2) */
 void sincos(double, double*, double*);
 void sincosf(float, float*, float*);
 void sincosl(long double, long double*, long double*);
-#endif /* __USE_GNU */
+#endif
 
-#pragma GCC visibility pop
 __END_DECLS
 
 #endif /* !_MATH_H_ */
diff --git a/libc/include/pwd.h b/libc/include/pwd.h
index e881129..0b39a78 100644
--- a/libc/include/pwd.h
+++ b/libc/include/pwd.h
@@ -105,7 +105,7 @@
 #ifdef __LP64__
   char* pw_gecos;
 #else
-  // Note: On LP32, we define pw_gecos to pw_passwd since they're both NULL.
+  /* Note: On LP32, we define pw_gecos to pw_passwd since they're both NULL. */
 # define pw_gecos pw_passwd
 #endif
   char* pw_dir;
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index b92f5d5..74208bc 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -88,10 +88,6 @@
 #define	FOPEN_MAX	20	/* must be <= OPEN_MAX <sys/syslimits.h> */
 #define	FILENAME_MAX	1024	/* must be <= PATH_MAX <sys/syslimits.h> */
 
-/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
-#if __BSD_VISIBLE || __XPG_VISIBLE
-#define	P_tmpdir	"/tmp/"
-#endif
 #define	L_tmpnam	1024	/* XXX must be == PATH_MAX */
 #define	TMP_MAX		308915776
 
@@ -145,8 +141,7 @@
 int dprintf(int, const char* __restrict, ...) __printflike(2, 3) __INTRODUCED_IN(21);
 int vdprintf(int, const char* __restrict, __va_list) __printflike(2, 0) __INTRODUCED_IN(21);
 
-#ifndef __AUDIT__
-#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
+#if __STDC_VERSION__ < 201112L
 char* gets(char*) __attribute__((deprecated("gets is unsafe, use fgets instead")));
 #endif
 int sprintf(char* __restrict, const char* __restrict, ...)
@@ -154,11 +149,11 @@
 int vsprintf(char* __restrict, const char* __restrict, __va_list)
     __printflike(2, 0) __warnattr("vsprintf is often misused; please use vsnprintf");
 char* tmpnam(char*) __attribute__((deprecated("tmpnam is unsafe, use mkstemp or tmpfile instead")));
-#if __XPG_VISIBLE
+#if defined(__USE_BSD) || defined(__USE_GNU)
+#define P_tmpdir "/tmp/" /* deprecated */
 char* tempnam(const char*, const char*)
     __attribute__((deprecated("tempnam is unsafe, use mkstemp or tmpfile instead")));
 #endif
-#endif
 
 int rename(const char*, const char*);
 int renameat(int, const char*, int, const char*);
@@ -208,78 +203,47 @@
 FILE* tmpfile(void);
 FILE* tmpfile64(void) __INTRODUCED_IN(24);
 
-#if __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE
-int	 snprintf(char * __restrict, size_t, const char * __restrict, ...)
-		__printflike(3, 4);
-int	 vfscanf(FILE * __restrict, const char * __restrict, __va_list)
-		__scanflike(2, 0);
-int	 vscanf(const char *, __va_list)
-		__scanflike(1, 0);
-int	 vsnprintf(char * __restrict, size_t, const char * __restrict, __va_list)
-		__printflike(3, 0);
-int	 vsscanf(const char * __restrict, const char * __restrict, __va_list)
-		__scanflike(2, 0);
-#endif /* __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE */
+int snprintf(char* __restrict, size_t, const char* __restrict, ...) __printflike(3, 4);
+int vfscanf(FILE* __restrict, const char* __restrict, __va_list) __scanflike(2, 0);
+int vscanf(const char*, __va_list) __scanflike(1, 0);
+int vsnprintf(char* __restrict, size_t, const char* __restrict, __va_list) __printflike(3, 0);
+int vsscanf(const char* __restrict, const char* __restrict, __va_list) __scanflike(2, 0);
 
-/*
- * Functions defined in POSIX 1003.1.
- */
-#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
-#define	L_ctermid	1024	/* size for ctermid(); PATH_MAX */
+#define L_ctermid 1024 /* size for ctermid() */
 char* ctermid(char*);
 
-FILE	*fdopen(int, const char *);
-int	 fileno(FILE *);
+FILE* fdopen(int, const char*);
+int fileno(FILE*);
+int pclose(FILE*);
+FILE* popen(const char*, const char*);
+void flockfile(FILE*);
+int ftrylockfile(FILE*);
+void funlockfile(FILE*);
+int getc_unlocked(FILE*);
+int getchar_unlocked(void);
+int putc_unlocked(int, FILE*);
+int putchar_unlocked(int);
 
-#if (__POSIX_VISIBLE >= 199209)
-int	 pclose(FILE *);
-FILE	*popen(const char *, const char *);
-#endif
-
-#if __POSIX_VISIBLE >= 199506
-void	 flockfile(FILE *);
-int	 ftrylockfile(FILE *);
-void	 funlockfile(FILE *);
-
-/*
- * These are normally used through macros as defined below, but POSIX
- * requires functions as well.
- */
-int	 getc_unlocked(FILE *);
-int	 getchar_unlocked(void);
-int	 putc_unlocked(int, FILE *);
-int	 putchar_unlocked(int);
-#endif /* __POSIX_VISIBLE >= 199506 */
-
-#if __POSIX_VISIBLE >= 200809
 FILE* fmemopen(void*, size_t, const char*) __INTRODUCED_IN(23);
 FILE* open_memstream(char**, size_t*) __INTRODUCED_IN(23);
-#endif /* __POSIX_VISIBLE >= 200809 */
-
-#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */
 
 /*
  * Routines that are purely local.
  */
-#if __BSD_VISIBLE
-int	 asprintf(char ** __restrict, const char * __restrict, ...)
-		__printflike(2, 3);
-char	*fgetln(FILE * __restrict, size_t * __restrict);
-int	 fpurge(FILE *);
-void	 setbuffer(FILE *, char *, int);
-int	 setlinebuf(FILE *);
-int	 vasprintf(char ** __restrict, const char * __restrict,
-    __va_list)
-		__printflike(2, 0);
-
+#if defined(__USE_BSD)
+int  asprintf(char** __restrict, const char* __restrict, ...) __printflike(2, 3);
+char* fgetln(FILE* __restrict, size_t* __restrict);
+int fpurge(FILE*);
+void setbuffer(FILE*, char*, int);
+int setlinebuf(FILE*);
+int vasprintf(char** __restrict, const char* __restrict, __va_list) __printflike(2, 0);
 void clearerr_unlocked(FILE*) __INTRODUCED_IN(23);
 int feof_unlocked(FILE*) __INTRODUCED_IN(23);
 int ferror_unlocked(FILE*) __INTRODUCED_IN(23);
 int fileno_unlocked(FILE*) __INTRODUCED_IN(24);
-
 #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
 #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
-#endif /* __BSD_VISIBLE */
+#endif /* __USE_BSD */
 
 extern char* __fgets_chk(char*, int, FILE*, size_t) __INTRODUCED_IN(17);
 extern char* __fgets_real(char*, int, FILE*) __RENAME(fgets);
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index b3e52d5..6fb2209 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -46,10 +46,8 @@
 extern __noreturn void _Exit(int) __INTRODUCED_IN(21);
 extern int atexit(void (*)(void));
 
-#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
 int at_quick_exit(void (*)(void));
 void quick_exit(int) __noreturn;
-#endif
 
 extern char* getenv(const char*);
 extern int putenv(char*);
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;
diff --git a/libc/include/wchar.h b/libc/include/wchar.h
index 91d6f24..7a1fc07 100644
--- a/libc/include/wchar.h
+++ b/libc/include/wchar.h
@@ -150,11 +150,9 @@
 extern size_t wcslcat(wchar_t*, const wchar_t*, size_t);
 extern size_t wcslcpy(wchar_t*, const wchar_t*, size_t);
 
-#if __POSIX_VISIBLE >= 200809
 FILE* open_wmemstream(wchar_t**, size_t*) __INTRODUCED_IN(23);
 wchar_t* wcsdup(const wchar_t*);
 size_t wcsnlen(const wchar_t*, size_t);
-#endif
 
 __END_DECLS
 
diff --git a/libm/Android.bp b/libm/Android.bp
index 08f1c66..25c3e8f 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -518,7 +518,6 @@
         "-Wno-sign-compare",
         "-Wno-uninitialized",
         "-Wno-unknown-pragmas",
-        "-fvisibility=hidden",
     ],
     conlyflags: ["-std=gnu11"],
 
diff --git a/tests/string_posix_strerror_r_test.cpp b/tests/string_posix_strerror_r_test.cpp
index ae3b41a..596684b 100644
--- a/tests/string_posix_strerror_r_test.cpp
+++ b/tests/string_posix_strerror_r_test.cpp
@@ -20,7 +20,7 @@
 #if defined(__GLIBC__)
 
 // At the time of writing, libcxx -- which is dragged in by gtest -- assumes
-// declarations from glibc of things that aren't available without __USE_GNU.
+// declarations from glibc of things that aren't available without _GNU_SOURCE.
 // This means we can't even build this test (which is a problem because that
 // means it doesn't get included in CTS).
 // For glibc 2.15, the symbols in question are: