Modernize codebase by replacing NULL with nullptr

Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I5b4123bc6709641315120a191e36cc57541349b2
diff --git a/libc/bionic/__cmsg_nxthdr.cpp b/libc/bionic/__cmsg_nxthdr.cpp
index f962788..354e17e 100644
--- a/libc/bionic/__cmsg_nxthdr.cpp
+++ b/libc/bionic/__cmsg_nxthdr.cpp
@@ -33,7 +33,7 @@
   ptr = reinterpret_cast<cmsghdr*>(reinterpret_cast<char*>(cmsg) + CMSG_ALIGN(cmsg->cmsg_len));
   size_t len = reinterpret_cast<char*>(ptr+1) - reinterpret_cast<char*>(msg->msg_control);
   if (len > msg->msg_controllen) {
-    return NULL;
+    return nullptr;
   }
   return ptr;
 }
diff --git a/libc/bionic/__gnu_basename.cpp b/libc/bionic/__gnu_basename.cpp
index 1eb3f65..f9f87a6 100644
--- a/libc/bionic/__gnu_basename.cpp
+++ b/libc/bionic/__gnu_basename.cpp
@@ -31,5 +31,5 @@
 
 extern "C" const char* __gnu_basename(const char* path) {
   const char* last_slash = strrchr(path, '/');
-  return (last_slash != NULL) ? last_slash + 1 : path;
+  return (last_slash != nullptr) ? last_slash + 1 : path;
 }
diff --git a/libc/bionic/atof.cpp b/libc/bionic/atof.cpp
index e77ccdd..c17deab 100644
--- a/libc/bionic/atof.cpp
+++ b/libc/bionic/atof.cpp
@@ -31,5 +31,5 @@
 double atof(const char* s) {
   // Despite the 'f' in the name, this returns a double and is
   // specified to be equivalent to strtod.
-  return strtod(s, NULL);
+  return strtod(s, nullptr);
 }
diff --git a/libc/bionic/brk.cpp b/libc/bionic/brk.cpp
index e1a4b05..566c33a 100644
--- a/libc/bionic/brk.cpp
+++ b/libc/bionic/brk.cpp
@@ -48,8 +48,8 @@
 
 void* sbrk(ptrdiff_t increment) {
   // Initialize __bionic_brk if necessary.
-  if (__bionic_brk == NULL) {
-    __bionic_brk = __brk(NULL);
+  if (__bionic_brk == nullptr) {
+    __bionic_brk = __brk(nullptr);
   }
 
   // Don't ask the kernel if we already know the answer.
diff --git a/libc/bionic/c16rtomb.cpp b/libc/bionic/c16rtomb.cpp
index 93749c6..2d6ae93 100644
--- a/libc/bionic/c16rtomb.cpp
+++ b/libc/bionic/c16rtomb.cpp
@@ -42,7 +42,7 @@
 
 size_t c16rtomb(char* s, char16_t c16, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
   if (mbsinit(state)) {
     if (is_high_surrogate(c16)) {
       char32_t c32 = (c16 & ~0xd800) << 10;
@@ -62,6 +62,6 @@
     char32_t c32 = ((mbstate_get_byte(state, 3) << 16) |
                     (mbstate_get_byte(state, 2) << 8) |
                     (c16 & ~0xdc00)) + 0x10000;
-    return mbstate_reset_and_return(c32rtomb(s, c32, NULL), state);
+    return mbstate_reset_and_return(c32rtomb(s, c32, nullptr), state);
   }
 }
diff --git a/libc/bionic/c32rtomb.cpp b/libc/bionic/c32rtomb.cpp
index ebe9cd3..2909d8b 100644
--- a/libc/bionic/c32rtomb.cpp
+++ b/libc/bionic/c32rtomb.cpp
@@ -34,9 +34,9 @@
 
 size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
 
-  if (s == NULL) {
+  if (s == nullptr) {
     // Equivalent to c32rtomb(buf, U'\0', ps).
     return mbstate_reset_and_return(1, state);
   }
diff --git a/libc/bionic/clearenv.cpp b/libc/bionic/clearenv.cpp
index c70cc3e..01c9c39 100644
--- a/libc/bionic/clearenv.cpp
+++ b/libc/bionic/clearenv.cpp
@@ -31,9 +31,9 @@
 
 int clearenv() {
   char** e = environ;
-  if (e != NULL) {
+  if (e != nullptr) {
     for (; *e; ++e) {
-      *e = NULL;
+      *e = nullptr;
     }
   }
   return 0;
diff --git a/libc/bionic/dirent.cpp b/libc/bionic/dirent.cpp
index 153e56a..8921ca0 100644
--- a/libc/bionic/dirent.cpp
+++ b/libc/bionic/dirent.cpp
@@ -68,15 +68,15 @@
 
 static DIR* __allocate_DIR(int fd) {
   DIR* d = reinterpret_cast<DIR*>(malloc(sizeof(DIR)));
-  if (d == NULL) {
-    return NULL;
+  if (d == nullptr) {
+    return nullptr;
   }
   d->fd_ = fd;
   android_fdsan_exchange_owner_tag(fd, 0, __get_dir_tag(d));
   d->available_bytes_ = 0;
-  d->next_ = NULL;
+  d->next_ = nullptr;
   d->current_pos_ = 0L;
-  pthread_mutex_init(&d->mutex_, NULL);
+  pthread_mutex_init(&d->mutex_, nullptr);
   return d;
 }
 
@@ -89,11 +89,11 @@
   // Is 'fd' actually a directory?
   struct stat sb;
   if (fstat(fd, &sb) == -1) {
-    return NULL;
+    return nullptr;
   }
   if (!S_ISDIR(sb.st_mode)) {
     errno = ENOTDIR;
-    return NULL;
+    return nullptr;
   }
 
   return __allocate_DIR(fd);
@@ -101,7 +101,7 @@
 
 DIR* opendir(const char* path) {
   int fd = open(path, O_CLOEXEC | O_DIRECTORY | O_RDONLY);
-  return (fd != -1) ? __allocate_DIR(fd) : NULL;
+  return (fd != -1) ? __allocate_DIR(fd) : nullptr;
 }
 
 static bool __fill_DIR(DIR* d) {
@@ -117,7 +117,7 @@
 
 static dirent* __readdir_locked(DIR* d) {
   if (d->available_bytes_ == 0 && !__fill_DIR(d)) {
-    return NULL;
+    return nullptr;
   }
 
   dirent* entry = d->next_;
@@ -141,17 +141,17 @@
 
   ErrnoRestorer errno_restorer;
 
-  *result = NULL;
+  *result = nullptr;
   errno = 0;
 
   ScopedPthreadMutexLocker locker(&d->mutex_);
 
   dirent* next = __readdir_locked(d);
-  if (errno != 0 && next == NULL) {
+  if (errno != 0 && next == nullptr) {
     return errno;
   }
 
-  if (next != NULL) {
+  if (next != nullptr) {
     memcpy(entry, next, next->d_reclen);
     *result = entry;
   }
@@ -160,7 +160,7 @@
 __strong_alias(readdir64_r, readdir_r);
 
 int closedir(DIR* d) {
-  if (d == NULL) {
+  if (d == nullptr) {
     errno = EINVAL;
     return -1;
   }
diff --git a/libc/bionic/error.cpp b/libc/bionic/error.cpp
index e8df0e0..a8adc1b 100644
--- a/libc/bionic/error.cpp
+++ b/libc/bionic/error.cpp
@@ -34,13 +34,13 @@
 #include <string.h>
 
 unsigned int error_message_count = 0;
-void (*error_print_progname)(void) = NULL;
+void (*error_print_progname)(void) = nullptr;
 int error_one_per_line = 0;
 
 static void __error_head() {
   ++error_message_count;
 
-  if (error_print_progname != NULL) {
+  if (error_print_progname != nullptr) {
     error_print_progname();
   } else {
     fflush(stdout);
@@ -77,7 +77,7 @@
   if (error_one_per_line) {
     static const char* last_file;
     static unsigned int last_line;
-    if (last_line == line && last_file != NULL && strcmp(last_file, file) == 0) {
+    if (last_line == line && last_file != nullptr && strcmp(last_file, file) == 0) {
       return;
     }
     last_file = file;
diff --git a/libc/bionic/fortify.cpp b/libc/bionic/fortify.cpp
index 3bd9e68..4b94573 100644
--- a/libc/bionic/fortify.cpp
+++ b/libc/bionic/fortify.cpp
@@ -290,7 +290,7 @@
       return const_cast<char*>(p);
     }
     if (*p == '\0') {
-      return NULL;
+      return nullptr;
     }
   }
 }
@@ -387,7 +387,7 @@
 }
 
 char* __strrchr_chk(const char* p, int ch, size_t s_len) {
-  for (const char* save = NULL;; ++p, s_len--) {
+  for (const char* save = nullptr;; ++p, s_len--) {
     if (s_len == 0) {
       __fortify_fatal("strrchr: prevented read past end of buffer");
     }
diff --git a/libc/bionic/futimens.cpp b/libc/bionic/futimens.cpp
index 1ca8eb5..03f7e38 100644
--- a/libc/bionic/futimens.cpp
+++ b/libc/bionic/futimens.cpp
@@ -30,5 +30,5 @@
 #include <sys/stat.h>
 
 int futimens(int fd, const struct timespec times[2]) {
-  return utimensat(fd, NULL, times, 0);
+  return utimensat(fd, nullptr, times, 0);
 }
diff --git a/libc/bionic/getauxval.cpp b/libc/bionic/getauxval.cpp
index 22922b9..607e89c 100644
--- a/libc/bionic/getauxval.cpp
+++ b/libc/bionic/getauxval.cpp
@@ -33,7 +33,7 @@
 #include <elf.h>
 #include <errno.h>
 
-__LIBC_HIDDEN__ ElfW(auxv_t)* __libc_auxv = NULL;
+__LIBC_HIDDEN__ ElfW(auxv_t)* __libc_auxv = nullptr;
 
 extern "C" unsigned long int getauxval(unsigned long int type) {
   for (ElfW(auxv_t)* v = __libc_auxv; v->a_type != AT_NULL; ++v) {
diff --git a/libc/bionic/getcwd.cpp b/libc/bionic/getcwd.cpp
index 8ead91f..c42d4d5 100644
--- a/libc/bionic/getcwd.cpp
+++ b/libc/bionic/getcwd.cpp
@@ -35,23 +35,23 @@
 
 char* getcwd(char* buf, size_t size) {
   // You can't specify size 0 unless you're asking us to allocate for you.
-  if (buf != NULL && size == 0) {
+  if (buf != nullptr && size == 0) {
     errno = EINVAL;
-    return NULL;
+    return nullptr;
   }
 
   // Allocate a buffer if necessary.
-  char* allocated_buf = NULL;
+  char* allocated_buf = nullptr;
   size_t allocated_size = size;
-  if (buf == NULL) {
+  if (buf == nullptr) {
     if (size == 0) {
       // The Linux kernel won't return more than a page, so translate size 0 to 4KiB.
       // TODO: if we need to support paths longer than that, we'll have to walk the tree ourselves.
       allocated_size = getpagesize();
     }
     buf = allocated_buf = static_cast<char*>(malloc(allocated_size));
-    if (buf == NULL) {
-      return NULL;
+    if (buf == nullptr) {
+      return nullptr;
     }
   }
 
@@ -60,11 +60,11 @@
   if (rc == -1) {
     free(allocated_buf);
     // __getcwd set errno.
-    return NULL;
+    return nullptr;
   }
 
   // If we allocated a whole page, only return as large an allocation as necessary.
-  if (allocated_buf != NULL) {
+  if (allocated_buf != nullptr) {
     if (size == 0) {
       buf = strdup(allocated_buf);
       free(allocated_buf);
diff --git a/libc/bionic/grp_pwd.cpp b/libc/bionic/grp_pwd.cpp
index 1de8fc5..136a098 100644
--- a/libc/bionic/grp_pwd.cpp
+++ b/libc/bionic/grp_pwd.cpp
@@ -83,7 +83,7 @@
   // getpwnam_r and getpwuid_r don't modify errno, but library calls we
   // make might.
   ErrnoRestorer errno_restorer;
-  *result = NULL;
+  *result = nullptr;
 
   // Our implementation of getpwnam(3) and getpwuid(3) use thread-local
   // storage, so we can call them as long as we copy everything out
@@ -92,7 +92,7 @@
 
   // POSIX allows failure to find a match to be considered a non-error.
   // Reporting success (0) but with *result NULL is glibc's behavior.
-  if (src == NULL) {
+  if (src == nullptr) {
     return (errno == ENOENT) ? 0 : errno;
   }
 
@@ -114,9 +114,9 @@
 
   // pw_passwd and pw_gecos are non-POSIX and unused (always NULL) in bionic.
   // Note: On LP32, we define pw_gecos to pw_passwd since they're both NULL.
-  dst->pw_passwd = NULL;
+  dst->pw_passwd = nullptr;
 #if defined(__LP64__)
-  dst->pw_gecos = NULL;
+  dst->pw_gecos = nullptr;
 #endif
 
   // Copy the integral fields.
@@ -134,7 +134,7 @@
 
 int getpwuid_r(uid_t uid, passwd* pwd,
                char* buf, size_t byte_count, passwd** result) {
-  return do_getpw_r(0, NULL, uid, pwd, buf, byte_count, result);
+  return do_getpw_r(0, nullptr, uid, pwd, buf, byte_count, result);
 }
 
 static passwd* android_iinfo_to_passwd(passwd_state_t* state,
@@ -169,7 +169,7 @@
       return android_iinfo_to_passwd(state, android_ids + n);
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 static passwd* android_name_to_passwd(passwd_state_t* state, const char* name) {
@@ -178,7 +178,7 @@
       return android_iinfo_to_passwd(state, android_ids + n);
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 static group* android_id_to_group(group_state_t* state, unsigned id) {
@@ -187,7 +187,7 @@
       return android_iinfo_to_group(state, android_ids + n);
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 static group* android_name_to_group(group_state_t* state, const char* name) {
@@ -196,7 +196,7 @@
       return android_iinfo_to_group(state, android_ids + n);
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 // These are a list of the reserved app ranges, and should never contain anything below
@@ -474,7 +474,7 @@
 static passwd* app_id_to_passwd(uid_t uid, passwd_state_t* state) {
   if (uid < AID_APP_START || !is_valid_app_id(uid)) {
     errno = ENOENT;
-    return NULL;
+    return nullptr;
   }
 
   print_app_name_from_uid(uid, state->name_buffer_, sizeof(state->name_buffer_));
@@ -502,7 +502,7 @@
 static group* app_id_to_group(gid_t gid, group_state_t* state) {
   if (gid < AID_APP_START || !is_valid_app_id(gid)) {
     errno = ENOENT;
-    return NULL;
+    return nullptr;
   }
 
   print_app_name_from_gid(gid, state->group_name_buffer_, sizeof(state->group_name_buffer_));
@@ -516,17 +516,17 @@
 
 passwd* getpwuid(uid_t uid) { // NOLINT: implementing bad function.
   passwd_state_t* state = get_passwd_tls_buffer();
-  if (state == NULL) {
-    return NULL;
+  if (state == nullptr) {
+    return nullptr;
   }
 
   passwd* pw = android_id_to_passwd(state, uid);
-  if (pw != NULL) {
+  if (pw != nullptr) {
     return pw;
   }
   // Handle OEM range.
   pw = oem_id_to_passwd(uid, state);
-  if (pw != NULL) {
+  if (pw != nullptr) {
     return pw;
   }
   return app_id_to_passwd(uid, state);
@@ -534,12 +534,12 @@
 
 passwd* getpwnam(const char* login) { // NOLINT: implementing bad function.
   passwd_state_t* state = get_passwd_tls_buffer();
-  if (state == NULL) {
-    return NULL;
+  if (state == nullptr) {
+    return nullptr;
   }
 
   passwd* pw = android_name_to_passwd(state, login);
-  if (pw != NULL) {
+  if (pw != nullptr) {
     return pw;
   }
 
@@ -551,7 +551,7 @@
 
   // Handle OEM range.
   pw = oem_id_to_passwd(oem_id_from_name(login), state);
-  if (pw != NULL) {
+  if (pw != nullptr) {
     return pw;
   }
   return app_id_to_passwd(app_id_from_name(login, false), state);
@@ -594,11 +594,11 @@
 
 passwd* getpwent() {
   passwd_state_t* state = get_passwd_tls_buffer();
-  if (state == NULL) {
-    return NULL;
+  if (state == nullptr) {
+    return nullptr;
   }
   if (state->getpwent_idx < 0) {
-    return NULL;
+    return nullptr;
   }
 
   size_t start = 0;
@@ -630,17 +630,17 @@
   }
 
   // We are not reporting u1_a* and higher or we will be here forever
-  return NULL;
+  return nullptr;
 }
 
 static group* getgrgid_internal(gid_t gid, group_state_t* state) {
   group* grp = android_id_to_group(state, gid);
-  if (grp != NULL) {
+  if (grp != nullptr) {
     return grp;
   }
   // Handle OEM range.
   grp = oem_id_to_group(gid, state);
-  if (grp != NULL) {
+  if (grp != nullptr) {
     return grp;
   }
   return app_id_to_group(gid, state);
@@ -648,15 +648,15 @@
 
 group* getgrgid(gid_t gid) { // NOLINT: implementing bad function.
   group_state_t* state = __group_state();
-  if (state == NULL) {
-    return NULL;
+  if (state == nullptr) {
+    return nullptr;
   }
   return getgrgid_internal(gid, state);
 }
 
 static group* getgrnam_internal(const char* name, group_state_t* state) {
   group* grp = android_name_to_group(state, name);
-  if (grp != NULL) {
+  if (grp != nullptr) {
     return grp;
   }
 
@@ -668,7 +668,7 @@
 
   // Handle OEM range.
   grp = oem_id_to_group(oem_id_from_name(name), state);
-  if (grp != NULL) {
+  if (grp != nullptr) {
     return grp;
   }
   return app_id_to_group(app_id_from_name(name, true), state);
@@ -676,8 +676,8 @@
 
 group* getgrnam(const char* name) { // NOLINT: implementing bad function.
   group_state_t* state = __group_state();
-  if (state == NULL) {
-    return NULL;
+  if (state == nullptr) {
+    return nullptr;
   }
   return getgrnam_internal(name, state);
 }
@@ -685,7 +685,7 @@
 static int getgroup_r(bool by_name, const char* name, gid_t gid, struct group* grp, char* buf,
                       size_t buflen, struct group** result) {
   ErrnoRestorer errno_restorer;
-  *result = NULL;
+  *result = nullptr;
   char* p = reinterpret_cast<char*>(
       __BIONIC_ALIGN(reinterpret_cast<uintptr_t>(buf), sizeof(uintptr_t)));
   if (p + sizeof(group_state_t) > buf + buflen) {
@@ -694,7 +694,7 @@
   group_state_t* state = reinterpret_cast<group_state_t*>(p);
   init_group_state(state);
   group* retval = (by_name ? getgrnam_internal(name, state) : getgrgid_internal(gid, state));
-  if (retval != NULL) {
+  if (retval != nullptr) {
     *grp = *retval;
     *result = grp;
     return 0;
@@ -703,7 +703,7 @@
 }
 
 int getgrgid_r(gid_t gid, struct group* grp, char* buf, size_t buflen, struct group** result) {
-  return getgroup_r(false, NULL, gid, grp, buf, buflen, result);
+  return getgroup_r(false, nullptr, gid, grp, buf, buflen, result);
 }
 
 int getgrnam_r(const char* name, struct group* grp, char* buf, size_t buflen,
@@ -724,11 +724,11 @@
 
 group* getgrent() {
   group_state_t* state = get_group_tls_buffer();
-  if (state == NULL) {
-    return NULL;
+  if (state == nullptr) {
+    return nullptr;
   }
   if (state->getgrent_idx < 0) {
-    return NULL;
+    return nullptr;
   }
 
   size_t start = 0;
@@ -766,5 +766,5 @@
   }
 
   // We are not reporting u1_a* and higher or we will be here forever
-  return NULL;
+  return nullptr;
 }
diff --git a/libc/bionic/jemalloc_wrapper.cpp b/libc/bionic/jemalloc_wrapper.cpp
index 19081a4..812884c 100644
--- a/libc/bionic/jemalloc_wrapper.cpp
+++ b/libc/bionic/jemalloc_wrapper.cpp
@@ -25,7 +25,7 @@
   size_t pagesize = getpagesize();
   size_t size = __BIONIC_ALIGN(bytes, pagesize);
   if (size < bytes) {
-    return NULL;
+    return nullptr;
   }
   return je_memalign(pagesize, size);
 }
diff --git a/libc/bionic/legacy_32_bit_support.cpp b/libc/bionic/legacy_32_bit_support.cpp
index ba59e8e..2de1bc7 100644
--- a/libc/bionic/legacy_32_bit_support.cpp
+++ b/libc/bionic/legacy_32_bit_support.cpp
@@ -104,12 +104,12 @@
 
 // There is no getrlimit64 system call, so we need to use prlimit64.
 int getrlimit64(int resource, rlimit64* limits64) {
-  return prlimit64(0, resource, NULL, limits64);
+  return prlimit64(0, resource, nullptr, limits64);
 }
 
 // There is no setrlimit64 system call, so we need to use prlimit64.
 int setrlimit64(int resource, const rlimit64* limits64) {
-  return prlimit64(0, resource, limits64, NULL);
+  return prlimit64(0, resource, limits64, nullptr);
 }
 
 // There is no prlimit system call, so we need to use prlimit64.
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 5c54341..f943402 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -346,7 +346,7 @@
   const Dtor minus1 = reinterpret_cast<Dtor>(static_cast<uintptr_t>(-1));
 
   // Sanity check - first entry must be -1.
-  if (array == NULL || fini_array[0] != minus1) {
+  if (array == nullptr || fini_array[0] != minus1) {
     return;
   }
 
@@ -355,7 +355,7 @@
 
   // Count the number of destructors.
   int count = 0;
-  while (fini_array[count] != NULL) {
+  while (fini_array[count] != nullptr) {
     ++count;
   }
 
diff --git a/libc/bionic/libc_init_dynamic.cpp b/libc/bionic/libc_init_dynamic.cpp
index c5606fb..0def359 100644
--- a/libc/bionic/libc_init_dynamic.cpp
+++ b/libc/bionic/libc_init_dynamic.cpp
@@ -130,7 +130,7 @@
   // so we need to ensure that these are called when the program exits
   // normally.
   if (structors->fini_array) {
-    __cxa_atexit(__libc_fini,structors->fini_array,NULL);
+    __cxa_atexit(__libc_fini,structors->fini_array,nullptr);
   }
 
   exit(slingshot(args.argc, args.argv, args.envp));
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index 3828def..9eb574a 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -117,8 +117,8 @@
   // The executable may have its own destructors listed in its .fini_array
   // so we need to ensure that these are called when the program exits
   // normally.
-  if (structors->fini_array != NULL) {
-    __cxa_atexit(__libc_fini,structors->fini_array,NULL);
+  if (structors->fini_array != nullptr) {
+    __cxa_atexit(__libc_fini,structors->fini_array,nullptr);
   }
 
   exit(slingshot(args.argc, args.argv, args.envp));
diff --git a/libc/bionic/libgen.cpp b/libc/bionic/libgen.cpp
index 33b46a1..b952822 100644
--- a/libc/bionic/libgen.cpp
+++ b/libc/bionic/libgen.cpp
@@ -37,13 +37,13 @@
 #include "bionic/pthread_internal.h"
 
 static int __basename_r(const char* path, char* buffer, size_t buffer_size) {
-  const char* startp = NULL;
-  const char* endp = NULL;
+  const char* startp = nullptr;
+  const char* endp = nullptr;
   int len;
   int result;
 
   // Empty or NULL string gets treated as ".".
-  if (path == NULL || *path == '\0') {
+  if (path == nullptr || *path == '\0') {
     startp = ".";
     len = 1;
     goto Exit;
@@ -72,7 +72,7 @@
 
  Exit:
   result = len;
-  if (buffer == NULL) {
+  if (buffer == nullptr) {
     return result;
   }
   if (len > static_cast<int>(buffer_size) - 1) {
@@ -94,12 +94,12 @@
 }
 
 static int __dirname_r(const char* path, char* buffer, size_t buffer_size) {
-  const char* endp = NULL;
+  const char* endp = nullptr;
   int len;
   int result;
 
   // Empty or NULL string gets treated as ".".
-  if (path == NULL || *path == '\0') {
+  if (path == nullptr || *path == '\0') {
     path = ".";
     len = 1;
     goto Exit;
@@ -135,7 +135,7 @@
     errno = ENAMETOOLONG;
     return -1;
   }
-  if (buffer == NULL) {
+  if (buffer == nullptr) {
     return result;
   }
 
@@ -160,11 +160,11 @@
 char* basename(const char* path) {
   char* buf = __get_bionic_tls().basename_buf;
   int rc = __basename_r(path, buf, sizeof(__get_bionic_tls().basename_buf));
-  return (rc < 0) ? NULL : buf;
+  return (rc < 0) ? nullptr : buf;
 }
 
 char* dirname(const char* path) {
   char* buf = __get_bionic_tls().dirname_buf;
   int rc = __dirname_r(path, buf, sizeof(__get_bionic_tls().dirname_buf));
-  return (rc < 0) ? NULL : buf;
+  return (rc < 0) ? nullptr : buf;
 }
diff --git a/libc/bionic/locale.cpp b/libc/bionic/locale.cpp
index 08c9401..2a5bcab 100644
--- a/libc/bionic/locale.cpp
+++ b/libc/bionic/locale.cpp
@@ -70,7 +70,7 @@
 };
 
 size_t __ctype_get_mb_cur_max() {
-  locale_t l = uselocale(NULL);
+  locale_t l = uselocale(nullptr);
   if (l == LC_GLOBAL_LOCALE) {
     return __bionic_current_locale_is_utf8 ? 4 : 1;
   } else {
@@ -142,14 +142,14 @@
 
 locale_t newlocale(int category_mask, const char* locale_name, locale_t /*base*/) {
   // Are 'category_mask' and 'locale_name' valid?
-  if ((category_mask & ~LC_ALL_MASK) != 0 || locale_name == NULL) {
+  if ((category_mask & ~LC_ALL_MASK) != 0 || locale_name == nullptr) {
     errno = EINVAL;
-    return NULL;
+    return nullptr;
   }
 
   if (!__is_supported_locale(locale_name)) {
     errno = ENOENT;
-    return NULL;
+    return nullptr;
   }
 
   return new __locale_t(__is_utf8_locale(locale_name) ? 4 : 1);
@@ -159,15 +159,15 @@
   // Is 'category' valid?
   if (category < LC_CTYPE || category > LC_IDENTIFICATION) {
     errno = EINVAL;
-    return NULL;
+    return nullptr;
   }
 
   // Caller wants to set the locale rather than just query?
-  if (locale_name != NULL) {
+  if (locale_name != nullptr) {
     if (!__is_supported_locale(locale_name)) {
       // We don't support this locale.
       errno = ENOENT;
-      return NULL;
+      return nullptr;
     }
     __bionic_current_locale_is_utf8 = __is_utf8_locale(locale_name);
   }
@@ -187,11 +187,11 @@
   locale_t old_locale = *get_current_locale_ptr();
 
   // If this is the first call to uselocale(3) on this thread, we return LC_GLOBAL_LOCALE.
-  if (old_locale == NULL) {
+  if (old_locale == nullptr) {
     old_locale = LC_GLOBAL_LOCALE;
   }
 
-  if (new_locale != NULL) {
+  if (new_locale != nullptr) {
     *get_current_locale_ptr() = new_locale;
   }
 
diff --git a/libc/bionic/mbrtoc16.cpp b/libc/bionic/mbrtoc16.cpp
index 2180516..acea426 100644
--- a/libc/bionic/mbrtoc16.cpp
+++ b/libc/bionic/mbrtoc16.cpp
@@ -60,10 +60,10 @@
 
 size_t mbrtoc16(char16_t* pc16, const char* s, size_t n, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
 
   char16_t __private_pc16;
-  if (pc16 == NULL) {
+  if (pc16 == nullptr) {
     pc16 = &__private_pc16;
   }
 
diff --git a/libc/bionic/mbrtoc32.cpp b/libc/bionic/mbrtoc32.cpp
index 88a077c..644e542 100644
--- a/libc/bionic/mbrtoc32.cpp
+++ b/libc/bionic/mbrtoc32.cpp
@@ -35,7 +35,7 @@
 
 size_t mbrtoc32(char32_t* pc32, const char* s, size_t n, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
 
   // We should never get to a state which has all 4 bytes of the sequence set.
   // Full state verification is done when decoding the sequence (after we have
@@ -44,10 +44,10 @@
     return mbstate_reset_and_return_illegal(EINVAL, state);
   }
 
-  if (s == NULL) {
+  if (s == nullptr) {
     s = "";
     n = 1;
-    pc32 = NULL;
+    pc32 = nullptr;
   }
 
   if (n == 0) {
@@ -57,7 +57,7 @@
   uint8_t ch;
   if (mbsinit(state) && (((ch = static_cast<uint8_t>(*s)) & ~0x7f) == 0)) {
     // Fast path for plain ASCII characters.
-    if (pc32 != NULL) {
+    if (pc32 != nullptr) {
       *pc32 = ch;
     }
     return (ch != '\0' ? 1 : 0);
@@ -131,7 +131,7 @@
     // Malformed input; invalid code points.
     return mbstate_reset_and_return_illegal(EILSEQ, state);
   }
-  if (pc32 != NULL) {
+  if (pc32 != nullptr) {
     *pc32 = c32;
   }
   return mbstate_reset_and_return(c32 == U'\0' ? 0 : bytes_wanted, state);
diff --git a/libc/bionic/mntent.cpp b/libc/bionic/mntent.cpp
index 92284ce..6a12e78 100644
--- a/libc/bionic/mntent.cpp
+++ b/libc/bionic/mntent.cpp
@@ -38,7 +38,7 @@
 
 mntent* getmntent_r(FILE* fp, struct mntent* e, char* buf, int buf_len) {
   memset(e, 0, sizeof(*e));
-  while (fgets(buf, buf_len, fp) != NULL) {
+  while (fgets(buf, buf_len, fp) != nullptr) {
     // Entries look like "proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0".
     // That is: mnt_fsname mnt_dir mnt_type mnt_opts 0 0.
     int fsname0, fsname1, dir0, dir1, type0, type1, opts0, opts1;
@@ -60,7 +60,7 @@
       return e;
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 FILE* setmntent(const char* path, const char* mode) {
@@ -68,7 +68,7 @@
 }
 
 int endmntent(FILE* fp) {
-  if (fp != NULL) {
+  if (fp != nullptr) {
     fclose(fp);
   }
   return 1;
diff --git a/libc/bionic/new.cpp b/libc/bionic/new.cpp
index 9499ff5..a0da2fb 100644
--- a/libc/bionic/new.cpp
+++ b/libc/bionic/new.cpp
@@ -25,7 +25,7 @@
 
 void* operator new(std::size_t size) {
     void* p = malloc(size);
-    if (p == NULL) {
+    if (p == nullptr) {
         async_safe_fatal("new failed to allocate %zu bytes", size);
     }
     return p;
@@ -33,7 +33,7 @@
 
 void* operator new[](std::size_t size) {
     void* p = malloc(size);
-    if (p == NULL) {
+    if (p == nullptr) {
         async_safe_fatal("new[] failed to allocate %zu bytes", size);
     }
     return p;
diff --git a/libc/bionic/posix_timers.cpp b/libc/bionic/posix_timers.cpp
index 47d6db0..f522516 100644
--- a/libc/bionic/posix_timers.cpp
+++ b/libc/bionic/posix_timers.cpp
@@ -92,7 +92,7 @@
     } else if (si.si_code == SI_TKILL) {
       // This signal was sent because someone wants us to exit.
       free(timer);
-      return NULL;
+      return nullptr;
     }
   }
 }
@@ -105,11 +105,11 @@
 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_create.html
 int timer_create(clockid_t clock_id, sigevent* evp, timer_t* timer_id) {
   PosixTimer* timer = reinterpret_cast<PosixTimer*>(malloc(sizeof(PosixTimer)));
-  if (timer == NULL) {
+  if (timer == nullptr) {
     return -1;
   }
 
-  timer->sigev_notify = (evp == NULL) ? SIGEV_SIGNAL : evp->sigev_notify;
+  timer->sigev_notify = (evp == nullptr) ? SIGEV_SIGNAL : evp->sigev_notify;
 
   // If not a SIGEV_THREAD timer, the kernel can handle it without our help.
   if (timer->sigev_notify != SIGEV_THREAD) {
@@ -128,7 +128,7 @@
   atomic_init(&timer->deleted, false);
 
   // Check arguments that the kernel doesn't care about but we do.
-  if (timer->callback == NULL) {
+  if (timer->callback == nullptr) {
     free(timer);
     errno = EINVAL;
     return -1;
@@ -136,7 +136,7 @@
 
   // Create this timer's thread.
   pthread_attr_t thread_attributes;
-  if (evp->sigev_notify_attributes == NULL) {
+  if (evp->sigev_notify_attributes == nullptr) {
     pthread_attr_init(&thread_attributes);
   } else {
     thread_attributes = *reinterpret_cast<pthread_attr_t*>(evp->sigev_notify_attributes);
diff --git a/libc/bionic/pthread_attr.cpp b/libc/bionic/pthread_attr.cpp
index 93177f1..3c4b169 100644
--- a/libc/bionic/pthread_attr.cpp
+++ b/libc/bionic/pthread_attr.cpp
@@ -43,7 +43,7 @@
 __BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_attr_init(pthread_attr_t* attr) {
   attr->flags = 0;
-  attr->stack_base = NULL;
+  attr->stack_base = nullptr;
   attr->stack_size = PTHREAD_STACK_SIZE_DEFAULT;
   attr->guard_size = PTHREAD_GUARD_SIZE;
   attr->sched_policy = SCHED_NORMAL;
@@ -206,7 +206,7 @@
     async_safe_fatal("couldn't open /proc/self/maps: %s", strerror(errno));
   }
   char line[BUFSIZ];
-  while (fgets(line, sizeof(line), fp) != NULL) {
+  while (fgets(line, sizeof(line), fp) != nullptr) {
     uintptr_t lo, hi;
     if (sscanf(line, "%" SCNxPTR "-%" SCNxPTR, &lo, &hi) == 2) {
       if (lo <= startstack && startstack <= hi) {
diff --git a/libc/bionic/pthread_cond.cpp b/libc/bionic/pthread_cond.cpp
index a42506a..9f0f8fa 100644
--- a/libc/bionic/pthread_cond.cpp
+++ b/libc/bionic/pthread_cond.cpp
@@ -136,7 +136,7 @@
   pthread_cond_internal_t* cond = __get_internal_cond(cond_interface);
 
   unsigned int init_state = 0;
-  if (attr != NULL) {
+  if (attr != nullptr) {
     init_state = (*attr & COND_FLAGS_MASK);
   }
   atomic_init(&cond->state, init_state);
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index 21a707b..c95d400 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -88,7 +88,7 @@
 
 void __init_alternate_signal_stack(pthread_internal_t* thread) {
   // Create and set an alternate signal stack.
-  void* stack_base = mmap(NULL, SIGNAL_STACK_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+  void* stack_base = mmap(nullptr, SIGNAL_STACK_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
   if (stack_base != MAP_FAILED) {
     // Create a guard to catch stack overflows in signal handlers.
     if (mprotect(stack_base, PTHREAD_GUARD_SIZE, PROT_NONE) == -1) {
@@ -99,7 +99,7 @@
     ss.ss_sp = reinterpret_cast<uint8_t*>(stack_base) + PTHREAD_GUARD_SIZE;
     ss.ss_size = SIGNAL_STACK_SIZE - PTHREAD_GUARD_SIZE;
     ss.ss_flags = 0;
-    sigaltstack(&ss, NULL);
+    sigaltstack(&ss, nullptr);
     thread->alternate_signal_stack = stack_base;
 
     // We can only use const static allocated string for mapped region name, as Android kernel
@@ -166,13 +166,13 @@
   // Create a new private anonymous map.
   int prot = PROT_READ | PROT_WRITE;
   int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE;
-  void* space = mmap(NULL, mmap_size, prot, flags, -1, 0);
+  void* space = mmap(nullptr, mmap_size, prot, flags, -1, 0);
   if (space == MAP_FAILED) {
     async_safe_format_log(ANDROID_LOG_WARN,
                       "libc",
                       "pthread_create failed: couldn't allocate %zu-bytes mapped space: %s",
                       mmap_size, strerror(errno));
-    return NULL;
+    return nullptr;
   }
 
   // Stack is at the lower end of mapped space, stack guard region is at the lower end of stack.
@@ -182,7 +182,7 @@
                           "pthread_create failed: couldn't mprotect PROT_NONE %zu-byte stack guard region: %s",
                           stack_guard_size, strerror(errno));
     munmap(space, mmap_size);
-    return NULL;
+    return nullptr;
   }
   prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, space, stack_guard_size, "thread stack guard");
 
@@ -193,7 +193,7 @@
   size_t mmap_size;
   uint8_t* stack_top;
 
-  if (attr->stack_base == NULL) {
+  if (attr->stack_base == nullptr) {
     // The caller didn't provide a stack, so allocate one.
     // Make sure the stack size and guard size are multiples of PAGE_SIZE.
     if (__builtin_add_overflow(attr->stack_size, attr->guard_size, &mmap_size)) return EAGAIN;
@@ -201,7 +201,7 @@
     mmap_size = __BIONIC_ALIGN(mmap_size, PAGE_SIZE);
     attr->guard_size = __BIONIC_ALIGN(attr->guard_size, PAGE_SIZE);
     attr->stack_base = __create_thread_mapped_space(mmap_size, attr->guard_size);
-    if (attr->stack_base == NULL) {
+    if (attr->stack_base == nullptr) {
       return EAGAIN;
     }
     stack_top = reinterpret_cast<uint8_t*>(attr->stack_base) + mmap_size;
@@ -261,7 +261,7 @@
 // going to run user code on it. We swap out the user's start routine for this and take advantage
 // of the regular thread teardown to free up resources.
 static void* __do_nothing(void*) {
-  return NULL;
+  return nullptr;
 }
 
 
@@ -271,15 +271,15 @@
   ErrnoRestorer errno_restorer;
 
   pthread_attr_t thread_attr;
-  if (attr == NULL) {
+  if (attr == nullptr) {
     pthread_attr_init(&thread_attr);
   } else {
     thread_attr = *attr;
-    attr = NULL; // Prevent misuse below.
+    attr = nullptr; // Prevent misuse below.
   }
 
-  pthread_internal_t* thread = NULL;
-  void* child_stack = NULL;
+  pthread_internal_t* thread = nullptr;
+  void* child_stack = nullptr;
   int result = __allocate_thread(&thread_attr, &thread, &child_stack);
   if (result != 0) {
     return result;
diff --git a/libc/bionic/pthread_detach.cpp b/libc/bionic/pthread_detach.cpp
index 011e6c6..c2e4127 100644
--- a/libc/bionic/pthread_detach.cpp
+++ b/libc/bionic/pthread_detach.cpp
@@ -35,7 +35,7 @@
 __BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_detach(pthread_t t) {
   pthread_internal_t* thread = __pthread_internal_find(t);
-  if (thread == NULL) {
+  if (thread == nullptr) {
     return ESRCH;
   }
 
@@ -48,7 +48,7 @@
     return 0;
   } else if (old_state == THREAD_EXITED_NOT_JOINED) {
     // Use pthread_join to clean it up.
-    return pthread_join(t, NULL);
+    return pthread_join(t, nullptr);
   }
   return EINVAL;
 }
diff --git a/libc/bionic/pthread_exit.cpp b/libc/bionic/pthread_exit.cpp
index f1b65fd..ac5d429 100644
--- a/libc/bionic/pthread_exit.cpp
+++ b/libc/bionic/pthread_exit.cpp
@@ -91,16 +91,16 @@
   // space (see pthread_key_delete).
   pthread_key_clean_all();
 
-  if (thread->alternate_signal_stack != NULL) {
+  if (thread->alternate_signal_stack != nullptr) {
     // Tell the kernel to stop using the alternate signal stack.
     stack_t ss;
     memset(&ss, 0, sizeof(ss));
     ss.ss_flags = SS_DISABLE;
-    sigaltstack(&ss, NULL);
+    sigaltstack(&ss, nullptr);
 
     // Free it.
     munmap(thread->alternate_signal_stack, SIGNAL_STACK_SIZE);
-    thread->alternate_signal_stack = NULL;
+    thread->alternate_signal_stack = nullptr;
   }
 
   ThreadJoinState old_state = THREAD_NOT_JOINED;
@@ -113,7 +113,7 @@
     // So we can free mapped space, which includes pthread_internal_t and thread stack.
     // First make sure that the kernel does not try to clear the tid field
     // because we'll have freed the memory before the thread actually exits.
-    __set_tid_address(NULL);
+    __set_tid_address(nullptr);
 
     // pthread_internal_t is freed below with stack, not here.
     __pthread_internal_remove(thread);
diff --git a/libc/bionic/pthread_join.cpp b/libc/bionic/pthread_join.cpp
index be76c20..9aad458 100644
--- a/libc/bionic/pthread_join.cpp
+++ b/libc/bionic/pthread_join.cpp
@@ -39,7 +39,7 @@
   }
 
   pthread_internal_t* thread = __pthread_internal_find(t);
-  if (thread == NULL) {
+  if (thread == nullptr) {
     return ESRCH;
   }
 
@@ -60,7 +60,7 @@
 
   // Wait for the thread to actually exit, if it hasn't already.
   while (*tid_ptr != 0) {
-    __futex_wait(tid_ptr, tid, NULL);
+    __futex_wait(tid_ptr, tid, nullptr);
   }
 
   if (return_value) {
diff --git a/libc/bionic/pthread_key.cpp b/libc/bionic/pthread_key.cpp
index baff9cc..f3878a6 100644
--- a/libc/bionic/pthread_key.cpp
+++ b/libc/bionic/pthread_key.cpp
@@ -79,7 +79,7 @@
     size_t called_destructor_count = 0;
     for (size_t i = 0; i < BIONIC_PTHREAD_KEY_COUNT; ++i) {
       uintptr_t seq = atomic_load_explicit(&key_map[i].seq, memory_order_relaxed);
-      if (SeqOfKeyInUse(seq) && seq == key_data[i].seq && key_data[i].data != NULL) {
+      if (SeqOfKeyInUse(seq) && seq == key_data[i].seq && key_data[i].data != nullptr) {
         // Other threads may be calling pthread_key_delete/pthread_key_create while current thread
         // is exiting. So we need to ensure we read the right key_destructor.
         // We can rely on a user-established happens-before relationship between the creation and
@@ -89,7 +89,7 @@
         // right key_destructor, or the sequence number must have changed when we reread it below.
         key_destructor_t key_destructor = reinterpret_cast<key_destructor_t>(
           atomic_load_explicit(&key_map[i].key_destructor, memory_order_relaxed));
-        if (key_destructor == NULL) {
+        if (key_destructor == nullptr) {
           continue;
         }
         atomic_thread_fence(memory_order_acquire);
@@ -102,7 +102,7 @@
         // We don't do this if 'key_destructor == NULL' just in case another destructor
         // function is responsible for manually releasing the corresponding data.
         void* data = key_data[i].data;
-        key_data[i].data = NULL;
+        key_data[i].data = nullptr;
 
         (*key_destructor)(data);
         ++called_destructor_count;
@@ -154,7 +154,7 @@
 __BIONIC_WEAK_FOR_NATIVE_BRIDGE
 void* pthread_getspecific(pthread_key_t key) {
   if (__predict_false(!KeyInValidRange(key))) {
-    return NULL;
+    return nullptr;
   }
   key &= ~KEY_VALID_FLAG;
   uintptr_t seq = atomic_load_explicit(&key_map[key].seq, memory_order_relaxed);
@@ -166,8 +166,8 @@
   }
   // We arrive here when current thread holds the seq of an deleted pthread key. So the
   // data is for the deleted pthread key, and should be cleared.
-  data->data = NULL;
-  return NULL;
+  data->data = nullptr;
+  return nullptr;
 }
 
 __BIONIC_WEAK_FOR_NATIVE_BRIDGE
diff --git a/libc/bionic/pthread_mutex.cpp b/libc/bionic/pthread_mutex.cpp
index 7f48972..fda0b93 100644
--- a/libc/bionic/pthread_mutex.cpp
+++ b/libc/bionic/pthread_mutex.cpp
@@ -502,7 +502,7 @@
 
     memset(mutex, 0, sizeof(pthread_mutex_internal_t));
 
-    if (__predict_true(attr == NULL)) {
+    if (__predict_true(attr == nullptr)) {
         atomic_init(&mutex->state, MUTEX_TYPE_BITS_NORMAL);
         return 0;
     }
@@ -800,7 +800,7 @@
     // Some apps depend on being able to pass NULL as a mutex and get EINVAL
     // back. Don't need to worry about it for LP64 since the ABI is brand new,
     // but keep compatibility for LP32. http://b/19995172.
-    if (mutex_interface == NULL) {
+    if (mutex_interface == nullptr) {
         return EINVAL;
     }
 #endif
@@ -834,7 +834,7 @@
     // Some apps depend on being able to pass NULL as a mutex and get EINVAL
     // back. Don't need to worry about it for LP64 since the ABI is brand new,
     // but keep compatibility for LP32. http://b/19995172.
-    if (mutex_interface == NULL) {
+    if (mutex_interface == nullptr) {
         return EINVAL;
     }
 #endif
diff --git a/libc/bionic/pthread_rwlock.cpp b/libc/bionic/pthread_rwlock.cpp
index 4f4c461..2b9be98 100644
--- a/libc/bionic/pthread_rwlock.cpp
+++ b/libc/bionic/pthread_rwlock.cpp
@@ -228,7 +228,7 @@
 
   memset(rwlock, 0, sizeof(pthread_rwlock_internal_t));
 
-  if (__predict_false(attr != NULL)) {
+  if (__predict_false(attr != nullptr)) {
     rwlock->pshared = __rwlockattr_getpshared(attr);
     int kind = __rwlockattr_getkind(attr);
     switch (kind) {
diff --git a/libc/bionic/pty.cpp b/libc/bionic/pty.cpp
index 599cbd2..71e14d9 100644
--- a/libc/bionic/pty.cpp
+++ b/libc/bionic/pty.cpp
@@ -55,11 +55,11 @@
   bionic_tls& tls = __get_bionic_tls();
   char* buf = tls.ptsname_buf;
   int error = ptsname_r(fd, buf, sizeof(tls.ptsname_buf));
-  return (error == 0) ? buf : NULL;
+  return (error == 0) ? buf : nullptr;
 }
 
 int ptsname_r(int fd, char* buf, size_t len) {
-  if (buf == NULL) {
+  if (buf == nullptr) {
     errno = EINVAL;
     return errno;
   }
@@ -82,11 +82,11 @@
   bionic_tls& tls = __get_bionic_tls();
   char* buf = tls.ttyname_buf;
   int error = ttyname_r(fd, buf, sizeof(tls.ttyname_buf));
-  return (error == 0) ? buf : NULL;
+  return (error == 0) ? buf : nullptr;
 }
 
 int ttyname_r(int fd, char* buf, size_t len) {
-  if (buf == NULL) {
+  if (buf == nullptr) {
     errno = EINVAL;
     return errno;
   }
@@ -124,7 +124,7 @@
   }
 
   char buf[32];
-  if (name == NULL) {
+  if (name == nullptr) {
     name = buf;
   }
   if (ptsname_r(*master, name, sizeof(buf)) != 0) {
@@ -138,10 +138,10 @@
     return -1;
   }
 
-  if (t != NULL) {
+  if (t != nullptr) {
     tcsetattr(*slave, TCSAFLUSH, t);
   }
-  if (ws != NULL) {
+  if (ws != nullptr) {
     ioctl(*slave, TIOCSWINSZ, ws);
   }
 
@@ -181,7 +181,7 @@
 int login_tty(int fd) {
   setsid();
 
-  if (ioctl(fd, TIOCSCTTY, NULL) == -1) {
+  if (ioctl(fd, TIOCSCTTY, nullptr) == -1) {
     return -1;
   }
 
diff --git a/libc/bionic/reboot.cpp b/libc/bionic/reboot.cpp
index 9cf4411..b0a1f97 100644
--- a/libc/bionic/reboot.cpp
+++ b/libc/bionic/reboot.cpp
@@ -32,5 +32,5 @@
 extern "C" int __reboot(int, int, int, void*);
 
 int reboot(int mode) {
-  return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, mode, NULL);
+  return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, mode, nullptr);
 }
diff --git a/libc/bionic/recv.cpp b/libc/bionic/recv.cpp
index 60f264d..32a7a72 100644
--- a/libc/bionic/recv.cpp
+++ b/libc/bionic/recv.cpp
@@ -29,5 +29,5 @@
 #include <sys/socket.h>
 
 ssize_t recv(int socket, void *buf, size_t len, int flags) {
-  return recvfrom(socket, buf, len, flags, NULL, 0);
+  return recvfrom(socket, buf, len, flags, nullptr, nullptr);
 }
diff --git a/libc/bionic/sched_getcpu.cpp b/libc/bionic/sched_getcpu.cpp
index 1f92e54..f245fba 100644
--- a/libc/bionic/sched_getcpu.cpp
+++ b/libc/bionic/sched_getcpu.cpp
@@ -33,7 +33,7 @@
 
 int sched_getcpu() {
   unsigned cpu;
-  int rc = __getcpu(&cpu, NULL, NULL);
+  int rc = __getcpu(&cpu, nullptr, nullptr);
   if (rc == -1) {
     return -1; // errno is already set.
   }
diff --git a/libc/bionic/send.cpp b/libc/bionic/send.cpp
index 2e5d457..7106c43 100644
--- a/libc/bionic/send.cpp
+++ b/libc/bionic/send.cpp
@@ -29,5 +29,5 @@
 #include <sys/socket.h>
 
 ssize_t send(int socket, const void* buf, size_t len, int flags) {
-  return sendto(socket, buf, len, flags, NULL, 0);
+  return sendto(socket, buf, len, flags, nullptr, 0);
 }
diff --git a/libc/bionic/sigaction.cpp b/libc/bionic/sigaction.cpp
index 41923cf..fb57d1c 100644
--- a/libc/bionic/sigaction.cpp
+++ b/libc/bionic/sigaction.cpp
@@ -40,7 +40,7 @@
 
 int sigaction(int signal, const struct sigaction* bionic_new_action, struct sigaction* bionic_old_action) {
   __kernel_sigaction kernel_new_action;
-  if (bionic_new_action != NULL) {
+  if (bionic_new_action != nullptr) {
     kernel_new_action.sa_flags = bionic_new_action->sa_flags;
     kernel_new_action.sa_handler = bionic_new_action->sa_handler;
     kernel_new_action.sa_mask = filter_reserved_signals(bionic_new_action->sa_mask);
@@ -62,11 +62,11 @@
 
   __kernel_sigaction kernel_old_action;
   int result = __rt_sigaction(signal,
-                              (bionic_new_action != NULL) ? &kernel_new_action : NULL,
-                              (bionic_old_action != NULL) ? &kernel_old_action : NULL,
+                              (bionic_new_action != nullptr) ? &kernel_new_action : nullptr,
+                              (bionic_old_action != nullptr) ? &kernel_old_action : nullptr,
                               sizeof(sigset_t));
 
-  if (bionic_old_action != NULL) {
+  if (bionic_old_action != nullptr) {
     bionic_old_action->sa_flags = kernel_old_action.sa_flags;
     bionic_old_action->sa_handler = kernel_old_action.sa_handler;
     bionic_old_action->sa_mask = kernel_old_action.sa_mask;
diff --git a/libc/bionic/strerror_r.cpp b/libc/bionic/strerror_r.cpp
index dad3fb3..1cf2abc 100644
--- a/libc/bionic/strerror_r.cpp
+++ b/libc/bionic/strerror_r.cpp
@@ -22,18 +22,18 @@
 };
 
 static const char* __code_string_lookup(const Pair* strings, int code) {
-  for (size_t i = 0; strings[i].msg != NULL; ++i) {
+  for (size_t i = 0; strings[i].msg != nullptr; ++i) {
     if (strings[i].code == code) {
       return strings[i].msg;
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 static const Pair _sys_error_strings[] = {
 #define  __BIONIC_ERRDEF(x,y,z)  { x, z },
 #include "private/bionic_errdefs.h"
-  { 0, NULL }
+  { 0, nullptr }
 };
 
 extern "C" __LIBC_HIDDEN__ const char* __strerror_lookup(int error_number) {
@@ -43,7 +43,7 @@
 static const Pair _sys_signal_strings[] = {
 #define  __BIONIC_SIGDEF(signal_number, signal_description)  { signal_number, signal_description },
 #include "private/bionic_sigdefs.h"
-  { 0, NULL }
+  { 0, nullptr }
 };
 
 extern "C" __LIBC_HIDDEN__ const char* __strsignal_lookup(int signal_number) {
@@ -55,7 +55,7 @@
   size_t length;
 
   const char* error_name = __strerror_lookup(error_number);
-  if (error_name != NULL) {
+  if (error_name != nullptr) {
     length = strlcpy(buf, error_name, buf_len);
   } else {
     length = async_safe_format_buffer(buf, buf_len, "Unknown error %d", error_number);
@@ -76,7 +76,7 @@
 
 extern "C" __LIBC_HIDDEN__ const char* __strsignal(int signal_number, char* buf, size_t buf_len) {
   const char* signal_name = __strsignal_lookup(signal_number);
-  if (signal_name != NULL) {
+  if (signal_name != nullptr) {
     return signal_name;
   }
 
@@ -87,7 +87,7 @@
   }
   size_t length = snprintf(buf, buf_len, "%s signal %d", prefix, signal_number);
   if (length >= buf_len) {
-    return NULL;
+    return nullptr;
   }
   return buf;
 }
diff --git a/libc/bionic/strsignal.cpp b/libc/bionic/strsignal.cpp
index 81a8f95..1cdfec1 100644
--- a/libc/bionic/strsignal.cpp
+++ b/libc/bionic/strsignal.cpp
@@ -36,7 +36,7 @@
 char* strsignal(int signal_number) {
   // Just return the original constant in the easy cases.
   char* result = const_cast<char*>(__strsignal_lookup(signal_number));
-  if (result != NULL) {
+  if (result != nullptr) {
     return result;
   }
 
diff --git a/libc/bionic/sysinfo.cpp b/libc/bionic/sysinfo.cpp
index 947de95..1d1070e 100644
--- a/libc/bionic/sysinfo.cpp
+++ b/libc/bionic/sysinfo.cpp
@@ -53,7 +53,7 @@
 
   int result = 0;
   dirent* entry;
-  while ((entry = reader.ReadEntry()) != NULL) {
+  while ((entry = reader.ReadEntry()) != nullptr) {
     if (entry->d_type == DT_DIR && __matches_cpuN(entry->d_name)) {
       ++result;
     }
diff --git a/libc/bionic/syslog.cpp b/libc/bionic/syslog.cpp
index 9424573..d1a0c5b 100644
--- a/libc/bionic/syslog.cpp
+++ b/libc/bionic/syslog.cpp
@@ -21,11 +21,11 @@
 
 #include <async_safe/log.h>
 
-static const char* syslog_log_tag = NULL;
+static const char* syslog_log_tag = nullptr;
 static int syslog_priority_mask = 0xff;
 
 void closelog() {
-  syslog_log_tag = NULL;
+  syslog_log_tag = nullptr;
 }
 
 void openlog(const char* log_tag, int /*options*/, int /*facility*/) {
@@ -58,7 +58,7 @@
 
   // What's our log tag?
   const char* log_tag = syslog_log_tag;
-  if (log_tag == NULL) {
+  if (log_tag == nullptr) {
     log_tag = getprogname();
   }
 
@@ -78,7 +78,7 @@
   // glibc's printf family support %m directly, but our BSD-based one doesn't.
   // If the format string seems to contain "%m", rewrite it.
   const char* log_fmt = fmt;
-  if (strstr(fmt, "%m") != NULL) {
+  if (strstr(fmt, "%m") != nullptr) {
     size_t dst_len = 1024;
     char* dst = reinterpret_cast<char*>(malloc(dst_len));
     log_fmt = dst;
diff --git a/libc/bionic/tdestroy.cpp b/libc/bionic/tdestroy.cpp
index 2968ff9..6606c56 100644
--- a/libc/bionic/tdestroy.cpp
+++ b/libc/bionic/tdestroy.cpp
@@ -27,7 +27,7 @@
 // This is a GNU extension, not available from BSD.
 void tdestroy(void* root, void (*destroy_func)(void*)) {
   node_t* root_node = reinterpret_cast<node_t*>(root);
-  if (root_node == NULL) {
+  if (root_node == nullptr) {
     return;
   }
   if (root_node->llink) {
diff --git a/libc/bionic/tmpfile.cpp b/libc/bionic/tmpfile.cpp
index bda3566..4378e84 100644
--- a/libc/bionic/tmpfile.cpp
+++ b/libc/bionic/tmpfile.cpp
@@ -42,9 +42,9 @@
 #include "private/ScopedSignalBlocker.h"
 
 static FILE* __tmpfile_dir(const char* tmp_dir) {
-  char* path = NULL;
+  char* path = nullptr;
   if (asprintf(&path, "%s/tmp.XXXXXXXXXX", tmp_dir) == -1) {
-    return NULL;
+    return nullptr;
   }
 
   int fd;
@@ -53,7 +53,7 @@
     fd = mkstemp(path);
     if (fd == -1) {
       free(path);
-      return NULL;
+      return nullptr;
     }
 
     // Unlink the file now so that it's removed when closed.
@@ -67,20 +67,20 @@
     if (rc == -1) {
       ErrnoRestorer errno_restorer;
       close(fd);
-      return NULL;
+      return nullptr;
     }
   }
 
   // Turn the file descriptor into a FILE*.
   FILE* fp = fdopen(fd, "w+");
-  if (fp != NULL) {
+  if (fp != nullptr) {
     return fp;
   }
 
   // Failure. Clean up. We already unlinked, so we just need to close.
   ErrnoRestorer errno_restorer;
   close(fd);
-  return NULL;
+  return nullptr;
 }
 
 FILE* tmpfile() {
@@ -90,7 +90,7 @@
   // This means we can't do the usual trick of calling unlink before handing the file back.
 
   FILE* fp = __tmpfile_dir("/data/local/tmp");
-  if (fp == NULL) {
+  if (fp == nullptr) {
     // P_tmpdir is "/tmp/", but POSIX explicitly says that tmpdir(3) should try P_tmpdir before
     // giving up. This is potentially useful for bionic on the host anyway.
     fp = __tmpfile_dir(P_tmpdir);
diff --git a/libc/bionic/wait.cpp b/libc/bionic/wait.cpp
index e5c93aa..3e59f51 100644
--- a/libc/bionic/wait.cpp
+++ b/libc/bionic/wait.cpp
@@ -32,14 +32,14 @@
 extern "C" int __waitid(idtype_t which, id_t id, siginfo_t* info, int options, struct rusage* ru);
 
 pid_t wait(int* status) {
-  return wait4(-1, status, 0, NULL);
+  return wait4(-1, status, 0, nullptr);
 }
 
 pid_t waitpid(pid_t pid, int* status, int options) {
-  return wait4(pid, status, options, NULL);
+  return wait4(pid, status, options, nullptr);
 }
 
 int waitid(idtype_t which, id_t id, siginfo_t* info, int options) {
   // The system call takes an optional struct rusage that we don't need.
-  return __waitid(which, id, info, options, NULL);
+  return __waitid(which, id, info, options, nullptr);
 }
diff --git a/libc/bionic/wchar.cpp b/libc/bionic/wchar.cpp
index 62023d6..dabe824 100644
--- a/libc/bionic/wchar.cpp
+++ b/libc/bionic/wchar.cpp
@@ -54,12 +54,12 @@
 //
 
 int mbsinit(const mbstate_t* ps) {
-  return (ps == NULL || (*(reinterpret_cast<const uint32_t*>(ps->__seq)) == 0));
+  return (ps == nullptr || (*(reinterpret_cast<const uint32_t*>(ps->__seq)) == 0));
 }
 
 size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
 
   // Our wchar_t is UTF-32.
   return mbrtoc32(reinterpret_cast<char32_t*>(pwc), s, n, state);
@@ -67,7 +67,7 @@
 
 size_t mbsnrtowcs(wchar_t* dst, const char** src, size_t nmc, size_t len, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
   size_t i, o, r;
 
   // The fast paths in the loops below are not safe if an ASCII
@@ -78,7 +78,7 @@
   }
 
   // Measure only?
-  if (dst == NULL) {
+  if (dst == nullptr) {
     for (i = o = 0; i < nmc; i += r, o++) {
       if (static_cast<uint8_t>((*src)[i]) < 0x80) {
         // Fast path for plain ASCII characters.
@@ -87,7 +87,7 @@
         }
         r = 1;
       } else {
-        r = mbrtowc(NULL, *src + i, nmc - i, state);
+        r = mbrtowc(nullptr, *src + i, nmc - i, state);
         if (r == __MB_ERR_ILLEGAL_SEQUENCE) {
           return mbstate_reset_and_return_illegal(EILSEQ, state);
         }
@@ -123,7 +123,7 @@
         return mbstate_reset_and_return_illegal(EILSEQ, state);
       }
       if (r == 0) {
-        *src = NULL;
+        *src = nullptr;
         return mbstate_reset_and_return(o, state);
       }
     }
@@ -138,7 +138,7 @@
 
 size_t wcrtomb(char* s, wchar_t wc, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
 
   // Our wchar_t is UTF-32.
   return c32rtomb(s, static_cast<char32_t>(wc), state);
@@ -146,7 +146,7 @@
 
 size_t wcsnrtombs(char* dst, const wchar_t** src, size_t nwc, size_t len, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
 
   if (!mbsinit(state)) {
     return mbstate_reset_and_return_illegal(EILSEQ, state);
@@ -154,7 +154,7 @@
 
   char buf[MB_LEN_MAX];
   size_t i, o, r;
-  if (dst == NULL) {
+  if (dst == nullptr) {
     for (i = o = 0; i < nwc; i++, o += r) {
       wchar_t wc = (*src)[i];
       if (static_cast<uint32_t>(wc) < 0x80) {
@@ -179,7 +179,7 @@
       // Fast path for plain ASCII characters.
       dst[o] = wc;
       if (wc == 0) {
-        *src = NULL;
+        *src = nullptr;
         return o;
       }
       r = 1;
diff --git a/libc/bionic/wcstod.cpp b/libc/bionic/wcstod.cpp
index 41a94fb..75a59f5 100644
--- a/libc/bionic/wcstod.cpp
+++ b/libc/bionic/wcstod.cpp
@@ -62,7 +62,7 @@
   f._bf._base = f._p = reinterpret_cast<unsigned char*>(ascii_str);
   f._bf._size = f._r = max_len;
   f._read = [](void*, char*, int) { return 0; }; // aka `eofread`, aka "no more data".
-  f._lb._base = NULL;
+  f._lb._base = nullptr;
 
   // Ask `parsefloat` to look at the same data more carefully.
 
diff --git a/libc/bionic/wctype.cpp b/libc/bionic/wctype.cpp
index 05b6e19..6e33b6c 100644
--- a/libc/bionic/wctype.cpp
+++ b/libc/bionic/wctype.cpp
@@ -155,7 +155,7 @@
 wctrans_t wctrans(const char* name) {
   if (strcmp(name, "tolower") == 0) return wctrans_tolower;
   if (strcmp(name, "toupper") == 0) return wctrans_toupper;
-  return 0;
+  return nullptr;
 }
 
 wctrans_t wctrans_l(const char* name, locale_t) {