libc/include: remove easy __ANDROID_API__ tautologies.

The next NDK to take these headers only supports API 21 and later, so
clean up some of the trivial cruft.

This doesn't include the remaining "legacy inlines", since they're a bit
more complicated. I'll remove those in later changes.

Test: treehugger
Change-Id: I94c32f6393dd3ae831165917303ea591222baa0d
diff --git a/libc/include/bits/fortify/fcntl.h b/libc/include/bits/fortify/fcntl.h
index 7fe60f4..1f6ebad 100644
--- a/libc/include/bits/fortify/fcntl.h
+++ b/libc/include/bits/fortify/fcntl.h
@@ -59,7 +59,7 @@
 int open(const char* const __pass_object_size pathname, int flags)
         __overloadable
         __clang_error_if(__open_modes_useful(flags), "'open' " __open_too_few_args_error) {
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     return __open_2(pathname, flags);
 #else
     return __open_real(pathname, flags);
@@ -83,7 +83,7 @@
 int openat(int dirfd, const char* const __pass_object_size pathname, int flags)
         __overloadable
         __clang_error_if(__open_modes_useful(flags), "'openat' " __open_too_few_args_error) {
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     return __openat_2(dirfd, pathname, flags);
 #else
     return __openat_real(dirfd, pathname, flags);
@@ -98,7 +98,6 @@
     return __openat_real(dirfd, pathname, flags, modes);
 }
 
-#if __ANDROID_API__ >= 21
 /* Note that open == open64, so we reuse those bits in the open64 variants below.  */
 
 __BIONIC_ERROR_FUNCTION_VISIBILITY
@@ -139,7 +138,6 @@
                            "'openat64' " __open_useless_modes_warning) {
     return openat(dirfd, pathname, flags, modes);
 }
-#endif /* __ANDROID_API__ >= 21 */
 
 #undef __open_too_many_args_error
 #undef __open_too_few_args_error
diff --git a/libc/include/bits/fortify/poll.h b/libc/include/bits/fortify/poll.h
index 143153c..0b5cd4b 100644
--- a/libc/include/bits/fortify/poll.h
+++ b/libc/include/bits/fortify/poll.h
@@ -54,7 +54,6 @@
   return __call_bypassing_fortify(poll)(fds, fd_count, timeout);
 }
 
-#if __ANDROID_API__ >= 21
 __BIONIC_FORTIFY_INLINE
 int ppoll(struct pollfd* const fds __pass_object_size, nfds_t fd_count, const struct timespec* timeout, const sigset_t* mask)
     __overloadable
@@ -69,7 +68,6 @@
 #endif
   return __call_bypassing_fortify(ppoll)(fds, fd_count, timeout, mask);
 }
-#endif /* __ANDROID_API__ >= 21 */
 
 #if __ANDROID_API__ >= 28
 __BIONIC_FORTIFY_INLINE
diff --git a/libc/include/bits/fortify/stat.h b/libc/include/bits/fortify/stat.h
index 2d42a51..9b4ade2 100644
--- a/libc/include/bits/fortify/stat.h
+++ b/libc/include/bits/fortify/stat.h
@@ -39,7 +39,7 @@
     __overloadable
     __enable_if(1, "")
     __clang_error_if(mode & ~0777, "'umask' called with invalid mode") {
-#if __ANDROID_API__ >= 18 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
   return __umask_chk(mode);
 #else
   return __umask_real(mode);
diff --git a/libc/include/bits/fortify/stdio.h b/libc/include/bits/fortify/stdio.h
index 77bdbb4..95db017 100644
--- a/libc/include/bits/fortify/stdio.h
+++ b/libc/include/bits/fortify/stdio.h
@@ -36,7 +36,7 @@
 
 #if defined(__BIONIC_FORTIFY) && !defined(__BIONIC_NO_STDIO_FORTIFY)
 
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_INLINE __printflike(3, 0)
 int vsnprintf(char* const __pass_object_size dest, size_t size, const char* format, va_list ap)
@@ -58,7 +58,7 @@
                 "format string will always overflow destination buffer")
     __errorattr("format string will always overflow destination buffer");
 
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
 __BIONIC_FORTIFY_VARIADIC __printflike(2, 3)
 int sprintf(char* const __pass_object_size dest, const char* format, ...) __overloadable {
     va_list va;
@@ -126,7 +126,7 @@
         __clang_error_if(size < 0, "in call to 'fgets', size should not be negative")
         __clang_error_if(__bos_unevaluated_lt(__bos(dest), size),
                          "in call to 'fgets', size is larger than the destination buffer") {
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     size_t bos = __bos(dest);
 
     if (!__bos_dynamic_check_impl_and(bos, >=, (size_t)size, size >= 0)) {
diff --git a/libc/include/bits/fortify/string.h b/libc/include/bits/fortify/string.h
index 08bce2d..f668b9f 100644
--- a/libc/include/bits/fortify/string.h
+++ b/libc/include/bits/fortify/string.h
@@ -40,7 +40,7 @@
 #if defined(__BIONIC_FORTIFY)
 extern void* __memrchr_real(const void*, int, size_t) __RENAME(memrchr);
 
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_INLINE
 void* memcpy(void* const dst __pass_object_size0, const void* src, size_t copy_amount)
@@ -82,7 +82,7 @@
         __overloadable
         __clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)),
                          "'stpcpy' called with string bigger than buffer") {
-#if __ANDROID_API__ >= 21 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     return __builtin___stpcpy_chk(dst, src, __bos(dst));
 #else
     return __builtin_stpcpy(dst, src);
@@ -95,7 +95,7 @@
         __overloadable
         __clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)),
                          "'strcpy' called with string bigger than buffer") {
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     return __builtin___strcpy_chk(dst, src, __bos(dst));
 #else
     return __builtin_strcpy(dst, src);
@@ -107,14 +107,14 @@
         __overloadable
         __clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)),
                          "'strcat' called with string bigger than buffer") {
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     return __builtin___strcat_chk(dst, src, __bos(dst));
 #else
     return __builtin_strcat(dst, src);
 #endif
 }
 
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_INLINE
 char* strncat(char* const dst __pass_object_size, const char* src, size_t n)
@@ -130,7 +130,7 @@
         __diagnose_as_builtin(__builtin_memset, 1, 2, 3)
         /* If you're a user who wants this warning to go away: use `(&memset)(foo, bar, baz)`. */
         __clang_warning_if(c && !n, "'memset' will set 0 bytes; maybe the arguments got flipped?") {
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     return __builtin___memset_chk(s, c, n, __bos0(s));
 #else
     return __builtin_memset(s, c, n);
@@ -161,7 +161,7 @@
 }
 #endif
 
-#if __ANDROID_API__ >= 21 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_INLINE
 char* stpncpy(char* const dst __pass_object_size, const char* const src __pass_object_size, size_t n)
@@ -200,7 +200,7 @@
         __overloadable
         __clang_error_if(__bos_unevaluated_lt(__bos(dst), size),
                          "'strlcpy' called with size bigger than buffer") {
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     return __strlcpy_chk(dst, src, size, __bos(dst));
 #else
     return __call_bypassing_fortify(strlcpy)(dst, src, size);
@@ -212,14 +212,14 @@
         __overloadable
         __clang_error_if(__bos_unevaluated_lt(__bos(dst), size),
                          "'strlcat' called with size bigger than buffer") {
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     return __strlcat_chk(dst, src, size, __bos(dst));
 #else
     return __call_bypassing_fortify(strlcat)(dst, src, size);
 #endif
 }
 
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
 __BIONIC_FORTIFY_INLINE
 size_t strlen(const char* const s __pass_object_size0) __overloadable {
     return __strlen_chk(s, __bos0(s));
@@ -228,7 +228,7 @@
 
 __BIONIC_FORTIFY_INLINE
 char* strchr(const char* const s __pass_object_size, int c) __overloadable {
-#if  __ANDROID_API__ >= 18 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     size_t bos = __bos(s);
 
     if (bos != __BIONIC_FORTIFY_UNKNOWN_SIZE) {
@@ -240,7 +240,7 @@
 
 __BIONIC_FORTIFY_INLINE
 char* strrchr(const char* const s __pass_object_size, int c) __overloadable {
-#if  __ANDROID_API__ >= 18 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     size_t bos = __bos(s);
 
     if (bos != __BIONIC_FORTIFY_UNKNOWN_SIZE) {
diff --git a/libc/include/bits/fortify/strings.h b/libc/include/bits/fortify/strings.h
index 65fc5f1..5515ef9 100644
--- a/libc/include/bits/fortify/strings.h
+++ b/libc/include/bits/fortify/strings.h
@@ -33,7 +33,7 @@
         __overloadable
         __clang_error_if(__bos_unevaluated_lt(__bos0(dst), len),
                          "'bcopy' called with size bigger than buffer") {
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     size_t bos = __bos0(dst);
     if (!__bos_trivially_ge(bos, len)) {
         __builtin___memmove_chk(dst, src, len, bos);
@@ -48,7 +48,7 @@
         __overloadable
         __clang_error_if(__bos_unevaluated_lt(__bos0(b), len),
                          "'bzero' called with size bigger than buffer") {
-#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     size_t bos = __bos0(b);
     if (!__bos_trivially_ge(bos, len)) {
         __builtin___memset_chk(b, 0, len, bos);
diff --git a/libc/include/bits/fortify/unistd.h b/libc/include/bits/fortify/unistd.h
index 49a3946..335d0b5 100644
--- a/libc/include/bits/fortify/unistd.h
+++ b/libc/include/bits/fortify/unistd.h
@@ -152,7 +152,7 @@
         __overloadable
         __error_if_overflows_ssizet(count, read)
         __error_if_overflows_objectsize(count, __bos0(buf), read) {
-#if __ANDROID_API__ >= 21 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     size_t bos = __bos0(buf);
 
     if (!__bos_trivially_ge_no_overflow(bos, count)) {
@@ -192,7 +192,6 @@
     return __call_bypassing_fortify(readlink)(path, buf, size);
 }
 
-#if __ANDROID_API__ >= 21
 __BIONIC_FORTIFY_INLINE
 ssize_t readlinkat(int dirfd, const char* path, char* const __pass_object_size buf, size_t size)
         __overloadable
@@ -207,7 +206,6 @@
 #endif
     return __call_bypassing_fortify(readlinkat)(dirfd, path, buf, size);
 }
-#endif /* __ANDROID_API__ >= 21 */
 
 #undef __bos_trivially_ge_no_overflow
 #undef __enable_if_no_overflow_ssizet
diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h
index 1ec932b..a8db387 100644
--- a/libc/include/fcntl.h
+++ b/libc/include/fcntl.h
@@ -84,7 +84,6 @@
 /** Flag for open(). */
 #define O_RSYNC O_SYNC
 
-#if __ANDROID_API__ >= 21
 /** Flag for splice(). */
 #define SPLICE_F_MOVE 1
 /** Flag for splice(). */
@@ -93,7 +92,6 @@
 #define SPLICE_F_MORE 4
 /** Flag for splice(). */
 #define SPLICE_F_GIFT 8
-#endif
 
 #if __ANDROID_API__ >= 26
 /** Flag for sync_file_range(). */
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index 22f949b..130a72f 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -58,9 +58,7 @@
 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP { { ((PTHREAD_MUTEX_ERRORCHECK & 3) << 14) } }
 
 #define PTHREAD_COND_INITIALIZER  { { 0 } }
-#if __ANDROID_API__ >= 21
 #define PTHREAD_COND_INITIALIZER_MONOTONIC_NP  { { 1 << 1 } }
-#endif
 
 #define PTHREAD_RWLOCK_INITIALIZER  { { 0 } }
 
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 9de12a4..f4b2911 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -136,20 +136,8 @@
 int vfprintf(FILE* __fp, const char* __fmt, va_list __args) __printflike(2, 0);
 int vprintf(const char* __fp, va_list __args) __printflike(1, 0);
 
-#if __ANDROID_API__ >= 21
 int dprintf(int __fd, const char* __fmt, ...) __printflike(2, 3) __INTRODUCED_IN(21);
 int vdprintf(int __fd, const char* __fmt, va_list __args) __printflike(2, 0) __INTRODUCED_IN(21);
-#else
-/*
- * Old versions of Android called these fdprintf and vfdprintf out of fears that the glibc names
- * would collide with user debug printfs.
- *
- * Allow users to just use dprintf and vfdprintf on any version by renaming those calls to their
- * legacy equivalents if needed.
- */
-int dprintf(int __fd, const char* __fmt, ...) __RENAME(fdprintf) __printflike(2, 3);
-int vdprintf(int __fd, const char* __fmt, va_list __args) __RENAME(vfdprintf) __printflike(2, 0);
-#endif
 
 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L) || \
     (defined(__cplusplus) && __cplusplus <= 201103L)
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index 2ff8089..c185ec7 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -43,11 +43,7 @@
 
 __noreturn void abort(void) __attribute__((__nomerge__));
 __noreturn void exit(int __status);
-#if __ANDROID_API__ >= 21
 __noreturn void _Exit(int __status) __INTRODUCED_IN(21);
-#else
-__noreturn void _Exit(int) __RENAME(_exit);
-#endif
 
 int atexit(void (* _Nonnull __fn)(void));
 
diff --git a/libc/include/sys/epoll.h b/libc/include/sys/epoll.h
index 302c8c3..9e09408 100644
--- a/libc/include/sys/epoll.h
+++ b/libc/include/sys/epoll.h
@@ -40,21 +40,6 @@
 int epoll_create(int __size);
 int epoll_create1(int __flags) __INTRODUCED_IN(21);
 
-/*
- * Some third-party code uses the existence of EPOLL_CLOEXEC to detect the
- * availability of epoll_create1. This is not correct, since having up-to-date
- * UAPI headers says nothing about the C library, but for the time being we
- * don't want to harm adoption to the unified headers. We'll undef EPOLL_CLOEXEC
- * if we don't have epoll_create1 for the time being, and maybe revisit this
- * later.
- *
- * https://github.com/android-ndk/ndk/issues/302
- * https://github.com/android-ndk/ndk/issues/394
- */
-#if __ANDROID_API__ < 21 && defined(EPOLL_CLOEXEC)
-#undef EPOLL_CLOEXEC
-#endif
-
 int epoll_ctl(int __epoll_fd, int __op, int __fd, struct epoll_event* __BIONIC_COMPLICATED_NULLNESS __event);
 int epoll_wait(int __epoll_fd, struct epoll_event* _Nonnull __events, int __event_count, int __timeout_ms);
 int epoll_pwait(int __epoll_fd, struct epoll_event* _Nonnull __events, int __event_count, int __timeout_ms, const sigset_t* _Nullable __mask) __INTRODUCED_IN(21);
diff --git a/libc/include/sys/inotify.h b/libc/include/sys/inotify.h
index 37fbf99..c3cdc85 100644
--- a/libc/include/sys/inotify.h
+++ b/libc/include/sys/inotify.h
@@ -37,21 +37,8 @@
 
 __BEGIN_DECLS
 
-/*
- * Some third-party code uses the existence of IN_CLOEXEC/IN_NONBLOCK to detect
- * the availability of inotify_init1. This is not correct, since
- * `syscall(__NR_inotify_init1, IN_CLOEXEC)` is still valid even if the C
- * library doesn't have that function, but for the time being we don't want to
- * harm adoption to the unified headers. We'll avoid defining IN_CLOEXEC and
- * IN_NONBLOCK if we don't have inotify_init1 for the time being, and maybe
- * revisit this later.
- *
- * https://github.com/android-ndk/ndk/issues/394
- */
-#if __ANDROID_API__ >= 21
 #define IN_CLOEXEC O_CLOEXEC
 #define IN_NONBLOCK O_NONBLOCK
-#endif
 
 int inotify_init(void);
 int inotify_init1(int __flags) __INTRODUCED_IN(21);
diff --git a/libc/include/sys/select.h b/libc/include/sys/select.h
index 65571eb..06914a6 100644
--- a/libc/include/sys/select.h
+++ b/libc/include/sys/select.h
@@ -79,8 +79,6 @@
 #define __FD_SET(fd, set) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] |= __FDMASK(fd))
 #define __FD_ISSET(fd, set) ((__FDS_BITS(const fd_set*,set)[__FDELT(fd)] & __FDMASK(fd)) != 0)
 
-#if __ANDROID_API__ >= 21
-
 /** Removes `fd` from the given set. Use <poll.h> instead. */
 #define FD_CLR(fd, set) __FD_CLR_chk(fd, set, __bos(set))
 /** Adds `fd` to the given set. Use <poll.h> instead. */
@@ -88,17 +86,6 @@
 /** Tests whether `fd` is in the given set. Use <poll.h> instead. */
 #define FD_ISSET(fd, set) __FD_ISSET_chk(fd, set, __bos(set))
 
-#else
-
-/** Removes `fd` from the given set. Use <poll.h> instead. */
-#define FD_CLR(fd, set) __FD_CLR(fd, set)
-/** Adds `fd` to the given set. Use <poll.h> instead. */
-#define FD_SET(fd, set) __FD_SET(fd, set)
-/** Tests whether `fd` is in the given set. Use <poll.h> instead. */
-#define FD_ISSET(fd, set) __FD_ISSET(fd, set)
-
-#endif /* __ANDROID_API >= 21 */
-
 /**
  * [select(2)](http://man7.org/linux/man-pages/man2/select.2.html) waits on a
  * set of file descriptors.
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 566caaa..7ad94e1 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -303,13 +303,7 @@
 
 int acct(const char* _Nullable __path);
 
-#if __ANDROID_API__ >= 21
 int getpagesize(void) __INTRODUCED_IN(21);
-#else
-static __inline__ int getpagesize(void) {
-  return sysconf(_SC_PAGESIZE);
-}
-#endif
 
 long syscall(long __number, ...);