Add and use constants for the Android API levels.

Test: bionic tests still pass
Change-Id: If1b619cfc9db1d3f5d91f14f2ace71058dca0c4a
diff --git a/libc/bionic/semaphore.cpp b/libc/bionic/semaphore.cpp
index 1981647..610a1b2 100644
--- a/libc/bionic/semaphore.cpp
+++ b/libc/bionic/semaphore.cpp
@@ -222,7 +222,7 @@
     }
 
     int result = __futex_wait_ex(sem_count_ptr, shared, shared | SEMCOUNT_MINUS_ONE, false, nullptr);
-    if (bionic_get_application_target_sdk_version() > 23) {
+    if (bionic_get_application_target_sdk_version() >= __ANDROID_API_N__) {
       if (result ==-EINTR) {
         errno = EINTR;
         return -1;
diff --git a/libc/include/android/api-level.h b/libc/include/android/api-level.h
index 6dd4c18..c83c18d 100644
--- a/libc/include/android/api-level.h
+++ b/libc/include/android/api-level.h
@@ -43,4 +43,17 @@
 #define __ANDROID_API__ __ANDROID_API_FUTURE__
 #endif
 
+#define __ANDROID_API_G__ 9
+#define __ANDROID_API_I__ 14
+#define __ANDROID_API_J__ 16
+#define __ANDROID_API_J_MR1__ 17
+#define __ANDROID_API_J_MR2__ 18
+#define __ANDROID_API_K__ 19
+#define __ANDROID_API_L__ 21
+#define __ANDROID_API_L_MR1__ 22
+#define __ANDROID_API_M__ 23
+#define __ANDROID_API_N__ 24
+#define __ANDROID_API_N_MR1__ 25
+#define __ANDROID_API_O__ 26
+
 #endif /* ANDROID_API_LEVEL_H */
diff --git a/libc/include/android/legacy_errno_inlines.h b/libc/include/android/legacy_errno_inlines.h
index 93cba1f..8f08074 100644
--- a/libc/include/android/legacy_errno_inlines.h
+++ b/libc/include/android/legacy_errno_inlines.h
@@ -32,7 +32,7 @@
 #include <errno.h>
 #include <sys/cdefs.h>
 
-#if __ANDROID_API__ < 21
+#if __ANDROID_API__ < __ANDROID_API_L__
 
 __BEGIN_DECLS
 
diff --git a/libc/include/android/legacy_fenv_inlines_arm.h b/libc/include/android/legacy_fenv_inlines_arm.h
index a5bb26b..58c49c2 100644
--- a/libc/include/android/legacy_fenv_inlines_arm.h
+++ b/libc/include/android/legacy_fenv_inlines_arm.h
@@ -31,7 +31,7 @@
 
 #include <fenv.h>
 
-#if __ANDROID_API__ < 21 && defined(__arm__)
+#if __ANDROID_API__ < __ANDROID_API_L__ && defined(__arm__)
 
 __BEGIN_DECLS
 
@@ -149,6 +149,6 @@
 
 __END_DECLS
 
-#endif /* __ANDROID_API__ < 21 && defined(__arm__) */
+#endif /* __ANDROID_API__ < __ANDROID_API_L__ && defined(__arm__) */
 
 #endif /* ANDROID_LEGACY_FENV_INLINES_ARM_H */
diff --git a/libc/include/android/legacy_fenv_inlines_mips.h b/libc/include/android/legacy_fenv_inlines_mips.h
index ead697c..10b93c0 100644
--- a/libc/include/android/legacy_fenv_inlines_mips.h
+++ b/libc/include/android/legacy_fenv_inlines_mips.h
@@ -31,7 +31,7 @@
 
 #include <fenv.h>
 
-#if __ANDROID_API__ < 21 && (defined(__mips__) && !defined(__LP64__))
+#if __ANDROID_API__ < __ANDROID_API_L__ && (defined(__mips__) && !defined(__LP64__))
 
 __BEGIN_DECLS
 
@@ -163,6 +163,6 @@
 
 __END_DECLS
 
-#endif /* __ANDROID_API__ < 21 && (defined(__mips__) && !defined(__LP64__)) */
+#endif /* __ANDROID_API__ < __ANDROID_API_L__ && (defined(__mips__) && !defined(__LP64__)) */
 
 #endif /* ANDROID_LEGACY_FENV_INLINES_MIPS_H */
diff --git a/libc/include/android/legacy_signal_inlines.h b/libc/include/android/legacy_signal_inlines.h
index 8ba7894..afdaca8 100644
--- a/libc/include/android/legacy_signal_inlines.h
+++ b/libc/include/android/legacy_signal_inlines.h
@@ -39,7 +39,7 @@
 
 sighandler_t bsd_signal(int signum, sighandler_t handler) __REMOVED_IN(21);
 
-#if __ANDROID_API__ < 21
+#if __ANDROID_API__ < __ANDROID_API_L__
 
 static __inline int sigismember(const sigset_t *set, int signum) {
   /* Signal numbers start at 1, but bit positions start at 0. */
@@ -98,7 +98,7 @@
   return bsd_signal(s, f);
 }
 
-#endif /* __ANDROID_API__ < 21 */
+#endif /* __ANDROID_API__ < __ANDROID_API_L__ */
 
 __END_DECLS
 
diff --git a/libc/include/android/legacy_stdlib_inlines.h b/libc/include/android/legacy_stdlib_inlines.h
index 93554e5..e211de5 100644
--- a/libc/include/android/legacy_stdlib_inlines.h
+++ b/libc/include/android/legacy_stdlib_inlines.h
@@ -32,7 +32,7 @@
 #include <stdlib.h>
 #include <sys/cdefs.h>
 
-#if __ANDROID_API__ < 21
+#if __ANDROID_API__ < __ANDROID_API_L__
 
 __BEGIN_DECLS
 
diff --git a/libc/include/android/legacy_sys_stat_inlines.h b/libc/include/android/legacy_sys_stat_inlines.h
index c08edfa..23a9f07 100644
--- a/libc/include/android/legacy_sys_stat_inlines.h
+++ b/libc/include/android/legacy_sys_stat_inlines.h
@@ -32,7 +32,7 @@
 #include <sys/cdefs.h>
 #include <sys/stat.h>
 
-#if __ANDROID_API__ < 21
+#if __ANDROID_API__ < __ANDROID_API_L__
 
 __BEGIN_DECLS
 
diff --git a/libc/include/android/legacy_sys_wait_inlines.h b/libc/include/android/legacy_sys_wait_inlines.h
index 63343eb..1124f8e 100644
--- a/libc/include/android/legacy_sys_wait_inlines.h
+++ b/libc/include/android/legacy_sys_wait_inlines.h
@@ -34,7 +34,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
-#if __ANDROID_API__ < 18
+#if __ANDROID_API__ < __ANDROID_API_J_MR2__
 
 __BEGIN_DECLS
 
@@ -44,6 +44,6 @@
 
 __END_DECLS
 
-#endif /* __ANDROID_API__ < 18 */
+#endif /* __ANDROID_API__ < __ANDROID_API_J_MR2__ */
 
 #endif /* _ANDROID_LEGACY_SYS_WAIT_INLINES_H_ */
diff --git a/libc/include/android/legacy_termios_inlines.h b/libc/include/android/legacy_termios_inlines.h
index 92cb22d..4424bdb 100644
--- a/libc/include/android/legacy_termios_inlines.h
+++ b/libc/include/android/legacy_termios_inlines.h
@@ -35,7 +35,7 @@
 
 #include <linux/termios.h>
 
-#if __ANDROID_API__ < 21
+#if __ANDROID_API__ < __ANDROID_API_L__
 
 __BEGIN_DECLS
 
diff --git a/libc/include/ctype.h b/libc/include/ctype.h
index f59b399..84dd5aa 100644
--- a/libc/include/ctype.h
+++ b/libc/include/ctype.h
@@ -76,7 +76,7 @@
 int tolower(int);
 int toupper(int);
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 int isalnum_l(int, locale_t) __INTRODUCED_IN(21);
 int isalpha_l(int, locale_t) __INTRODUCED_IN(21);
 int isblank_l(int, locale_t) __INTRODUCED_IN(21);
diff --git a/libc/include/fenv.h b/libc/include/fenv.h
index 241e845..a4c37e6 100644
--- a/libc/include/fenv.h
+++ b/libc/include/fenv.h
@@ -36,7 +36,7 @@
 __BEGIN_DECLS
 
 // fenv was always available on x86.
-#if __ANDROID_API__ >= 21 || defined(__i386__)
+#if __ANDROID_API__ >= __ANDROID_API_L__ || defined(__i386__)
 int feclearexcept(int) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9);
 int fegetexceptflag(fexcept_t*, int) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21)
     __INTRODUCED_IN_X86(9);
diff --git a/libc/include/netinet/in.h b/libc/include/netinet/in.h
index 3574976..10fbafa 100644
--- a/libc/include/netinet/in.h
+++ b/libc/include/netinet/in.h
@@ -47,13 +47,13 @@
 
 int bindresvport(int, struct sockaddr_in*);
 
-#if __ANDROID_API__ >= 24
+#if __ANDROID_API__ >= __ANDROID_API_N__
 extern const struct in6_addr in6addr_any __INTRODUCED_IN(24);
 extern const struct in6_addr in6addr_loopback __INTRODUCED_IN(24);
 #else
 static const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
 static const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT;
-#endif /* __ANDROID_API__ >= 24 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */
 
 __END_DECLS
 
diff --git a/libc/include/poll.h b/libc/include/poll.h
index 0fa55d2..c4e62f9 100644
--- a/libc/include/poll.h
+++ b/libc/include/poll.h
@@ -53,7 +53,7 @@
 
 #if defined(__BIONIC_FORTIFY)
 
-#if __ANDROID_API__ >= 23
+#if __ANDROID_API__ >= __ANDROID_API_M__
 __BIONIC_FORTIFY_INLINE
 int poll(struct pollfd* fds, nfds_t fd_count, int timeout) {
 #if defined(__clang__)
@@ -85,7 +85,7 @@
   return __ppoll_real(fds, fd_count, timeout, mask);
 #endif
 }
-#endif /* __ANDROID_API__ >= 23 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */
 
 #endif
 
diff --git a/libc/include/signal.h b/libc/include/signal.h
index 17bc57d..7ae50de 100644
--- a/libc/include/signal.h
+++ b/libc/include/signal.h
@@ -118,7 +118,7 @@
 
 int siginterrupt(int, int);
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 sighandler_t signal(int, sighandler_t) __INTRODUCED_IN(21);
 int sigaddset(sigset_t*, int) __INTRODUCED_IN(21);
 int sigdelset(sigset_t*, int) __INTRODUCED_IN(21);
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 816bd28..9125e4c 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -49,7 +49,7 @@
 
 #include <bits/seek_constants.h>
 
-#if __ANDROID_API__ <= 23
+#if __ANDROID_API__ < __ANDROID_API_N__
 #include <bits/struct_file.h>
 #endif
 
@@ -66,7 +66,7 @@
 struct __sFILE;
 typedef struct __sFILE FILE;
 
-#if __ANDROID_API__ >= 23
+#if __ANDROID_API__ >= __ANDROID_API_M__
 extern FILE* stdin __INTRODUCED_IN(23);
 extern FILE* stdout __INTRODUCED_IN(23);
 extern FILE* stderr __INTRODUCED_IN(23);
@@ -268,7 +268,7 @@
 
 #if defined(__BIONIC_FORTIFY) && !defined(__BIONIC_NO_STDIO_FORTIFY)
 
-#if __ANDROID_API__ >= 17
+#if __ANDROID_API__ >= __ANDROID_API_J_MR1__
 __BIONIC_FORTIFY_INLINE
 __printflike(3, 0) int vsnprintf(char* dest, size_t size, const char* _Nonnull format, __va_list ap) {
     return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap);
@@ -302,9 +302,9 @@
     return __builtin___sprintf_chk(dest, 0, __bos(dest), format, __builtin_va_arg_pack());
 }
 #endif
-#endif /* __ANDROID_API__ >= 17 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */
 
-#if __ANDROID_API__ >= 24
+#if __ANDROID_API__ >= __ANDROID_API_N__
 __BIONIC_FORTIFY_INLINE
 size_t fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict stream) {
     size_t bos = __bos0(buf);
@@ -356,7 +356,7 @@
 
     return __fwrite_chk(buf, size, count, stream, bos);
 }
-#endif /* __ANDROID_API__ >= 24 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */
 
 #if !defined(__clang__)
 
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index c84460b..d0c08e1 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -152,7 +152,7 @@
 
 size_t wcstombs(char*, const wchar_t*, size_t);
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 size_t __ctype_get_mb_cur_max(void) __INTRODUCED_IN(21);
 #define MB_CUR_MAX __ctype_get_mb_cur_max()
 #else
@@ -184,7 +184,7 @@
 
 #endif /* defined(__BIONIC_FORTIFY) */
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 float strtof(const char*, char**) __INTRODUCED_IN(21);
 double atof(const char*) __attribute_pure__ __INTRODUCED_IN(21);
 int abs(int) __attribute_const__ __INTRODUCED_IN(21);
diff --git a/libc/include/string.h b/libc/include/string.h
index b3b3ed0..3e52f48 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -114,7 +114,7 @@
 int strcoll(const char* _Nonnull, const char* _Nonnull) __attribute_pure__;
 size_t strxfrm(char* __restrict, const char* _Nonnull __restrict, size_t);
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 int strcoll_l(const char* _Nonnull, const char* _Nonnull, locale_t) __attribute_pure__ __INTRODUCED_IN(21);
 size_t strxfrm_l(char* __restrict, const char* _Nonnull __restrict, size_t, locale_t) __INTRODUCED_IN(21);
 #else
@@ -152,7 +152,7 @@
 
 #if defined(__BIONIC_FORTIFY)
 
-#if __ANDROID_API__ >= 23
+#if __ANDROID_API__ >= __ANDROID_API_M__
 __BIONIC_FORTIFY_INLINE
 void* memchr(const void* s, int c, size_t n) {
     size_t bos = __bos(s);
@@ -194,9 +194,9 @@
 
     return __memrchr_chk(s, c, n, bos);
 }
-#endif /* __ANDROID_API__ >= 23 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */
 
-#if __ANDROID_API__ >= 17
+#if __ANDROID_API__ >= __ANDROID_API_J_MR1__
 __BIONIC_FORTIFY_INLINE
 void* memcpy(void* _Nonnull __restrict dst, const void* _Nonnull __restrict src, size_t copy_amount) {
     return __builtin___memcpy_chk(dst, src, copy_amount, __bos0(dst));
@@ -206,23 +206,23 @@
 void* memmove(void* _Nonnull dst, const void* _Nonnull src, size_t len) {
     return __builtin___memmove_chk(dst, src, len, __bos0(dst));
 }
-#endif /* __ANDROID_API__ >= 17 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 __BIONIC_FORTIFY_INLINE
 char* stpcpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) {
     return __builtin___stpcpy_chk(dst, src, __bos(dst));
 }
-#endif /* __ANDROID_API__ >= 21 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_L__ */
 
-#if __ANDROID_API__ >= 17
+#if __ANDROID_API__ >= __ANDROID_API_J_MR1__
 __BIONIC_FORTIFY_INLINE
 char* strcpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) {
     return __builtin___strcpy_chk(dst, src, __bos(dst));
 }
-#endif /* __ANDROID_API__ >= 17 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 __BIONIC_FORTIFY_INLINE
 char* stpncpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t n) {
     size_t bos_dst = __bos(dst);
@@ -264,9 +264,9 @@
 
     return __strncpy_chk2(dst, src, n, bos_dst, bos_src);
 }
-#endif /* __ANDROID_API__ >= 21 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_L__ */
 
-#if __ANDROID_API__ >= 17
+#if __ANDROID_API__ >= __ANDROID_API_J_MR1__
 __BIONIC_FORTIFY_INLINE
 char* strcat(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) {
     return __builtin___strcat_chk(dst, src, __bos(dst));
@@ -341,9 +341,9 @@
 
     return __strlen_chk(s, bos);
 }
-#endif /* __ANDROID_API__ >= 17 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */
 
-#if  __ANDROID_API__ >= 18
+#if  __ANDROID_API__ >= __ANDROID_API_J_MR2__
 __BIONIC_FORTIFY_INLINE
 char* strchr(const char* _Nonnull s, int c) {
     size_t bos = __bos(s);
@@ -381,7 +381,7 @@
 
     return __strrchr_chk(s, c, bos);
 }
-#endif /* __ANDROID_API__ >= 18 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR2__ */
 
 #endif /* defined(__BIONIC_FORTIFY) */
 
diff --git a/libc/include/sys/select.h b/libc/include/sys/select.h
index df118e3..40bd32e 100644
--- a/libc/include/sys/select.h
+++ b/libc/include/sys/select.h
@@ -62,7 +62,7 @@
 void __FD_SET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
 int __FD_ISSET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
 
-#if defined(__BIONIC_FORTIFY) && __ANDROID_API__ >= 21
+#if defined(__BIONIC_FORTIFY) && __ANDROID_API__ >= __ANDROID_API_L__
 #define FD_CLR(fd, set) __FD_CLR_chk(fd, set, __bos(set))
 #define FD_SET(fd, set) __FD_SET_chk(fd, set, __bos(set))
 #define FD_ISSET(fd, set) __FD_ISSET_chk(fd, set, __bos(set))
diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h
index 03dc849..8e05cf1 100644
--- a/libc/include/sys/socket.h
+++ b/libc/include/sys/socket.h
@@ -114,7 +114,7 @@
    ? (struct cmsghdr*) (msg)->msg_control : (struct cmsghdr*) NULL)
 #define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) &&   (cmsg)->cmsg_len <= (unsigned long)   ((mhdr)->msg_controllen -   ((char*)(cmsg) - (char*)(mhdr)->msg_control)))
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 struct cmsghdr* __cmsg_nxthdr(struct msghdr*, struct cmsghdr*) __INTRODUCED_IN(21);
 #else
 /* TODO(danalbert): Move this into libandroid_support. */
@@ -129,7 +129,7 @@
   }
   return ptr;
 }
-#endif /* __ANDROID_API__ >= 21 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_L__ */
 
 #define SCM_RIGHTS 0x01
 #define SCM_CREDENTIALS 0x02
@@ -315,7 +315,7 @@
 
 #if defined(__BIONIC_FORTIFY)
 
-#if __ANDROID_API__ >= 24
+#if __ANDROID_API__ >= __ANDROID_API_N__
 __BIONIC_FORTIFY_INLINE
 ssize_t recvfrom(int fd, void* buf, size_t len, int flags, struct sockaddr* src_addr, socklen_t* addr_len) {
   size_t bos = __bos0(buf);
@@ -336,7 +336,7 @@
 
   return __recvfrom_chk(fd, buf, len, bos, flags, src_addr, addr_len);
 }
-#endif /* __ANDROID_API__ >= 24 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */
 
 __BIONIC_FORTIFY_INLINE
 ssize_t recv(int socket, void* buf, size_t len, int flags) {
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index cc9dd91..f961cf8 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -169,7 +169,7 @@
 
 #if defined(__BIONIC_FORTIFY)
 
-#if __ANDROID_API__ >= 18
+#if __ANDROID_API__ >= __ANDROID_API_J_MR2__
 __BIONIC_FORTIFY_INLINE
 mode_t umask(mode_t mode) {
 #if !defined(__clang__)
@@ -182,11 +182,11 @@
 #endif
   return __umask_chk(mode);
 }
-#endif /* __ANDROID_API__ >= 18 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR2__ */
 
 #endif /* defined(__BIONIC_FORTIFY) */
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 int mkfifo(const char*, mode_t) __INTRODUCED_IN(21);
 #else
 // Implemented as a static inline before 21.
diff --git a/libc/include/sys/wait.h b/libc/include/sys/wait.h
index f3972fc..0247b2b 100644
--- a/libc/include/sys/wait.h
+++ b/libc/include/sys/wait.h
@@ -51,7 +51,7 @@
 
 pid_t wait(int*);
 pid_t waitpid(pid_t, int*, int);
-#if __ANDROID_API__ >= 18
+#if __ANDROID_API__ >= __ANDROID_API_J_MR2__
 pid_t wait4(pid_t, int*, int, struct rusage*) __INTRODUCED_IN(18);
 #else
 // Implemented as a static inline before 18.
diff --git a/libc/include/termios.h b/libc/include/termios.h
index c17794c..49ffcd2 100644
--- a/libc/include/termios.h
+++ b/libc/include/termios.h
@@ -35,7 +35,7 @@
 
 __BEGIN_DECLS
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 // Implemented as static inlines before 21.
 speed_t cfgetispeed(const struct termios*) __INTRODUCED_IN(21);
 speed_t cfgetospeed(const struct termios*) __INTRODUCED_IN(21);
diff --git a/libc/include/time.h b/libc/include/time.h
index 37246b4..9fde77e 100644
--- a/libc/include/time.h
+++ b/libc/include/time.h
@@ -77,7 +77,7 @@
 char* strptime(const char*, const char*, struct tm*);
 size_t strftime(char*, size_t, const char*, const struct tm*);
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 size_t strftime_l(char*, size_t, const char*, const struct tm*, locale_t) __INTRODUCED_IN(21);
 #else
 // Implemented as static inline before 21.
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 130ede6..1e239cd 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -169,7 +169,7 @@
 
 off64_t lseek64(int __fd, off64_t __offset, int __whence);
 
-#if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ >= 21
+#if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ >= __ANDROID_API_L__
 int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21);
 ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset) __RENAME(pread64)
   __INTRODUCED_IN(12);
@@ -206,7 +206,7 @@
 
 int acct(const char* __filepath);
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 int getpagesize(void) __INTRODUCED_IN(21);
 #else
 static __inline__ int getpagesize(void) {
@@ -284,7 +284,7 @@
 
 #if defined(__BIONIC_FORTIFY)
 
-#if __ANDROID_API__ >= 24
+#if __ANDROID_API__ >= __ANDROID_API_N__
 __BIONIC_FORTIFY_INLINE
 char* getcwd(char* buf, size_t size) {
     size_t bos = __bos(buf);
@@ -315,7 +315,7 @@
 
     return __getcwd_chk(buf, size, bos);
 }
-#endif /* __ANDROID_API__ >= 24 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */
 
 #if defined(__USE_FILE_OFFSET64)
 #define __PREAD_PREFIX(x) __pread64_ ## x
@@ -323,7 +323,7 @@
 #define __PREAD_PREFIX(x) __pread_ ## x
 #endif
 
-#if __ANDROID_API__ >= 23
+#if __ANDROID_API__ >= __ANDROID_API_M__
 __BIONIC_FORTIFY_INLINE
 ssize_t pread(int fd, void* buf, size_t count, off_t offset) {
     size_t bos = __bos0(buf);
@@ -373,7 +373,7 @@
 
     return __pread64_chk(fd, buf, count, offset, bos);
 }
-#endif /* __ANDROID_API__ >= 23 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */
 
 #if defined(__USE_FILE_OFFSET64)
 #define __PWRITE_PREFIX(x) __pwrite64_ ## x
@@ -381,7 +381,7 @@
 #define __PWRITE_PREFIX(x) __pwrite_ ## x
 #endif
 
-#if __ANDROID_API__ >= 24
+#if __ANDROID_API__ >= __ANDROID_API_N__
 __BIONIC_FORTIFY_INLINE
 ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) {
     size_t bos = __bos0(buf);
@@ -431,9 +431,9 @@
 
     return __pwrite64_chk(fd, buf, count, offset, bos);
 }
-#endif /* __ANDROID_API__ >= 24 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 __BIONIC_FORTIFY_INLINE
 ssize_t read(int fd, void* buf, size_t count) {
     size_t bos = __bos0(buf);
@@ -458,9 +458,9 @@
 
     return __read_chk(fd, buf, count, bos);
 }
-#endif /* __ANDROID_API__ >= 21 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_L__ */
 
-#if __ANDROID_API__ >= 24
+#if __ANDROID_API__ >= __ANDROID_API_N__
 __BIONIC_FORTIFY_INLINE
 ssize_t write(int fd, const void* buf, size_t count) {
     size_t bos = __bos0(buf);
@@ -487,9 +487,9 @@
 
     return __write_chk(fd, buf, count, bos);
 }
-#endif /* __ANDROID_API__ >= 24 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */
 
-#if __ANDROID_API__ >= 23
+#if __ANDROID_API__ >= __ANDROID_API_M__
 __BIONIC_FORTIFY_INLINE
 ssize_t readlink(const char* path, char* buf, size_t size) {
     size_t bos = __bos(buf);
@@ -539,7 +539,7 @@
 
     return __readlinkat_chk(dirfd, path, buf, size, bos);
 }
-#endif /* __ANDROID_API__ >= 23 */
+#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */
 
 #endif /* defined(__BIONIC_FORTIFY) */
 
diff --git a/libc/include/wchar.h b/libc/include/wchar.h
index 2ee6c69..d3e9f5c 100644
--- a/libc/include/wchar.h
+++ b/libc/include/wchar.h
@@ -132,7 +132,7 @@
 int               wprintf(const wchar_t *, ...);
 int               wscanf(const wchar_t *, ...);
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 long long wcstoll_l(const wchar_t*, wchar_t**, int, locale_t) __INTRODUCED_IN(21);
 unsigned long long wcstoull_l(const wchar_t*, wchar_t**, int, locale_t) __INTRODUCED_IN(21);
 long double wcstold_l(const wchar_t*, wchar_t**, locale_t) __INTRODUCED_IN(21);
diff --git a/libc/include/wctype.h b/libc/include/wctype.h
index 0613e7e..a0ed09a 100644
--- a/libc/include/wctype.h
+++ b/libc/include/wctype.h
@@ -35,7 +35,7 @@
 
 __BEGIN_DECLS
 
-#if __ANDROID_API__ >= 21
+#if __ANDROID_API__ >= __ANDROID_API_L__
 int iswalnum_l(wint_t, locale_t) __INTRODUCED_IN(21);
 int iswalpha_l(wint_t, locale_t) __INTRODUCED_IN(21);
 int iswblank_l(wint_t, locale_t) __INTRODUCED_IN(21);
diff --git a/linker/linker.cpp b/linker/linker.cpp
index f8531b6..d5839d3 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -154,8 +154,8 @@
     nullptr
   };
 
-  // limit greylisting to apps targeting sdk version 23 and below
-  if (get_application_target_sdk_version() > 23) {
+  // If you're targeting N, you don't get the greylist.
+  if (get_application_target_sdk_version() >= __ANDROID_API_N__) {
     return false;
   }
 
@@ -776,9 +776,10 @@
   for (auto it = start, end = soinfo_list.end(); it != end; ++it) {
     soinfo* si = *it;
     // Do not skip RTLD_LOCAL libraries in dlsym(RTLD_DEFAULT, ...)
-    // if the library is opened by application with target api level <= 22
+    // if the library is opened by application with target api level < M.
     // See http://b/21565766
-    if ((si->get_rtld_flags() & RTLD_GLOBAL) == 0 && si->get_target_sdk_version() > 22) {
+    if ((si->get_rtld_flags() & RTLD_GLOBAL) == 0 &&
+        si->get_target_sdk_version() >= __ANDROID_API_M__) {
       continue;
     }
 
@@ -1031,7 +1032,7 @@
 const char* fix_dt_needed(const char* dt_needed, const char* sopath __unused) {
 #if !defined(__LP64__)
   // Work around incorrect DT_NEEDED entries for old apps: http://b/21364029
-  if (get_application_target_sdk_version() <= 22) {
+  if (get_application_target_sdk_version() < __ANDROID_API_M__) {
     const char* bname = basename(dt_needed);
     if (bname != dt_needed) {
       DL_WARN("library \"%s\" has invalid DT_NEEDED entry \"%s\"", sopath, dt_needed);
@@ -3031,12 +3032,12 @@
   // In the case when dt_soname is absent some apps stop working
   // because they can't find dt_needed library by soname.
   // This workaround should keep them working. (applies only
-  // for apps targeting sdk version <=22). Make an exception for
+  // for apps targeting sdk version < M). Make an exception for
   // the main executable and linker; they do not need to have dt_soname
   if (soname_ == nullptr &&
       this != solist_get_somain() &&
       (flags_ & FLAG_LINKER) == 0 &&
-      get_application_target_sdk_version() <= 22) {
+      get_application_target_sdk_version() < __ANDROID_API_M__) {
     soname_ = basename(realpath_.c_str());
     DL_WARN("%s: is missing DT_SONAME will use basename as a replacement: \"%s\"",
         get_realpath(), soname_);
@@ -3065,8 +3066,8 @@
 
 #if !defined(__LP64__)
   if (has_text_relocations) {
-    // Fail if app is targeting sdk version > 22
-    if (get_application_target_sdk_version() > 22) {
+    // Fail if app is targeting M or above.
+    if (get_application_target_sdk_version() >= __ANDROID_API_M__) {
       DL_ERR_AND_LOG("\"%s\" has text relocations", get_realpath());
       return false;
     }
@@ -3226,4 +3227,3 @@
 
   g_default_namespace.set_default_library_paths(std::move(ld_default_paths));
 };
-
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index 5b0ee49..1b18450 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -608,7 +608,7 @@
       int prot = PFLAGS_TO_PROT(phdr->p_flags);
       if ((prot & (PROT_EXEC | PROT_WRITE)) == (PROT_EXEC | PROT_WRITE)) {
         // W + E PT_LOAD segments are not allowed in O.
-        if (get_application_target_sdk_version() > 25) {
+        if (get_application_target_sdk_version() >= __ANDROID_API_O__) {
           DL_ERR_AND_LOG("\"%s\": W + E load segments are not allowed", name_.c_str());
           return false;
         }
diff --git a/linker/linker_soinfo.cpp b/linker/linker_soinfo.cpp
index 59bdc4d..16e42c2 100644
--- a/linker/linker_soinfo.cpp
+++ b/linker/linker_soinfo.cpp
@@ -726,7 +726,7 @@
 }
 
 void* soinfo::to_handle() {
-  if (get_application_target_sdk_version() <= 23 || !has_min_version(3)) {
+  if (get_application_target_sdk_version() < __ANDROID_API_N__ || !has_min_version(3)) {
     return this;
   }
 
@@ -791,5 +791,3 @@
 
   return gnu_hash_;
 }
-
-
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index 8527b00..ed50ea5 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -1191,10 +1191,9 @@
 }
 
 TEST(dlext, dlopen_handle_value_app_compat) {
-  android_set_application_target_sdk_version(23);
+  android_set_application_target_sdk_version(__ANDROID_API_M__);
   void* handle = dlopen("libtest_dlsym_from_this.so", RTLD_NOW | RTLD_LOCAL);
   ASSERT_TRUE(reinterpret_cast<uintptr_t>(handle) % sizeof(uintptr_t) == 0)
           << "dlopen should return valid pointer";
   dlclose(handle);
 }
-
diff --git a/tests/semaphore_test.cpp b/tests/semaphore_test.cpp
index 7dc7225..24a2dbe 100644
--- a/tests/semaphore_test.cpp
+++ b/tests/semaphore_test.cpp
@@ -188,7 +188,7 @@
 
 TEST(semaphore, sem_wait_no_EINTR_in_sdk_less_equal_than_23) {
 #if defined(__BIONIC__)
-  android_set_application_target_sdk_version(23U);
+  android_set_application_target_sdk_version(__ANDROID_API_M__);
   sem_t s;
   ASSERT_EQ(0, sem_init(&s, 0, 0));
   ScopedSignalHandler handler(SIGUSR1, sem_wait_test_signal_handler);