Don't expose all BSD extensions.

Just expose the ones that bionic historically leaked.

Also, many of the M_* constants in <math.h> are actually POSIX.

Change-Id: I6275df84c5866b872b71f1c8ed14e2aada12b793
diff --git a/libc/include/limits.h b/libc/include/limits.h
index 84effa7..cb86aec 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -66,7 +66,7 @@
 #define ULONG_LONG_MAX  ULLONG_MAX
 #endif
 
-#if defined(__USE_BSD)
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
 #if defined(__LP64__)
 #define SIZE_T_MAX ULONG_MAX
 #else
diff --git a/libc/include/math.h b/libc/include/math.h
index c84d017..1afef4c 100644
--- a/libc/include/math.h
+++ b/libc/include/math.h
@@ -297,7 +297,6 @@
 long double tgammal(long double) __INTRODUCED_IN(21);
 long double truncl(long double);
 
-#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 */
@@ -311,7 +310,10 @@
 #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)
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
 extern int signgam;
 double j0(double);
 double j1(double);
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index cfcdf1a..ef660d8 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -227,10 +227,7 @@
 FILE* fmemopen(void*, size_t, const char*) __INTRODUCED_IN(23);
 FILE* open_memstream(char**, size_t*) __INTRODUCED_IN(23);
 
-/*
- * Routines that are purely local.
- */
-#if defined(__USE_BSD)
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
 int  asprintf(char** __restrict, const char* __restrict, ...) __printflike(2, 3);
 char* fgetln(FILE* __restrict, size_t* __restrict);
 int fpurge(FILE*);
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 5369e30..8cde1c7 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -233,11 +233,6 @@
 # define __USE_BSD 1
 #endif
 
-/* 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
diff --git a/libc/include/sys/endian.h b/libc/include/sys/endian.h
index 99d5ff1..b9e4758 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 defined(__USE_BSD)
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
 #define LITTLE_ENDIAN _LITTLE_ENDIAN
 #define BIG_ENDIAN _BIG_ENDIAN
 #define PDP_ENDIAN _PDP_ENDIAN
diff --git a/libc/include/sys/limits.h b/libc/include/sys/limits.h
index b7d899b..5aa3d80 100644
--- a/libc/include/sys/limits.h
+++ b/libc/include/sys/limits.h
@@ -73,7 +73,7 @@
 # define LLONG_MIN	(-0x7fffffffffffffffLL-1)
 					/* min value for a signed long long */
 
-#if defined(__USE_BSD)
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
 # 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/types.h b/libc/include/sys/types.h
index 469842d..2895057 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;
 
-#if defined(__USE_BSD)
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
 #include <sys/sysmacros.h>
 
 typedef unsigned char  u_char;
diff --git a/libm/Android.bp b/libm/Android.bp
index 25c3e8f..23b9d5e 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -510,6 +510,7 @@
 
     cflags: [
         "-D__BIONIC_NO_MATH_INLINES",
+        "-D_BSD_SOURCE",
         "-DFLT_EVAL_METHOD=0",
         "-include freebsd-compat.h",
         "-Werror",