Merge "Revert "Don't use serialized propertyinfo""
diff --git a/docs/status.md b/docs/status.md
index 0aaa0b3..d4ca913 100644
--- a/docs/status.md
+++ b/docs/status.md
@@ -1,71 +1,39 @@
-Android bionic status
-=====================
+# Android bionic status
 
-# Target API level behavioral differences
+## Bionic function availability
 
-Most bionic bug fixes and improvements have been made without checks for
-the app's `targetSdkVersion`. As of O there were exactly two exceptions,
-but there are likely to be more in future because of Project Treble.
+### POSIX
 
-Invalid `pthread_t` handling (targetSdkVersion >= O)
-----------------------------------------------------
+You can see the current status with respect to POSIX in the form of tests:
+https://android.googlesource.com/platform/bionic/+/master/tests/headers/posix/
 
-As part of a long-term goal to remove the global thread list,
-and in an attempt to flush out racy code, we changed how an invalid
-`pthread_t` is handled. For `pthread_detach`, `pthread_getcpuclockid`,
-`pthread_getschedparam`/`pthread_setschedparam`, `pthread_join`, and
-`pthread_kill`, instead of returning ESRCH when passed an invalid
-`pthread_t`, if you're targeting O or above, they'll abort with the
-message "attempt to use invalid pthread\_t".
+Some POSIX functionality is not supported by the Linux kernel, and
+is guarded with tests for `__linux__`. Other functionality is not
+supported by bionic or glibc, and guarded with tests for `__BIONIC__`
+and `__GLIBC__`. In other cases historical accidents mean 32-bit
+bionic diverged but 64-bit bionic matches POSIX; these are guarded with
+`__LP64__`.
 
-Note that this doesn't change behavior as much as you might think: the
-old lookup only held the global thread list lock for the duration of
-the lookup, so there was still a race between that and the dereference
-in the caller, given that callers actually need the tid to pass to some
-syscall or other, and sometimes update fields in the `pthread_internal_t`
-struct too.
+Most bionic-only diversions should be accompanied by an explanatory comment.
 
-We can't check a thread's tid against 0 to see whether a `pthread_t`
-is still valid because a dead thread gets its thread struct unmapped
-along with its stack, so the dereference isn't safe.
+Missing functions are either obsolete or explicitly disallowed by SELinux:
+  * `a64l`/`l64a`
+  * `confstr`
+  * `crypt`/`encrypt`/`setkey`
+  * `gethostid`
+  * `shm_open`/`shm_unlink`
+  * `sockatmark`
 
-To fix your code, taking the affected functions one by one:
+Missing functionality:
+  * `<aio.h>`
+  * `<wordexp.h>`
+  * Thread cancellation
+  * Robust mutexes
 
-  * `pthread_getcpuclockid` and `pthread_getschedparam`/`pthread_setschedparam`
-    should be fine. Unsafe calls to those seem highly unlikely.
+Run `./libc/tools/check-symbols-glibc.py` in bionic/ for the current
+list of POSIX functions implemented by glibc but not by bionic.
 
-  * Unsafe `pthread_detach` callers probably want to switch to
-    `pthread_attr_setdetachstate` instead, or use
-    `pthread_detach(pthread_self());` from the new thread's start routine
-    rather than calling detach in the parent.
-
-  * `pthread_join` calls should be safe anyway, because a joinable thread
-    won't actually exit and unmap until it's joined. If you're joining an
-    unjoinable thread, the fix is to stop marking it detached. If you're
-    joining an already-joined thread, you need to rethink your design!
-
-  * Unsafe `pthread_kill` calls aren't portably fixable. (And are obviously
-    inherently non-portable as-is.) The best alternative on Android is to
-    use `pthread_gettid_np` at some point that you know the thread to be
-    alive, and then call `kill`/`tgkill` with signal 0 (which checks
-    whether a process exists rather than actually sending a
-    signal). That's still not completely safe because if you're too late
-    the tid may have been reused, but your code is inherently unsafe without
-    a redesign anyway.
-
-Interruptable `sem_wait` (targetSdkVersion >= N)
-------------------------------------------------
-
-POSIX says that `sem_wait` can be interrupted by delivery of a
-signal. This wasn't historically true in Android, and when we fixed this
-bug we found that existing code relied on the old behavior. To preserve
-compatibility, `sem_wait` can only return EINTR on Android if the app
-targets N or later.
-
-# Bionic function availability
-
-libc
-----
+### libc
 
 Current libc symbols: https://android.googlesource.com/platform/bionic/+/master/libc/libc.map.txt
 
@@ -124,40 +92,11 @@
   G 803, H 825, I 826, J 846, J-MR1 873, J-MR2 881, K 896, L 1116, M 1181, N 1226, O 1278
 
 ```
-ndk-r17$ for i in `ls -1v platforms/android-*/arch-arm/usr/lib/libc.so` ; do echo $i; nm $i | grep -vw [AbdNnt] | grep -vw B | wc -l ; done
+ndk-r17$ for i in `ls -1v platforms/android-*/arch-arm/usr/lib/libc.so` ; do \
+  echo $i; nm $i | grep -vw [AbdNnt] | grep -vw B | wc -l ; done
 ```
 
-Run `./libc/tools/check-symbols-glibc.py` in bionic/ for the current
-list of POSIX functions implemented by glibc but not by bionic. Currently
-(2017-10):
-```
-aio_cancel
-aio_error
-aio_fsync
-aio_read
-aio_return
-aio_suspend
-aio_write
-lio_listio
-pthread_cancel
-pthread_mutex_consistent
-pthread_mutex_getprioceiling
-pthread_mutex_setprioceiling
-pthread_mutexattr_getprioceiling
-pthread_mutexattr_getprotocol
-pthread_mutexattr_getrobust
-pthread_mutexattr_setprioceiling
-pthread_mutexattr_setprotocol
-pthread_mutexattr_setrobust
-pthread_setcancelstate
-pthread_setcanceltype
-pthread_testcancel
-wordexp
-wordfree
-```
-
-libm
-----
+### libm
 
 Current libm symbols: https://android.googlesource.com/platform/bionic/+/master/libm/libm.map.txt
 
@@ -167,3 +106,64 @@
 
 libm function count over time:
   G 158, J-MR2 164, L 220, M 265, O 284
+
+
+
+## Target API level behavioral differences
+
+Most bionic bug fixes and improvements have been made without checks for
+the app's `targetSdkVersion`. As of O there were exactly two exceptions,
+but there are likely to be more in future because of Project Treble.
+
+### Invalid `pthread_t` handling (targetSdkVersion >= O)
+
+As part of a long-term goal to remove the global thread list,
+and in an attempt to flush out racy code, we changed how an invalid
+`pthread_t` is handled. For `pthread_detach`, `pthread_getcpuclockid`,
+`pthread_getschedparam`/`pthread_setschedparam`, `pthread_join`, and
+`pthread_kill`, instead of returning ESRCH when passed an invalid
+`pthread_t`, if you're targeting O or above, they'll abort with the
+message "attempt to use invalid pthread\_t".
+
+Note that this doesn't change behavior as much as you might think: the
+old lookup only held the global thread list lock for the duration of
+the lookup, so there was still a race between that and the dereference
+in the caller, given that callers actually need the tid to pass to some
+syscall or other, and sometimes update fields in the `pthread_internal_t`
+struct too.
+
+We can't check a thread's tid against 0 to see whether a `pthread_t`
+is still valid because a dead thread gets its thread struct unmapped
+along with its stack, so the dereference isn't safe.
+
+To fix your code, taking the affected functions one by one:
+
+  * `pthread_getcpuclockid` and `pthread_getschedparam`/`pthread_setschedparam`
+    should be fine. Unsafe calls to those seem highly unlikely.
+
+  * Unsafe `pthread_detach` callers probably want to switch to
+    `pthread_attr_setdetachstate` instead, or use
+    `pthread_detach(pthread_self());` from the new thread's start routine
+    rather than calling detach in the parent.
+
+  * `pthread_join` calls should be safe anyway, because a joinable thread
+    won't actually exit and unmap until it's joined. If you're joining an
+    unjoinable thread, the fix is to stop marking it detached. If you're
+    joining an already-joined thread, you need to rethink your design!
+
+  * Unsafe `pthread_kill` calls aren't portably fixable. (And are obviously
+    inherently non-portable as-is.) The best alternative on Android is to
+    use `pthread_gettid_np` at some point that you know the thread to be
+    alive, and then call `kill`/`tgkill` with signal 0 (which checks
+    whether a process exists rather than actually sending a
+    signal). That's still not completely safe because if you're too late
+    the tid may have been reused, but your code is inherently unsafe without
+    a redesign anyway.
+
+### Interruptable `sem_wait` (targetSdkVersion >= N)
+
+POSIX says that `sem_wait` can be interrupted by delivery of a
+signal. This wasn't historically true in Android, and when we fixed this
+bug we found that existing code relied on the old behavior. To preserve
+compatibility, `sem_wait` can only return EINTR on Android if the app
+targets N or later.
diff --git a/libc/Android.bp b/libc/Android.bp
index 52e53e2..1017fa5 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1420,8 +1420,8 @@
         },
     },
     product_variables: {
-        treble: {
-            cflags: ["-D__ANDROID_TREBLE__"],
+        treble_linker_namespaces: {
+            cflags: ["-DTREBLE_LINKER_NAMESPACES"],
         },
     },
     whole_static_libs: ["libpropertyinfoparser"],
diff --git a/libc/bionic/__bionic_get_shell_path.cpp b/libc/bionic/__bionic_get_shell_path.cpp
index 41162e9..1352815 100644
--- a/libc/bionic/__bionic_get_shell_path.cpp
+++ b/libc/bionic/__bionic_get_shell_path.cpp
@@ -40,7 +40,7 @@
    * in $PATH for the vendor shell, simply return the system shell.
    */
 
-#ifdef __ANDROID_TREBLE__
+#ifdef TREBLE_LINKER_NAMESPACES
   /* look for /system or /vendor prefix */
   char exe_path[strlen(VENDOR_PREFIX)];
   ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path));
diff --git a/libc/include/bits/epoll_event.h b/libc/include/bits/epoll_event.h
new file mode 100644
index 0000000..054323c
--- /dev/null
+++ b/libc/include/bits/epoll_event.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _BITS_EPOLL_EVENT_H_
+#define _BITS_EPOLL_EVENT_H_
+
+#include <sys/cdefs.h>
+#include <stdint.h>
+
+typedef union epoll_data {
+  void* ptr;
+  int fd;
+  uint32_t u32;
+  uint64_t u64;
+} epoll_data_t;
+
+struct epoll_event {
+  uint32_t events;
+  epoll_data_t data;
+}
+#ifdef __x86_64__
+__packed
+#endif
+;
+
+#endif
diff --git a/libc/include/bits/in_addr.h b/libc/include/bits/in_addr.h
new file mode 100644
index 0000000..834c056
--- /dev/null
+++ b/libc/include/bits/in_addr.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _BITS_IN_ADDR_H_
+#define _BITS_IN_ADDR_H_
+
+#include <sys/cdefs.h>
+#include <stdint.h>
+
+typedef uint32_t in_addr_t;
+
+struct in_addr {
+  in_addr_t s_addr;
+};
+
+#endif
diff --git a/libc/include/bits/ip_mreq_source.h b/libc/include/bits/ip_mreq_source.h
new file mode 100644
index 0000000..0eb8d68
--- /dev/null
+++ b/libc/include/bits/ip_mreq_source.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _BITS_IP_MREQ_SOURCE_H_
+#define _BITS_IP_MREQ_SOURCE_H_
+
+#include <sys/cdefs.h>
+#include <bits/in_addr.h>
+
+struct ip_mreq_source {
+  struct in_addr imr_multiaddr;
+  struct in_addr imr_interface;
+  struct in_addr imr_sourceaddr;
+};
+
+#endif
diff --git a/libc/include/bits/ip_msfilter.h b/libc/include/bits/ip_msfilter.h
new file mode 100644
index 0000000..23c127d
--- /dev/null
+++ b/libc/include/bits/ip_msfilter.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _BITS_IP_MSFILTER_H_
+#define _BITS_IP_MSFILTER_H_
+
+#include <sys/cdefs.h>
+#include <bits/in_addr.h>
+
+struct ip_msfilter {
+  struct in_addr imsf_multiaddr;
+  struct in_addr imsf_interface;
+  uint32_t imsf_fmode;
+  uint32_t imsf_numsrc;
+  struct in_addr imsf_slist[1];
+};
+
+#endif
diff --git a/libc/include/bits/termios_inlines.h b/libc/include/bits/termios_inlines.h
index d49167e..5f7cc42 100644
--- a/libc/include/bits/termios_inlines.h
+++ b/libc/include/bits/termios_inlines.h
@@ -42,6 +42,9 @@
 
 __BEGIN_DECLS
 
+// Supporting separate input and output speeds would require an ABI
+// change for `struct termios`.
+
 static __inline speed_t cfgetspeed(const struct termios* s) {
   return __BIONIC_CAST(static_cast, speed_t, s->c_cflag & CBAUD);
 }
@@ -60,10 +63,16 @@
   s->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
   s->c_cflag &= ~(CSIZE|PARENB);
   s->c_cflag |= CS8;
+  s->c_cc[VMIN] = 1;
+  s->c_cc[VTIME] = 0;
 }
 
 __BIONIC_TERMIOS_INLINE int cfsetspeed(struct termios* s, speed_t speed) {
-  // TODO: check 'speed' is valid.
+  // CBAUD is 0x100f, and every matching bit pattern has a Bxxx constant.
+  if ((speed & ~CBAUD) != 0) {
+    errno = EINVAL;
+    return -1;
+  }
   s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD);
   return 0;
 }
diff --git a/libc/include/bits/wait.h b/libc/include/bits/wait.h
new file mode 100644
index 0000000..a35f789
--- /dev/null
+++ b/libc/include/bits/wait.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _BITS_WAIT_H_
+#define _BITS_WAIT_H_
+
+#include <sys/cdefs.h>
+
+#include <linux/wait.h>
+
+#define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
+#define WCOREDUMP(s)   ((s) & 0x80)
+#define WTERMSIG(s)    ((s) & 0x7f)
+#define WSTOPSIG(s)    WEXITSTATUS(s)
+
+#define WIFEXITED(s)    (WTERMSIG(s) == 0)
+#define WIFSTOPPED(s)   (WTERMSIG(s) == 0x7f)
+#define WIFSIGNALED(s)  (WTERMSIG((s)+1) >= 2)
+#define WIFCONTINUED(s) ((s) == 0xffff)
+
+#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
+#define W_STOPCODE(sig)      ((sig) << 8 | 0x7f)
+
+#endif
diff --git a/libc/include/netinet/in.h b/libc/include/netinet/in.h
index 0ca8c82..1c9961c 100644
--- a/libc/include/netinet/in.h
+++ b/libc/include/netinet/in.h
@@ -43,7 +43,6 @@
 #define INET_ADDRSTRLEN 16
 
 typedef uint16_t in_port_t;
-typedef uint32_t in_addr_t;
 
 int bindresvport(int __fd, struct sockaddr_in* __sin);
 
@@ -57,4 +56,4 @@
 
 __END_DECLS
 
-#endif /* _NETINET_IN_H_ */
+#endif
diff --git a/libc/include/signal.h b/libc/include/signal.h
index ece2916..d9c9ee2 100644
--- a/libc/include/signal.h
+++ b/libc/include/signal.h
@@ -37,17 +37,13 @@
 #include <bits/timespec.h>
 #include <limits.h>
 
-#if defined(__LP64__) || defined(__mips__)
-/* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one,
- * so we need to expose our own and translate behind the scenes. */
-#  define sigaction __kernel_sigaction
-#  include <linux/signal.h>
-#  undef sigaction
-#else
-/* For 32-bit, we're stuck with the definitions we already shipped,
+/* For 64-bit (and mips), the kernel's struct sigaction doesn't match the
+ * POSIX one, so we need to expose our own and translate behind the scenes.
+ * For 32-bit, we're stuck with the definitions we already shipped,
  * even though they contain a sigset_t that's too small. */
-#  include <linux/signal.h>
-#endif
+#define sigaction __kernel_sigaction
+#include <linux/signal.h>
+#undef sigaction
 
 #include <sys/ucontext.h>
 #define __BIONIC_HAVE_UCONTEXT_T
@@ -87,7 +83,7 @@
 #if defined(__LP64__)
 
 struct sigaction {
-  unsigned int sa_flags;
+  int sa_flags;
   union {
     sighandler_t sa_handler;
     void (*sa_sigaction)(int, struct siginfo*, void*);
@@ -99,7 +95,7 @@
 #elif defined(__mips__)
 
 struct sigaction {
-  unsigned int sa_flags;
+  int sa_flags;
   union {
     sighandler_t sa_handler;
     void (*sa_sigaction) (int, struct siginfo*, void*);
@@ -107,6 +103,18 @@
   sigset_t sa_mask;
 };
 
+#else
+
+struct sigaction {
+  union {
+    sighandler_t _sa_handler;
+    void (*_sa_sigaction)(int, struct siginfo*, void*);
+  } _u;
+  sigset_t sa_mask;
+  int sa_flags;
+  void (*sa_restorer)(void);
+};
+
 #endif
 
 int sigaction(int __signal, const struct sigaction* __new_action, struct sigaction* __old_action);
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index cf0dea8..1ae3c6e 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -29,12 +29,12 @@
 #ifndef _STDLIB_H
 #define _STDLIB_H
 
-#include <sys/cdefs.h>
-#include <xlocale.h>
-
 #include <alloca.h>
+#include <bits/wait.h>
 #include <malloc.h>
 #include <stddef.h>
+#include <sys/cdefs.h>
+#include <xlocale.h>
 
 __BEGIN_DECLS
 
diff --git a/libc/include/sys/epoll.h b/libc/include/sys/epoll.h
index 6ecd93f..2bc16f5 100644
--- a/libc/include/sys/epoll.h
+++ b/libc/include/sys/epoll.h
@@ -37,22 +37,6 @@
 
 __BEGIN_DECLS
 
-typedef union epoll_data {
-  void* ptr;
-  int fd;
-  uint32_t u32;
-  uint64_t u64;
-} epoll_data_t;
-
-struct epoll_event {
-  uint32_t events;
-  epoll_data_t data;
-}
-#ifdef __x86_64__
-__packed
-#endif
-;
-
 int epoll_create(int __size);
 int epoll_create1(int __flags) __INTRODUCED_IN(21);
 
diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h
index ed851a2..152f39d 100644
--- a/libc/include/sys/socket.h
+++ b/libc/include/sys/socket.h
@@ -44,8 +44,6 @@
 
 __BEGIN_DECLS
 
-#define sockaddr_storage __kernel_sockaddr_storage
-
 struct timespec;
 
 #ifdef __mips__
diff --git a/libc/include/sys/wait.h b/libc/include/sys/wait.h
index e259e31..106946b 100644
--- a/libc/include/sys/wait.h
+++ b/libc/include/sys/wait.h
@@ -29,6 +29,7 @@
 #ifndef _SYS_WAIT_H_
 #define _SYS_WAIT_H_
 
+#include <bits/wait.h>
 #include <sys/cdefs.h>
 #include <sys/types.h>
 #include <sys/resource.h>
@@ -37,19 +38,6 @@
 
 __BEGIN_DECLS
 
-#define WEXITSTATUS(s)  (((s) & 0xff00) >> 8)
-#define WCOREDUMP(s)    ((s) & 0x80)
-#define WTERMSIG(s)     ((s) & 0x7f)
-#define WSTOPSIG(s)     WEXITSTATUS(s)
-
-#define WIFEXITED(s)    (WTERMSIG(s) == 0)
-#define WIFSTOPPED(s)   (WTERMSIG(s) == 0x7f)
-#define WIFSIGNALED(s)  (WTERMSIG((s)+1) >= 2)
-#define WIFCONTINUED(s) ((s) == 0xffff)
-
-#define W_EXITCODE(ret, sig)    ((ret) << 8 | (sig))
-#define W_STOPCODE(sig)         ((sig) << 8 | 0x7f)
-
 pid_t wait(int* __status);
 pid_t waitpid(pid_t __pid, int* __status, int __options);
 #if __ANDROID_API__ >= __ANDROID_API_J_MR2__
diff --git a/libc/kernel/tools/clean_header.py b/libc/kernel/tools/clean_header.py
index d63ea03..7c802c2 100755
--- a/libc/kernel/tools/clean_header.py
+++ b/libc/kernel/tools/clean_header.py
@@ -94,11 +94,9 @@
 
     # Extract the architecture if found.
     arch = None
-    statics = kernel_known_generic_statics
     m = re.search(r"(^|/)asm-([\w\d_\+\.\-]+)/.*", rel_path)
     if m and m.group(2) != 'generic':
         arch = m.group(2)
-        statics = statics.union(kernel_known_statics.get(arch, set()))
 
     # Now, let's parse the file.
     parser = cpp.BlockParser()
@@ -116,9 +114,8 @@
 
     blocks.optimizeMacros(macros)
     blocks.optimizeIf01()
-    blocks.removeVarsAndFuncs(statics)
+    blocks.removeVarsAndFuncs(kernel_known_generic_statics)
     blocks.replaceTokens(kernel_token_replacements)
-    blocks.removeMacroDefines(kernel_ignored_macros)
 
     out = StringOutput()
     out.write(kernel_disclaimer)
diff --git a/libc/kernel/tools/cpp.py b/libc/kernel/tools/cpp.py
index 68144cd..2400f5d 100644
--- a/libc/kernel/tools/cpp.py
+++ b/libc/kernel/tools/cpp.py
@@ -31,6 +31,7 @@
 
 from defaults import kCppUndefinedMacro
 from defaults import kernel_remove_config_macros
+from defaults import kernel_struct_replacements
 from defaults import kernel_token_replacements
 
 
@@ -1215,10 +1216,6 @@
             if b.isIf():
                 b.expr.optimize(macros)
 
-    def removeMacroDefines(self, macros):
-        """Remove known macro definitions from a BlockList."""
-        self.blocks = remove_macro_defines(self.blocks, macros)
-
     def optimizeAll(self, macros):
         self.optimizeMacros(macros)
         self.optimizeIf01()
@@ -1238,7 +1235,7 @@
         for b in self.blocks:
             indent = b.write(out, indent)
 
-    def removeVarsAndFuncs(self, knownStatics=None):
+    def removeVarsAndFuncs(self, keep):
         """Remove variable and function declarations.
 
         All extern and static declarations corresponding to variable and
@@ -1246,7 +1243,7 @@
         enum/structs/union declarations.
 
         However, we keep the definitions corresponding to the set of known
-        static inline functions in the set 'knownStatics', which is useful
+        static inline functions in the set 'keep', which is useful
         for optimized byteorder swap functions and stuff like that.
         """
 
@@ -1262,8 +1259,6 @@
         # state = 2 => var declaration encountered, ends with ";"
         # state = 3 => func declaration encountered, ends with "}"
 
-        if knownStatics is None:
-            knownStatics = set()
         state = 0
         depth = 0
         blocks2 = []
@@ -1319,9 +1314,9 @@
                     # its name.
                     #
                     # We're going to parse the next tokens of the same block
-                    # until we find a semi-column or a left parenthesis.
+                    # until we find a semicolon or a left parenthesis.
                     #
-                    # The semi-column corresponds to a variable definition,
+                    # The semicolon corresponds to a variable definition,
                     # the left-parenthesis to a function definition.
                     #
                     # We also assume that the var/func name is the last
@@ -1355,7 +1350,7 @@
                                       ident)
                         break
 
-                    if ident in knownStatics:
+                    if ident in keep:
                         logging.debug("### keep var/func '%s': %s", ident,
                                       repr(b.tokens[i:j]))
                     else:
@@ -1370,21 +1365,42 @@
                     i += 1
 
                 if i > first:
-                    # print "### final '%s'" % repr(b.tokens[first:i])
+                    #print "### final '%s'" % repr(b.tokens[first:i])
                     blocks2.append(Block(b.tokens[first:i]))
 
         self.blocks = blocks2
 
     def replaceTokens(self, replacements):
         """Replace tokens according to the given dict."""
+        extra_includes = []
         for b in self.blocks:
             made_change = False
             if b.isInclude() is None:
-                for tok in b.tokens:
+                i = 0
+                while i < len(b.tokens):
+                    tok = b.tokens[i]
+                    if (tok.kind == TokenKind.KEYWORD and tok.id == 'struct'
+                        and (i + 2) < len(b.tokens) and b.tokens[i + 2].id == '{'):
+                        struct_name = b.tokens[i + 1].id
+                        if struct_name in kernel_struct_replacements:
+                            extra_includes.append("<bits/%s.h>" % struct_name)
+                            end = i + 2
+                            while end < len(b.tokens) and b.tokens[end].id != '}':
+                                end += 1
+                            end += 1 # Swallow '}'
+                            while end < len(b.tokens) and b.tokens[end].id != ';':
+                                end += 1
+                            end += 1 # Swallow ';'
+                            # Remove these tokens. We'll replace them later with a #include block.
+                            b.tokens[i:end] = []
+                            made_change = True
+                            # We've just modified b.tokens, so revisit the current offset.
+                            continue
                     if tok.kind == TokenKind.IDENTIFIER:
                         if tok.id in replacements:
                             tok.id = replacements[tok.id]
                             made_change = True
+                    i += 1
 
                 if b.isDefine() and b.define_id in replacements:
                     b.define_id = replacements[b.define_id]
@@ -1394,6 +1410,11 @@
                 # Keep 'expr' in sync with 'tokens'.
                 b.expr = CppExpr(b.tokens)
 
+        for extra_include in extra_includes:
+            replacement = CppStringTokenizer(extra_include)
+            self.blocks.insert(2, Block(replacement.tokens, directive='include'))
+
+
 
 def strip_space(s):
     """Strip out redundant space in a given string."""
@@ -1620,19 +1641,6 @@
 ################################################################################
 
 
-def remove_macro_defines(blocks, excludedMacros=None):
-    """Remove macro definitions like #define <macroName>  ...."""
-    if excludedMacros is None:
-        excludedMacros = set()
-    result = []
-    for b in blocks:
-        macroName = b.isDefine()
-        if macroName is None or macroName not in excludedMacros:
-            result.append(b)
-
-    return result
-
-
 def find_matching_endif(blocks, i):
     """Traverse the blocks to find out the matching #endif."""
     n = len(blocks)
diff --git a/libc/kernel/tools/defaults.py b/libc/kernel/tools/defaults.py
index 1afdc77..967d0c7 100644
--- a/libc/kernel/tools/defaults.py
+++ b/libc/kernel/tools/defaults.py
@@ -78,34 +78,27 @@
     "SIGRTMAX": "__SIGRTMAX",
     # We want to support both BSD and Linux member names in struct udphdr.
     "udphdr": "__kernel_udphdr",
-    # The kernel's struct epoll_event just has __u64 for the data.
-    "epoll_event": "__kernel_uapi_epoll_event",
     # This causes problems when trying to export the headers for the ndk.
     "__attribute_const__": "__attribute__((__const__))",
+    # In this case the kernel tries to keep out of our way, but we're happy to use its definition.
+    "__kernel_sockaddr_storage": "sockaddr_storage",
     }
 
+
+# This is the set of struct definitions that we want to replace with
+# a #include of <bits/struct.h> instead.
+kernel_struct_replacements = set(
+        [
+          "epoll_event",
+          "in_addr",
+          "ip_mreq_source",
+          "ip_msfilter",
+        ]
+    )
+
+
 # This is the set of known static inline functions that we want to keep
 # in the final kernel headers.
-kernel_known_arm_statics = set(
-        [
-        ]
-    )
-
-kernel_known_arm64_statics = set(
-        [
-        ]
-    )
-
-kernel_known_mips_statics = set(
-        [
-        ]
-    )
-
-kernel_known_x86_statics = set(
-        [
-        ]
-    )
-
 kernel_known_generic_statics = set(
         [
           "ipt_get_target",  # uapi/linux/netfilter_ipv4/ip_tables.h
@@ -133,25 +126,6 @@
         ]
     )
 
-# this maps an architecture to the set of static inline functions that
-# we want to keep in the final headers
-#
-kernel_known_statics = {
-        "arm" : kernel_known_arm_statics,
-        "arm64" : kernel_known_arm64_statics,
-        "mips" : kernel_known_mips_statics,
-        "x86" : kernel_known_x86_statics,
-    }
-
-# this is a list of macros which we want to specifically exclude from
-# the generated files.
-#
-kernel_ignored_macros = set(
-        [
-
-        ]
-    )
-
 # this is the standard disclaimer
 #
 kernel_disclaimer = """\
diff --git a/libc/kernel/uapi/linux/eventpoll.h b/libc/kernel/uapi/linux/eventpoll.h
index d0a5f6e..eec1077 100644
--- a/libc/kernel/uapi/linux/eventpoll.h
+++ b/libc/kernel/uapi/linux/eventpoll.h
@@ -18,6 +18,7 @@
  ****************************************************************************/
 #ifndef _UAPI_LINUX_EVENTPOLL_H
 #define _UAPI_LINUX_EVENTPOLL_H
+#include <bits/epoll_event.h>
 #include <linux/fcntl.h>
 #include <linux/types.h>
 #define EPOLL_CLOEXEC O_CLOEXEC
@@ -44,8 +45,4 @@
 #else
 #define EPOLL_PACKED
 #endif
-struct __kernel_uapi_epoll_event {
-  __u32 events;
-  __u64 data;
-} EPOLL_PACKED;
 #endif
diff --git a/libc/kernel/uapi/linux/if.h b/libc/kernel/uapi/linux/if.h
index d815ef8..15de690 100644
--- a/libc/kernel/uapi/linux/if.h
+++ b/libc/kernel/uapi/linux/if.h
@@ -31,10 +31,27 @@
 #if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 || __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0
 enum net_device_flags {
 #if __UAPI_DEF_IF_NET_DEVICE_FLAGS
-  IFF_UP = 1 << 0, IFF_BROADCAST = 1 << 1, IFF_DEBUG = 1 << 2, IFF_LOOPBACK = 1 << 3, IFF_POINTOPOINT = 1 << 4, IFF_NOTRAILERS = 1 << 5, IFF_RUNNING = 1 << 6, IFF_NOARP = 1 << 7, IFF_PROMISC = 1 << 8, IFF_ALLMULTI = 1 << 9, IFF_MASTER = 1 << 10, IFF_SLAVE = 1 << 11, IFF_MULTICAST = 1 << 12, IFF_PORTSEL = 1 << 13, IFF_AUTOMEDIA = 1 << 14, IFF_DYNAMIC = 1 << 15,
+  IFF_UP = 1 << 0,
+  IFF_BROADCAST = 1 << 1,
+  IFF_DEBUG = 1 << 2,
+  IFF_LOOPBACK = 1 << 3,
+  IFF_POINTOPOINT = 1 << 4,
+  IFF_NOTRAILERS = 1 << 5,
+  IFF_RUNNING = 1 << 6,
+  IFF_NOARP = 1 << 7,
+  IFF_PROMISC = 1 << 8,
+  IFF_ALLMULTI = 1 << 9,
+  IFF_MASTER = 1 << 10,
+  IFF_SLAVE = 1 << 11,
+  IFF_MULTICAST = 1 << 12,
+  IFF_PORTSEL = 1 << 13,
+  IFF_AUTOMEDIA = 1 << 14,
+  IFF_DYNAMIC = 1 << 15,
 #endif
 #if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
-  IFF_LOWER_UP = 1 << 16, IFF_DORMANT = 1 << 17, IFF_ECHO = 1 << 18,
+  IFF_LOWER_UP = 1 << 16,
+  IFF_DORMANT = 1 << 17,
+  IFF_ECHO = 1 << 18,
 #endif
 };
 #endif
diff --git a/libc/kernel/uapi/linux/in.h b/libc/kernel/uapi/linux/in.h
index 351126a..788a6d9 100644
--- a/libc/kernel/uapi/linux/in.h
+++ b/libc/kernel/uapi/linux/in.h
@@ -18,6 +18,9 @@
  ****************************************************************************/
 #ifndef _UAPI_LINUX_IN_H
 #define _UAPI_LINUX_IN_H
+#include <bits/ip_msfilter.h>
+#include <bits/ip_mreq_source.h>
+#include <bits/in_addr.h>
 #include <linux/types.h>
 #include <linux/libc-compat.h>
 #include <linux/socket.h>
@@ -77,9 +80,6 @@
 };
 #endif
 #if __UAPI_DEF_IN_ADDR
-struct in_addr {
-  __be32 s_addr;
-};
 #endif
 #define IP_TOS 1
 #define IP_TTL 2
@@ -147,36 +147,24 @@
   struct in_addr imr_address;
   int imr_ifindex;
 };
-struct ip_mreq_source {
-  __be32 imr_multiaddr;
-  __be32 imr_interface;
-  __be32 imr_sourceaddr;
-};
-struct ip_msfilter {
-  __be32 imsf_multiaddr;
-  __be32 imsf_interface;
-  __u32 imsf_fmode;
-  __u32 imsf_numsrc;
-  __be32 imsf_slist[1];
-};
 #define IP_MSFILTER_SIZE(numsrc) (sizeof(struct ip_msfilter) - sizeof(__u32) + (numsrc) * sizeof(__u32))
 struct group_req {
   __u32 gr_interface;
-  struct __kernel_sockaddr_storage gr_group;
+  struct sockaddr_storage gr_group;
 };
 struct group_source_req {
   __u32 gsr_interface;
-  struct __kernel_sockaddr_storage gsr_group;
-  struct __kernel_sockaddr_storage gsr_source;
+  struct sockaddr_storage gsr_group;
+  struct sockaddr_storage gsr_source;
 };
 struct group_filter {
   __u32 gf_interface;
-  struct __kernel_sockaddr_storage gf_group;
+  struct sockaddr_storage gf_group;
   __u32 gf_fmode;
   __u32 gf_numsrc;
-  struct __kernel_sockaddr_storage gf_slist[1];
+  struct sockaddr_storage gf_slist[1];
 };
-#define GROUP_FILTER_SIZE(numsrc) (sizeof(struct group_filter) - sizeof(struct __kernel_sockaddr_storage) + (numsrc) * sizeof(struct __kernel_sockaddr_storage))
+#define GROUP_FILTER_SIZE(numsrc) (sizeof(struct group_filter) - sizeof(struct sockaddr_storage) + (numsrc) * sizeof(struct sockaddr_storage))
 #endif
 #if __UAPI_DEF_IN_PKTINFO
 struct in_pktinfo {
diff --git a/libc/kernel/uapi/linux/rds.h b/libc/kernel/uapi/linux/rds.h
index ccb3f54..cfb0a3b 100644
--- a/libc/kernel/uapi/linux/rds.h
+++ b/libc/kernel/uapi/linux/rds.h
@@ -145,7 +145,7 @@
   __u64 flags;
 };
 struct rds_get_mr_for_dest_args {
-  struct __kernel_sockaddr_storage dest_addr;
+  struct sockaddr_storage dest_addr;
   struct rds_iovec vec;
   __u64 cookie_addr;
   __u64 flags;
diff --git a/libc/kernel/uapi/linux/socket.h b/libc/kernel/uapi/linux/socket.h
index 371ba30..4f52bcb 100644
--- a/libc/kernel/uapi/linux/socket.h
+++ b/libc/kernel/uapi/linux/socket.h
@@ -21,7 +21,7 @@
 #define _K_SS_MAXSIZE 128
 #define _K_SS_ALIGNSIZE (__alignof__(struct sockaddr *))
 typedef unsigned short __kernel_sa_family_t;
-struct __kernel_sockaddr_storage {
+struct sockaddr_storage {
   __kernel_sa_family_t ss_family;
   char __data[_K_SS_MAXSIZE - sizeof(unsigned short)];
 } __attribute__((aligned(_K_SS_ALIGNSIZE)));
diff --git a/libc/kernel/uapi/linux/tcp.h b/libc/kernel/uapi/linux/tcp.h
index f5134d6..13354e6 100644
--- a/libc/kernel/uapi/linux/tcp.h
+++ b/libc/kernel/uapi/linux/tcp.h
@@ -188,7 +188,7 @@
 #define TCP_MD5SIG_MAXKEYLEN 80
 #define TCP_MD5SIG_FLAG_PREFIX 1
 struct tcp_md5sig {
-  struct __kernel_sockaddr_storage tcpm_addr;
+  struct sockaddr_storage tcpm_addr;
   __u8 tcpm_flags;
   __u8 tcpm_prefixlen;
   __u16 tcpm_keylen;
diff --git a/libc/kernel/uapi/rdma/rdma_user_cm.h b/libc/kernel/uapi/rdma/rdma_user_cm.h
index 81d963b..24e0f2e 100644
--- a/libc/kernel/uapi/rdma/rdma_user_cm.h
+++ b/libc/kernel/uapi/rdma/rdma_user_cm.h
@@ -82,7 +82,7 @@
   __u32 id;
   __u16 addr_size;
   __u16 reserved;
-  struct __kernel_sockaddr_storage addr;
+  struct sockaddr_storage addr;
 };
 struct rdma_ucm_resolve_ip {
   struct sockaddr_in6 src_addr;
@@ -96,8 +96,8 @@
   __u16 src_size;
   __u16 dst_size;
   __u32 reserved;
-  struct __kernel_sockaddr_storage src_addr;
-  struct __kernel_sockaddr_storage dst_addr;
+  struct sockaddr_storage src_addr;
+  struct sockaddr_storage dst_addr;
 };
 struct rdma_ucm_resolve_route {
   __u32 id;
@@ -129,8 +129,8 @@
   __u16 pkey;
   __u16 src_size;
   __u16 dst_size;
-  struct __kernel_sockaddr_storage src_addr;
-  struct __kernel_sockaddr_storage dst_addr;
+  struct sockaddr_storage src_addr;
+  struct sockaddr_storage dst_addr;
 };
 struct rdma_ucm_query_path_resp {
   __u32 num_paths;
@@ -208,7 +208,7 @@
   __u32 id;
   __u16 addr_size;
   __u16 join_flags;
-  struct __kernel_sockaddr_storage addr;
+  struct sockaddr_storage addr;
 };
 struct rdma_ucm_get_event {
   __u64 response;
diff --git a/libc/stdio/vfscanf.c b/libc/stdio/vfscanf.c
index 887b435..c9e4385 100644
--- a/libc/stdio/vfscanf.c
+++ b/libc/stdio/vfscanf.c
@@ -324,10 +324,7 @@
         /* scan arbitrary characters (sets NOSKIP) */
         if (width == 0) width = 1;
         if (flags & LONG) {
-          if ((flags & SUPPRESS) == 0)
-            wcp = va_arg(ap, wchar_t*);
-          else
-            wcp = NULL;
+          wcp = ((flags & SUPPRESS) == 0) ? va_arg(ap, wchar_t*) : NULL;
           n = 0;
           while (width != 0) {
             if (n == (int)MB_CUR_MAX) {
@@ -388,20 +385,17 @@
         break;
 
       case CT_CCL:
-        /* scan a (nonempty) character class (sets NOSKIP) */
-        if (width == 0) width = (size_t)~0; /* `infinity' */
-        /* take only those things in the class */
+      case CT_STRING:
+        // CT_CCL: scan a (nonempty) character class (sets NOSKIP).
+        // CT_STRING: like CCL, but zero-length string OK, & no NOSKIP.
+        if (width == 0) width = (size_t)~0; // 'infinity'.
         if (flags & LONG) {
           wchar_t twc;
-          int nchars;
+          int nchars = 0;
 
-          if ((flags & SUPPRESS) == 0)
-            wcp = va_arg(ap, wchar_t*);
-          else
-            wcp = &twc;
+          wcp = (flags & SUPPRESS) == 0 ? va_arg(ap, wchar_t*) : &twc;
           n = 0;
-          nchars = 0;
-          while (width != 0) {
+          while ((c == CT_CCL || !isspace(*fp->_p)) && width != 0) {
             if (n == (int)MB_CUR_MAX) {
               fp->_flags |= __SERR;
               goto input_failure;
@@ -417,7 +411,7 @@
             }
             if (nconv == 0) *wcp = L'\0';
             if (nconv != (size_t)-2) {
-              if (wctob(*wcp) != EOF && !ccltab[wctob(*wcp)]) {
+              if ((c == CT_CCL && wctob(*wcp) != EOF && !ccltab[wctob(*wcp)]) || (c == CT_STRING && iswspace(*wcp))) {
                 while (n != 0) {
                   n--;
                   ungetc(buf[n], fp);
@@ -438,121 +432,46 @@
               break;
             }
           }
-          if (n != 0) {
+          if (c == CT_CCL && n != 0) {
             fp->_flags |= __SERR;
             goto input_failure;
           }
           n = nchars;
-          if (n == 0) goto match_failure;
-          if (!(flags & SUPPRESS)) {
-            *wcp = L'\0';
-            nassigned++;
-          }
-        } else
-            /* take only those things in the class */
-            if (flags & SUPPRESS) {
+        } else if (flags & SUPPRESS) {
           n = 0;
-          while (ccltab[*fp->_p]) {
+          while ((c == CT_CCL && ccltab[*fp->_p]) || (c == CT_STRING && !isspace(*fp->_p))) {
             n++, fp->_r--, fp->_p++;
             if (--width == 0) break;
             if (fp->_r <= 0 && __srefill(fp)) {
-              if (n == 0) goto input_failure;
+              if (c == CT_CCL && n == 0) goto input_failure;
               break;
             }
           }
-          if (n == 0) goto match_failure;
         } else {
           p0 = p = va_arg(ap, char*);
-          while (ccltab[*fp->_p]) {
+          while ((c == CT_CCL && ccltab[*fp->_p]) || (c == CT_STRING && !isspace(*fp->_p))) {
             fp->_r--;
             *p++ = *fp->_p++;
             if (--width == 0) break;
             if (fp->_r <= 0 && __srefill(fp)) {
-              if (p == p0) goto input_failure;
+              if (c == CT_CCL && p == p0) goto input_failure;
               break;
             }
           }
           n = p - p0;
-          if (n == 0) goto match_failure;
-          *p = '\0';
-          nassigned++;
+        }
+        if (c == CT_CCL && n == 0) goto match_failure;
+        if (!(flags & SUPPRESS)) {
+          if (flags & LONG) {
+            *wcp = L'\0';
+          } else {
+            *p = '\0';
+          }
+          ++nassigned;
         }
         nread += n;
         break;
 
-      case CT_STRING:
-        /* like CCL, but zero-length string OK, & no NOSKIP */
-        if (width == 0) width = (size_t)~0;
-        if (flags & LONG) {
-          wchar_t twc;
-
-          if ((flags & SUPPRESS) == 0)
-            wcp = va_arg(ap, wchar_t*);
-          else
-            wcp = &twc;
-          n = 0;
-          while (!isspace(*fp->_p) && width != 0) {
-            if (n == (int)MB_CUR_MAX) {
-              fp->_flags |= __SERR;
-              goto input_failure;
-            }
-            buf[n++] = *fp->_p;
-            fp->_p++;
-            fp->_r--;
-            memset(&mbs, 0, sizeof(mbs));
-            nconv = mbrtowc(wcp, buf, n, &mbs);
-            if (nconv == (size_t)-1) {
-              fp->_flags |= __SERR;
-              goto input_failure;
-            }
-            if (nconv == 0) *wcp = L'\0';
-            if (nconv != (size_t)-2) {
-              if (iswspace(*wcp)) {
-                while (n != 0) {
-                  n--;
-                  ungetc(buf[n], fp);
-                }
-                break;
-              }
-              nread += n;
-              width--;
-              if (!(flags & SUPPRESS)) wcp++;
-              n = 0;
-            }
-            if (fp->_r <= 0 && __srefill(fp)) {
-              if (n != 0) {
-                fp->_flags |= __SERR;
-                goto input_failure;
-              }
-              break;
-            }
-          }
-          if (!(flags & SUPPRESS)) {
-            *wcp = L'\0';
-            nassigned++;
-          }
-        } else if (flags & SUPPRESS) {
-          n = 0;
-          while (!isspace(*fp->_p)) {
-            n++, fp->_r--, fp->_p++;
-            if (--width == 0) break;
-            if (fp->_r <= 0 && __srefill(fp)) break;
-          }
-          nread += n;
-        } else {
-          p0 = p = va_arg(ap, char*);
-          while (!isspace(*fp->_p)) {
-            fp->_r--;
-            *p++ = *fp->_p++;
-            if (--width == 0) break;
-            if (fp->_r <= 0 && __srefill(fp)) break;
-          }
-          *p = '\0';
-          nread += p - p0;
-          nassigned++;
-        }
-        continue;
-
       case CT_INT:
         /* scan an integer as if by strtoimax/strtoumax */
 #ifdef hardway
diff --git a/libc/stdio/vfwscanf.c b/libc/stdio/vfwscanf.c
index 1030a62..71cd49b 100644
--- a/libc/stdio/vfwscanf.c
+++ b/libc/stdio/vfwscanf.c
@@ -182,7 +182,7 @@
         if ((wi = __fgetwc_unlock(fp)) == WEOF) goto input_failure;
         if (wi != c) {
           __ungetwc(wi, fp);
-          goto input_failure;
+          goto match_failure;
         }
         nread++;
         continue;
@@ -402,28 +402,26 @@
         break;
 
       case CT_CCL:
-        /* scan a (nonempty) character class (sets NOSKIP) */
-        if (width == 0) width = (size_t)~0; /* `infinity' */
-        /* take only those things in the class */
+      case CT_STRING:
+        // CT_CCL: scan a (nonempty) character class (sets NOSKIP).
+        // CT_STRING: like CCL, but zero-length string OK, & no NOSKIP.
+        if (width == 0) width = (size_t)~0; // 'infinity'.
         if ((flags & SUPPRESS) && (flags & LONG)) {
           n = 0;
-          while ((wi = __fgetwc_unlock(fp)) != WEOF && width-- != 0 && in_ccl(wi, ccl)) n++;
+          while ((wi = __fgetwc_unlock(fp)) != WEOF && width-- != 0 && ((c == CT_CCL && in_ccl(wi, ccl)) || (c == CT_STRING && !iswspace(wi)))) n++;
           if (wi != WEOF) __ungetwc(wi, fp);
-          if (n == 0) goto match_failure;
         } else if (flags & LONG) {
           p0 = p = va_arg(ap, wchar_t*);
-          while ((wi = __fgetwc_unlock(fp)) != WEOF && width-- != 0 && in_ccl(wi, ccl))
+          while ((wi = __fgetwc_unlock(fp)) != WEOF && width-- != 0 && ((c == CT_CCL && in_ccl(wi, ccl)) || (c == CT_STRING && !iswspace(wi)))) {
             *p++ = (wchar_t)wi;
+          }
           if (wi != WEOF) __ungetwc(wi, fp);
           n = p - p0;
-          if (n == 0) goto match_failure;
-          *p = 0;
-          nassigned++;
         } else {
           if (!(flags & SUPPRESS)) mbp = va_arg(ap, char*);
           n = 0;
           memset(&mbs, 0, sizeof(mbs));
-          while ((wi = __fgetwc_unlock(fp)) != WEOF && width != 0 && in_ccl(wi, ccl)) {
+          while ((wi = __fgetwc_unlock(fp)) != WEOF && width != 0 && ((c == CT_CCL && in_ccl(wi, ccl)) || (c == CT_STRING && !iswspace(wi)))) {
             if (width >= MB_CUR_MAX && !(flags & SUPPRESS)) {
               nconv = wcrtomb(mbp, wi, &mbs);
               if (nconv == (size_t)-1) goto input_failure;
@@ -438,57 +436,20 @@
             n++;
           }
           if (wi != WEOF) __ungetwc(wi, fp);
-          if (n == 0) goto match_failure;
-          if (!(flags & SUPPRESS)) {
-            *mbp = 0;
-            nassigned++;
+        }
+        if (c == CT_CCL && n == 0) goto match_failure;
+        if (!(flags & SUPPRESS)) {
+          if (flags & LONG) {
+            *p = L'\0';
+          } else {
+            *mbp = '\0';
           }
+          ++nassigned;
         }
         nread += n;
         nconversions++;
         break;
 
-      case CT_STRING:
-        /* like CCL, but zero-length string OK, & no NOSKIP */
-        if (width == 0) width = (size_t)~0;
-        if ((flags & SUPPRESS) && (flags & LONG)) {
-          while ((wi = __fgetwc_unlock(fp)) != WEOF && width-- != 0 && !iswspace(wi)) nread++;
-          if (wi != WEOF) __ungetwc(wi, fp);
-        } else if (flags & LONG) {
-          p0 = p = va_arg(ap, wchar_t*);
-          while ((wi = __fgetwc_unlock(fp)) != WEOF && width-- != 0 && !iswspace(wi)) {
-            *p++ = (wchar_t)wi;
-            nread++;
-          }
-          if (wi != WEOF) __ungetwc(wi, fp);
-          *p = 0;
-          nassigned++;
-        } else {
-          if (!(flags & SUPPRESS)) mbp = va_arg(ap, char*);
-          memset(&mbs, 0, sizeof(mbs));
-          while ((wi = __fgetwc_unlock(fp)) != WEOF && width != 0 && !iswspace(wi)) {
-            if (width >= MB_CUR_MAX && !(flags & SUPPRESS)) {
-              nconv = wcrtomb(mbp, wi, &mbs);
-              if (nconv == (size_t)-1) goto input_failure;
-            } else {
-              nconv = wcrtomb(mbbuf, wi, &mbs);
-              if (nconv == (size_t)-1) goto input_failure;
-              if (nconv > width) break;
-              if (!(flags & SUPPRESS)) memcpy(mbp, mbbuf, nconv);
-            }
-            if (!(flags & SUPPRESS)) mbp += nconv;
-            width -= nconv;
-            nread++;
-          }
-          if (wi != WEOF) __ungetwc(wi, fp);
-          if (!(flags & SUPPRESS)) {
-            *mbp = 0;
-            nassigned++;
-          }
-        }
-        nconversions++;
-        continue;
-
       case CT_INT:
         /* scan an integer as if by strtoimax/strtoumax */
         if (width == 0 || width > sizeof(buf) / sizeof(*buf) - 1)
diff --git a/libc/system_properties/prop_area.cpp b/libc/system_properties/prop_area.cpp
index e11f292..032fa4e 100644
--- a/libc/system_properties/prop_area.cpp
+++ b/libc/system_properties/prop_area.cpp
@@ -26,6 +26,7 @@
  * SUCH DAMAGE.
  */
 
+#include <errno.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <sys/cdefs.h>
diff --git a/tests/Android.bp b/tests/Android.bp
index 28df084..51a721a 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -155,6 +155,7 @@
         "sys_xattr_test.cpp",
         "system_properties_test.cpp",
         "system_properties_test2.cpp",
+        "termios_test.cpp",
         "tgmath_test.c",
         "time_test.cpp",
         "uchar_test.cpp",
@@ -645,4 +646,4 @@
     },
 }
 
-subdirs = ["libs"]
+subdirs = ["*"]
diff --git a/tests/ctype_test.cpp b/tests/ctype_test.cpp
index 7b27d64..c12518b 100644
--- a/tests/ctype_test.cpp
+++ b/tests/ctype_test.cpp
@@ -26,6 +26,14 @@
   EXPECT_FALSE(isalnum(' '));
 }
 
+TEST(ctype, isalnum_l) {
+  EXPECT_TRUE(isalnum_l('1', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isalnum_l('a', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isalnum_l('A', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isalnum_l('!', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isalnum_l(' ', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, isalpha) {
   EXPECT_FALSE(isalpha('1'));
   EXPECT_TRUE(isalpha('a'));
@@ -34,6 +42,14 @@
   EXPECT_FALSE(isalpha(' '));
 }
 
+TEST(ctype, isalpha_l) {
+  EXPECT_FALSE(isalpha_l('1', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isalpha_l('a', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isalpha_l('A', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isalpha_l('!', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isalpha_l(' ', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, isascii) {
   EXPECT_TRUE(isascii('\x7f'));
   EXPECT_FALSE(isascii('\x80'));
@@ -45,17 +61,34 @@
   EXPECT_TRUE(isblank('\t'));
 }
 
+TEST(ctype, isblank_l) {
+  EXPECT_FALSE(isblank_l('1', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isblank_l(' ', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isblank_l('\t', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, iscntrl) {
   EXPECT_FALSE(iscntrl('1'));
   EXPECT_TRUE(iscntrl('\b'));
 }
 
+TEST(ctype, iscntrl_l) {
+  EXPECT_FALSE(iscntrl_l('1', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(iscntrl_l('\b', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, isdigit) {
   EXPECT_TRUE(isdigit('1'));
   EXPECT_FALSE(isdigit('a'));
   EXPECT_FALSE(isdigit('x'));
 }
 
+TEST(ctype, isdigit_l) {
+  EXPECT_TRUE(isdigit_l('1', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isdigit_l('a', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isdigit_l('x', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, isgraph) {
   EXPECT_TRUE(isgraph('a'));
   EXPECT_TRUE(isgraph('A'));
@@ -64,18 +97,38 @@
   EXPECT_FALSE(isgraph(' '));
 }
 
+TEST(ctype, isgraph_l) {
+  EXPECT_TRUE(isgraph_l('a', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isgraph_l('A', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isgraph_l('1', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isgraph_l('!', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isgraph_l(' ', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, islower) {
   EXPECT_TRUE(islower('a'));
   EXPECT_FALSE(islower('A'));
   EXPECT_FALSE(islower('!'));
 }
 
+TEST(ctype, islower_l) {
+  EXPECT_TRUE(islower_l('a', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(islower_l('A', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(islower_l('!', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, isprint) {
   EXPECT_TRUE(isprint('a'));
   EXPECT_TRUE(isprint(' '));
   EXPECT_FALSE(isprint('\b'));
 }
 
+TEST(ctype, isprint_l) {
+  EXPECT_TRUE(isprint_l('a', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isprint_l(' ', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isprint_l('\b', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, ispunct) {
   EXPECT_TRUE(ispunct('!'));
   EXPECT_FALSE(ispunct('a'));
@@ -83,6 +136,13 @@
   EXPECT_FALSE(ispunct('\b'));
 }
 
+TEST(ctype, ispunct_l) {
+  EXPECT_TRUE(ispunct_l('!', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(ispunct_l('a', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(ispunct_l(' ', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(ispunct_l('\b', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, isspace) {
   EXPECT_TRUE(isspace(' '));
   EXPECT_TRUE(isspace('\f'));
@@ -94,12 +154,29 @@
   EXPECT_FALSE(isspace('!'));
 }
 
+TEST(ctype, isspace_l) {
+  EXPECT_TRUE(isspace_l(' ', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isspace_l('\f', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isspace_l('\n', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isspace_l('\r', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isspace_l('\t', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isspace_l('\v', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isspace_l('a', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isspace_l('!', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, isupper) {
   EXPECT_TRUE(isupper('A'));
   EXPECT_FALSE(isupper('a'));
   EXPECT_FALSE(isupper('!'));
 }
 
+TEST(ctype, isupper_l) {
+  EXPECT_TRUE(isupper_l('A', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isupper_l('a', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isupper_l('!', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, isxdigit) {
   EXPECT_TRUE(isxdigit('0'));
   EXPECT_FALSE(isxdigit('x'));
@@ -110,6 +187,16 @@
   EXPECT_FALSE(isxdigit(' '));
 }
 
+TEST(ctype, isxdigit_l) {
+  EXPECT_TRUE(isxdigit_l('0', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isxdigit_l('x', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isxdigit_l('1', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isxdigit_l('a', LC_GLOBAL_LOCALE));
+  EXPECT_TRUE(isxdigit_l('A', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isxdigit_l('g', LC_GLOBAL_LOCALE));
+  EXPECT_FALSE(isxdigit_l(' ', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, toascii) {
   EXPECT_EQ('a', toascii('a'));
   EXPECT_EQ('a', toascii(0x80 | 'a'));
@@ -121,6 +208,12 @@
   EXPECT_EQ('a', tolower('A'));
 }
 
+TEST(ctype, tolower_l) {
+  EXPECT_EQ('!', tolower_l('!', LC_GLOBAL_LOCALE));
+  EXPECT_EQ('a', tolower_l('a', LC_GLOBAL_LOCALE));
+  EXPECT_EQ('a', tolower_l('A', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, _tolower) {
   // _tolower may mangle characters for which isupper is false.
   EXPECT_EQ('a', _tolower('A'));
@@ -132,6 +225,12 @@
   EXPECT_EQ('A', toupper('A'));
 }
 
+TEST(ctype, toupper_l) {
+  EXPECT_EQ('!', toupper_l('!', LC_GLOBAL_LOCALE));
+  EXPECT_EQ('A', toupper_l('a', LC_GLOBAL_LOCALE));
+  EXPECT_EQ('A', toupper_l('A', LC_GLOBAL_LOCALE));
+}
+
 TEST(ctype, _toupper) {
   // _toupper may mangle characters for which islower is false.
   EXPECT_EQ('A', _toupper('a'));
diff --git a/tests/headers/Android.bp b/tests/headers/Android.bp
new file mode 100644
index 0000000..b44c296
--- /dev/null
+++ b/tests/headers/Android.bp
@@ -0,0 +1 @@
+subdirs = ["*"]
diff --git a/tests/headers/posix/Android.bp b/tests/headers/posix/Android.bp
new file mode 100644
index 0000000..682627f
--- /dev/null
+++ b/tests/headers/posix/Android.bp
@@ -0,0 +1,33 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_library_static {
+    name: "libbionic_tests_headers_posix",
+    srcs: ["*.c"],
+    cflags: [
+      "-Wno-absolute-value", // broken clang diagnostic that doesn't understand <tgmath.h>
+      "-Wno-deprecated",
+      "-Werror",
+      "-D_POSIX_C_SOURCE=200809L",
+      "-D_XOPEN_SOURCE=700",
+    ],
+    host_supported: true,
+    target: {
+        darwin: {
+            enabled: false,
+        },
+    },
+}
diff --git a/tests/headers/posix/arpa_inet_h.c b/tests/headers/posix/arpa_inet_h.c
new file mode 100644
index 0000000..51df1c7
--- /dev/null
+++ b/tests/headers/posix/arpa_inet_h.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <arpa/inet.h>
+
+#include "header_checks.h"
+
+static void arpa_inet_h() {
+  TYPE(in_port_t);
+  TYPE(in_addr_t);
+  TYPE(struct in_addr);
+
+  MACRO(INET_ADDRSTRLEN);
+  MACRO(INET6_ADDRSTRLEN);
+
+  FUNCTION(htonl, uint32_t (*f)(uint32_t));
+  FUNCTION(htons, uint16_t (*f)(uint16_t));
+  FUNCTION(ntohl, uint32_t (*f)(uint32_t));
+  FUNCTION(ntohs, uint16_t (*f)(uint16_t));
+
+  TYPE(uint32_t);
+  TYPE(uint16_t);
+
+  FUNCTION(inet_addr, in_addr_t (*f)(const char*));
+}
diff --git a/tests/headers/posix/assert_h.c b/tests/headers/posix/assert_h.c
new file mode 100644
index 0000000..81c577a
--- /dev/null
+++ b/tests/headers/posix/assert_h.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#undef NDEBUG
+
+#define NDEBUG
+#include <assert.h>
+#if !defined(assert)
+#error
+#endif
+
+#undef NDEBUG
+#include <assert.h>
+#if !defined(assert)
+#error
+#endif
diff --git a/tests/headers/posix/complex_h.c b/tests/headers/posix/complex_h.c
new file mode 100644
index 0000000..5003139
--- /dev/null
+++ b/tests/headers/posix/complex_h.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <complex.h>
+
+#include "header_checks.h"
+
+#if !defined(complex)
+#error complex
+#endif
+#if !defined(_Complex_I)
+#error _Complex_I
+#endif
+
+#if 0 // No libc actually implements this.
+#if !defined(imaginary)
+#error imaginary
+#endif
+#if !defined(_Imaginary_I)
+#error _Imaginary_I
+#endif
+#endif
+
+#if !defined(I)
+#error I
+#endif
+
+static void complex_h() {
+  FUNCTION(cabs, double (*f)(double complex));
+  FUNCTION(cabsf, float (*f)(float complex));
+  FUNCTION(cabsl, long double (*f)(long double complex));
+
+  FUNCTION(cacos, double complex (*f)(double complex));
+  FUNCTION(cacosf, float complex (*f)(float complex));
+  FUNCTION(cacosl, long double complex (*f)(long double complex));
+
+  FUNCTION(cacosh, double complex (*f)(double complex));
+  FUNCTION(cacoshf, float complex (*f)(float complex));
+  FUNCTION(cacoshl, long double complex (*f)(long double complex));
+
+  FUNCTION(carg, double (*f)(double complex));
+  FUNCTION(cargf, float (*f)(float complex));
+  FUNCTION(cargl, long double (*f)(long double complex));
+
+  FUNCTION(casin, double complex (*f)(double complex));
+  FUNCTION(casinf, float complex (*f)(float complex));
+  FUNCTION(casinl, long double complex (*f)(long double complex));
+
+  FUNCTION(casinh, double complex (*f)(double complex));
+  FUNCTION(casinhf, float complex (*f)(float complex));
+  FUNCTION(casinhl, long double complex (*f)(long double complex));
+
+  FUNCTION(catan, double complex (*f)(double complex));
+  FUNCTION(catanf, float complex (*f)(float complex));
+  FUNCTION(catanl, long double complex (*f)(long double complex));
+
+  FUNCTION(catanh, double complex (*f)(double complex));
+  FUNCTION(catanhf, float complex (*f)(float complex));
+  FUNCTION(catanhl, long double complex (*f)(long double complex));
+
+  FUNCTION(ccos, double complex (*f)(double complex));
+  FUNCTION(ccosf, float complex (*f)(float complex));
+  FUNCTION(ccosl, long double complex (*f)(long double complex));
+
+  FUNCTION(ccosh, double complex (*f)(double complex));
+  FUNCTION(ccoshf, float complex (*f)(float complex));
+  FUNCTION(ccoshl, long double complex (*f)(long double complex));
+
+  FUNCTION(cexp, double complex (*f)(double complex));
+  FUNCTION(cexpf, float complex (*f)(float complex));
+  FUNCTION(cexpl, long double complex (*f)(long double complex));
+
+  FUNCTION(cimag, double (*f)(double complex));
+  FUNCTION(cimagf, float (*f)(float complex));
+  FUNCTION(cimagl, long double (*f)(long double complex));
+
+  FUNCTION(clog, double complex (*f)(double complex));
+  FUNCTION(clogf, float complex (*f)(float complex));
+  FUNCTION(clogl, long double complex (*f)(long double complex));
+
+  FUNCTION(conj, double complex (*f)(double complex));
+  FUNCTION(conjf, float complex (*f)(float complex));
+  FUNCTION(conjl, long double complex (*f)(long double complex));
+
+  FUNCTION(cpow, double complex (*f)(double complex, double complex));
+  FUNCTION(cpowf, float complex (*f)(float complex, float complex));
+  FUNCTION(cpowl, long double complex (*f)(long double complex, long double complex));
+
+  FUNCTION(cproj, double complex (*f)(double complex));
+  FUNCTION(cprojf, float complex (*f)(float complex));
+  FUNCTION(cprojl, long double complex (*f)(long double complex));
+
+  FUNCTION(creal, double (*f)(double complex));
+  FUNCTION(crealf, float (*f)(float complex));
+  FUNCTION(creall, long double (*f)(long double complex));
+
+  FUNCTION(csin, double complex (*f)(double complex));
+  FUNCTION(csinf, float complex (*f)(float complex));
+  FUNCTION(csinl, long double complex (*f)(long double complex));
+
+  FUNCTION(csinh, double complex (*f)(double complex));
+  FUNCTION(csinhf, float complex (*f)(float complex));
+  FUNCTION(csinhl, long double complex (*f)(long double complex));
+
+  FUNCTION(csqrt, double complex (*f)(double complex));
+  FUNCTION(csqrtf, float complex (*f)(float complex));
+  FUNCTION(csqrtl, long double complex (*f)(long double complex));
+
+  FUNCTION(ctan, double complex (*f)(double complex));
+  FUNCTION(ctanf, float complex (*f)(float complex));
+  FUNCTION(ctanl, long double complex (*f)(long double complex));
+
+  FUNCTION(ctanh, double complex (*f)(double complex));
+  FUNCTION(ctanhf, float complex (*f)(float complex));
+  FUNCTION(ctanhl, long double complex (*f)(long double complex));
+}
diff --git a/tests/headers/posix/cpio_h.c b/tests/headers/posix/cpio_h.c
new file mode 100644
index 0000000..0dd2407
--- /dev/null
+++ b/tests/headers/posix/cpio_h.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <cpio.h>
+
+#include "header_checks.h"
+
+static void cpio_h() {
+  MACRO_VALUE(C_IRUSR, 0400);
+  MACRO_VALUE(C_IWUSR, 0200);
+  MACRO_VALUE(C_IXUSR, 0100);
+
+  MACRO_VALUE(C_IRGRP, 040);
+  MACRO_VALUE(C_IWGRP, 020);
+  MACRO_VALUE(C_IXGRP, 010);
+
+  MACRO_VALUE(C_IROTH, 04);
+  MACRO_VALUE(C_IWOTH, 02);
+  MACRO_VALUE(C_IXOTH, 01);
+
+  MACRO_VALUE(C_ISUID, 04000);
+  MACRO_VALUE(C_ISGID, 02000);
+  MACRO_VALUE(C_ISVTX, 01000);
+
+  MACRO_VALUE(C_ISDIR, 040000);
+  MACRO_VALUE(C_ISFIFO, 010000);
+  MACRO_VALUE(C_ISREG, 0100000);
+  MACRO_VALUE(C_ISBLK, 060000);
+  MACRO_VALUE(C_ISCHR, 020000);
+
+  MACRO_VALUE(C_ISCTG, 0110000);
+  MACRO_VALUE(C_ISLNK, 0120000);
+  MACRO_VALUE(C_ISSOCK, 0140000);
+
+#if !defined(MAGIC)
+#error MAGIC
+#endif
+}
diff --git a/tests/headers/posix/ctype_h.c b/tests/headers/posix/ctype_h.c
new file mode 100644
index 0000000..c901284
--- /dev/null
+++ b/tests/headers/posix/ctype_h.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+
+#include "header_checks.h"
+
+static void ctype_h() {
+  FUNCTION(isalnum, int (*f)(int));
+  FUNCTION(isalnum_l, int (*f)(int, locale_t));
+  FUNCTION(isalpha, int (*f)(int));
+  FUNCTION(isalpha_l, int (*f)(int, locale_t));
+  FUNCTION(isascii, int (*f)(int));
+  FUNCTION(isblank, int (*f)(int));
+  FUNCTION(isblank_l, int (*f)(int, locale_t));
+  FUNCTION(iscntrl, int (*f)(int));
+  FUNCTION(iscntrl_l, int (*f)(int, locale_t));
+  FUNCTION(isdigit, int (*f)(int));
+  FUNCTION(isdigit_l, int (*f)(int, locale_t));
+  FUNCTION(isgraph, int (*f)(int));
+  FUNCTION(isgraph_l, int (*f)(int, locale_t));
+  FUNCTION(islower, int (*f)(int));
+  FUNCTION(islower_l, int (*f)(int, locale_t));
+  FUNCTION(isprint, int (*f)(int));
+  FUNCTION(isprint_l, int (*f)(int, locale_t));
+  FUNCTION(ispunct, int (*f)(int));
+  FUNCTION(ispunct_l, int (*f)(int, locale_t));
+  FUNCTION(isspace, int (*f)(int));
+  FUNCTION(isspace_l, int (*f)(int, locale_t));
+  FUNCTION(isupper, int (*f)(int));
+  FUNCTION(isupper_l, int (*f)(int, locale_t));
+  FUNCTION(isxdigit, int (*f)(int));
+  FUNCTION(isxdigit_l, int (*f)(int, locale_t));
+
+  FUNCTION(toascii, int (*f)(int));
+  FUNCTION(tolower, int (*f)(int));
+  FUNCTION(tolower_l, int (*f)(int, locale_t));
+  FUNCTION(toupper, int (*f)(int));
+  FUNCTION(toupper_l, int (*f)(int, locale_t));
+
+#if !defined(__BIONIC__) // These are marked obsolescent.
+  #if !defined(_toupper)
+    #error _toupper
+  #endif
+  #if !defined(_tolower)
+    #error _tolower
+  #endif
+#endif
+}
diff --git a/tests/headers/posix/dirent_h.c b/tests/headers/posix/dirent_h.c
new file mode 100644
index 0000000..4ce0f18
--- /dev/null
+++ b/tests/headers/posix/dirent_h.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <dirent.h>
+
+#include "header_checks.h"
+
+static void dirent_h() {
+  INCOMPLETE_TYPE(DIR);
+
+  TYPE(struct dirent);
+#if defined(__BIONIC__) && !defined(__LP64__) // Historical ABI accident.
+  STRUCT_MEMBER(struct dirent, uint64_t, d_ino);
+#else
+  STRUCT_MEMBER(struct dirent, ino_t, d_ino);
+#endif
+  STRUCT_MEMBER_ARRAY(struct dirent, char/*[]*/, d_name);
+
+  TYPE(ino_t);
+
+  FUNCTION(alphasort, int (*f)(const struct dirent**, const struct dirent**));
+  FUNCTION(closedir, int (*f)(DIR*));
+  FUNCTION(dirfd, int (*f)(DIR*));
+  FUNCTION(fdopendir, DIR* (*f)(int));
+  FUNCTION(opendir, DIR* (*f)(const char*));
+  FUNCTION(readdir, struct dirent* (*f)(DIR*));
+  FUNCTION(readdir_r, int (*f)(DIR*, struct dirent*, struct dirent**));
+  FUNCTION(rewinddir, void (*f)(DIR*));
+  FUNCTION(scandir, int (*f)(const char*, struct dirent***,
+                             int (*)(const struct dirent*),
+                             int (*)(const struct dirent**, const struct dirent**)));
+  FUNCTION(seekdir, void (*f)(DIR*, long));
+  FUNCTION(telldir, long (*f)(DIR*));
+}
diff --git a/tests/headers/posix/dlfcn_h.c b/tests/headers/posix/dlfcn_h.c
new file mode 100644
index 0000000..4800075
--- /dev/null
+++ b/tests/headers/posix/dlfcn_h.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <dlfcn.h>
+
+#include "header_checks.h"
+
+static void dlfcn_h() {
+  MACRO(RTLD_LAZY);
+  MACRO(RTLD_NOW);
+  MACRO(RTLD_GLOBAL);
+  MACRO(RTLD_LOCAL);
+
+  FUNCTION(dlclose, int (*f)(void*));
+  FUNCTION(dlerror, char* (*f)(void));
+  FUNCTION(dlopen, void* (*f)(const char*, int));
+  FUNCTION(dlsym, void* (*f)(void*, const char*));
+}
diff --git a/tests/headers/posix/errno_h.c b/tests/headers/posix/errno_h.c
new file mode 100644
index 0000000..9eabfd5
--- /dev/null
+++ b/tests/headers/posix/errno_h.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+
+#include "header_checks.h"
+
+static void errno_h() {
+  int error = errno;
+
+  MACRO(E2BIG);
+  MACRO(EACCES);
+  MACRO(EADDRINUSE);
+  MACRO(EADDRNOTAVAIL);
+  MACRO(EAFNOSUPPORT);
+  MACRO(EAGAIN);
+  MACRO(EALREADY);
+  MACRO(EBADF);
+  MACRO(EBADMSG);
+  MACRO(EBUSY);
+  MACRO(ECANCELED);
+  MACRO(ECHILD);
+  MACRO(ECONNABORTED);
+  MACRO(ECONNRESET);
+  MACRO(EDEADLK);
+  MACRO(EDESTADDRREQ);
+  MACRO(EDOM);
+  MACRO(EDQUOT);
+  MACRO(EEXIST);
+  MACRO(EFAULT);
+  MACRO(EFBIG);
+  MACRO(EHOSTUNREACH);
+  MACRO(EIDRM);
+  MACRO(EILSEQ);
+  MACRO(EINPROGRESS);
+  MACRO(EINTR);
+  MACRO(EINVAL);
+  MACRO(EIO);
+  MACRO(EISCONN);
+  MACRO(EISDIR);
+  MACRO(ELOOP);
+  MACRO(EMFILE);
+  MACRO(EMLINK);
+  MACRO(EMSGSIZE);
+  MACRO(EMULTIHOP);
+  MACRO(ENAMETOOLONG);
+  MACRO(ENETDOWN);
+  MACRO(ENETRESET);
+  MACRO(ENETUNREACH);
+  MACRO(ENFILE);
+  MACRO(ENOBUFS);
+  MACRO(ENODATA);
+  MACRO(ENODEV);
+  MACRO(ENOENT);
+  MACRO(ENOEXEC);
+  MACRO(ENOLCK);
+  MACRO(ENOLINK);
+  MACRO(ENOMEM);
+  MACRO(ENOMSG);
+  MACRO(ENOPROTOOPT);
+  MACRO(ENOSPC);
+  MACRO(ENOSR);
+  MACRO(ENOSTR);
+  MACRO(ENOSYS);
+  MACRO(ENOTCONN);
+  MACRO(ENOTDIR);
+  MACRO(ENOTEMPTY);
+  MACRO(ENOTRECOVERABLE);
+  MACRO(ENOTSOCK);
+  MACRO(ENOTSUP);
+  MACRO(ENOTTY);
+  MACRO(ENXIO);
+  MACRO(EOPNOTSUPP);
+  MACRO(EOVERFLOW);
+  MACRO(EOWNERDEAD);
+  MACRO(EPERM);
+  MACRO(EPIPE);
+  MACRO(EPROTO);
+  MACRO(EPROTONOSUPPORT);
+  MACRO(EPROTOTYPE);
+  MACRO(ERANGE);
+  MACRO(EROFS);
+  MACRO(ESPIPE);
+  MACRO(ESRCH);
+  MACRO(ESTALE);
+  MACRO(ETIME);
+  MACRO(ETIMEDOUT);
+  MACRO(ETXTBSY);
+  MACRO(EWOULDBLOCK);
+  MACRO(EXDEV);
+}
diff --git a/tests/headers/posix/fcntl_h.c b/tests/headers/posix/fcntl_h.c
new file mode 100644
index 0000000..a55fe89
--- /dev/null
+++ b/tests/headers/posix/fcntl_h.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <fcntl.h>
+
+#include "header_checks.h"
+
+static void fcntl_h() {
+  MACRO(F_DUPFD);
+  MACRO(F_DUPFD_CLOEXEC);
+  MACRO(F_GETFD);
+  MACRO(F_SETFD);
+  MACRO(F_GETFL);
+  MACRO(F_SETFL);
+  MACRO(F_GETLK);
+  MACRO(F_SETLK);
+  MACRO(F_SETLKW);
+  MACRO(F_GETOWN);
+  MACRO(F_SETOWN);
+
+  MACRO(FD_CLOEXEC);
+
+  MACRO(F_RDLCK);
+  MACRO(F_UNLCK);
+  MACRO(F_WRLCK);
+
+  MACRO(SEEK_SET);
+  MACRO(SEEK_CUR);
+  MACRO(SEEK_END);
+
+  MACRO(O_CLOEXEC);
+  MACRO(O_CREAT);
+  MACRO(O_DIRECTORY);
+  MACRO(O_EXCL);
+  MACRO(O_NOCTTY);
+  MACRO(O_NOFOLLOW);
+  MACRO(O_TRUNC);
+#if !defined(__linux__)
+  MACRO(O_TTY_INIT);
+#endif
+
+  MACRO(O_APPEND);
+  MACRO(O_DSYNC);
+  MACRO(O_NONBLOCK);
+  MACRO(O_RSYNC);
+  MACRO(O_SYNC);
+
+  MACRO(O_ACCMODE);
+
+#if !defined(__linux__)
+  MACRO(O_EXEC);
+#endif
+  MACRO(O_RDONLY);
+  MACRO(O_RDWR);
+#if !defined(__linux__)
+  MACRO(O_SEARCH);
+#endif
+  MACRO(O_WRONLY);
+
+  // POSIX: "The <fcntl.h> header shall define the symbolic constants for
+  // file modes for use as values of mode_t as described in <sys/stat.h>."
+#include "sys_stat_h_mode_constants.h"
+
+  MACRO(AT_FDCWD);
+#if !defined(__BIONIC__) // See comment in "faccessat.cpp".
+  MACRO(AT_EACCESS);
+#endif
+  MACRO(AT_SYMLINK_NOFOLLOW);
+  MACRO(AT_REMOVEDIR);
+
+  MACRO(POSIX_FADV_DONTNEED);
+  MACRO(POSIX_FADV_NOREUSE);
+  MACRO(POSIX_FADV_NORMAL);
+  MACRO(POSIX_FADV_RANDOM);
+  MACRO(POSIX_FADV_SEQUENTIAL);
+  MACRO(POSIX_FADV_WILLNEED);
+
+  TYPE(struct flock);
+  STRUCT_MEMBER(struct flock, short, l_type);
+  STRUCT_MEMBER(struct flock, short, l_whence);
+  STRUCT_MEMBER(struct flock, off_t, l_start);
+  STRUCT_MEMBER(struct flock, off_t, l_len);
+  STRUCT_MEMBER(struct flock, pid_t, l_pid);
+
+  TYPE(mode_t);
+  TYPE(off_t);
+  TYPE(pid_t);
+
+  FUNCTION(creat, int (*f)(const char*, mode_t));
+  FUNCTION(fcntl, int (*f)(int, int, ...));
+  FUNCTION(open, int (*f)(const char*, int, ...));
+  FUNCTION(openat, int (*f)(int, const char*, int, ...));
+  FUNCTION(posix_fadvise, int (*f)(int, off_t, off_t, int));
+  FUNCTION(posix_fallocate, int (*f)(int, off_t, off_t));
+}
diff --git a/tests/headers/posix/fenv_h.c b/tests/headers/posix/fenv_h.c
new file mode 100644
index 0000000..cabe4ae
--- /dev/null
+++ b/tests/headers/posix/fenv_h.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <fenv.h>
+
+#include "header_checks.h"
+
+static void fenv_h() {
+  TYPE(fenv_t);
+  TYPE(fexcept_t);
+
+  MACRO(FE_DIVBYZERO);
+  MACRO(FE_INEXACT);
+  MACRO(FE_INVALID);
+  MACRO(FE_OVERFLOW);
+  MACRO(FE_UNDERFLOW);
+
+  MACRO(FE_ALL_EXCEPT);
+
+  MACRO(FE_DOWNWARD);
+  MACRO(FE_TONEAREST);
+  MACRO(FE_TOWARDZERO);
+  MACRO(FE_UPWARD);
+
+  const fenv_t* fe_dfl_env = FE_DFL_ENV;
+
+  FUNCTION(feclearexcept, int (*f)(int));
+  FUNCTION(fegetenv, int (*f)(fenv_t*));
+  FUNCTION(fegetexceptflag, int (*f)(fexcept_t*, int));
+  FUNCTION(fegetround, int (*f)(void));
+  FUNCTION(feholdexcept, int (*f)(fenv_t*));
+  FUNCTION(feraiseexcept, int (*f)(int));
+  FUNCTION(fesetenv, int (*f)(const fenv_t*));
+  FUNCTION(fesetexceptflag, int (*f)(const fexcept_t*, int));
+  FUNCTION(fesetround, int (*f)(int));
+  FUNCTION(fetestexcept, int (*f)(int));
+  FUNCTION(feupdateenv, int (*f)(const fenv_t*));
+}
diff --git a/tests/headers/posix/float_h.c b/tests/headers/posix/float_h.c
new file mode 100644
index 0000000..5f12fa2
--- /dev/null
+++ b/tests/headers/posix/float_h.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <float.h>
+
+#include "header_checks.h"
+
+static void float_h() {
+  int flt_rounds = FLT_ROUNDS;
+
+  MACRO(FLT_EVAL_METHOD);
+
+  MACRO(FLT_RADIX);
+  MACRO(FLT_MANT_DIG);
+  MACRO(DBL_MANT_DIG);
+  MACRO(LDBL_MANT_DIG);
+  MACRO(DECIMAL_DIG);
+  MACRO(FLT_DIG);
+  MACRO(DBL_DIG);
+  MACRO(LDBL_DIG);
+  MACRO(FLT_MIN_EXP);
+  MACRO(DBL_MIN_EXP);
+  MACRO(LDBL_MIN_EXP);
+  MACRO(FLT_MIN_10_EXP);
+  MACRO(DBL_MIN_10_EXP);
+  MACRO(LDBL_MIN_10_EXP);
+  MACRO(FLT_MAX_EXP);
+  MACRO(DBL_MAX_EXP);
+  MACRO(LDBL_MAX_EXP);
+  MACRO(FLT_MAX_10_EXP);
+  MACRO(DBL_MAX_10_EXP);
+  MACRO(LDBL_MAX_10_EXP);
+  MACRO(FLT_MAX);
+  MACRO(DBL_MAX);
+  MACRO(LDBL_MAX);
+  MACRO(FLT_EPSILON);
+  MACRO(DBL_EPSILON);
+  MACRO(LDBL_EPSILON);
+  MACRO(FLT_MIN);
+  MACRO(DBL_MIN);
+  MACRO(LDBL_MIN);
+}
diff --git a/tests/headers/posix/fnmatch_h.c b/tests/headers/posix/fnmatch_h.c
new file mode 100644
index 0000000..3dd41d7
--- /dev/null
+++ b/tests/headers/posix/fnmatch_h.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <fnmatch.h>
+
+#include "header_checks.h"
+
+static void fnmatch_h() {
+  MACRO(FNM_NOMATCH);
+  MACRO(FNM_PATHNAME);
+  MACRO(FNM_PERIOD);
+  MACRO(FNM_NOESCAPE);
+
+  FUNCTION(fnmatch, int (*f)(const char*, const char*, int));
+}
diff --git a/tests/headers/posix/ftw_h.c b/tests/headers/posix/ftw_h.c
new file mode 100644
index 0000000..0a78d94
--- /dev/null
+++ b/tests/headers/posix/ftw_h.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ftw.h>
+
+#include "header_checks.h"
+
+static void ftw_h() {
+  TYPE(struct FTW);
+  STRUCT_MEMBER(struct FTW, int, base);
+  STRUCT_MEMBER(struct FTW, int, level);
+
+  MACRO(FTW_F);
+  MACRO(FTW_D);
+  MACRO(FTW_DNR);
+  MACRO(FTW_DP);
+  MACRO(FTW_NS);
+  MACRO(FTW_SL);
+  MACRO(FTW_SLN);
+
+  MACRO(FTW_PHYS);
+  MACRO(FTW_MOUNT);
+  MACRO(FTW_DEPTH);
+  MACRO(FTW_CHDIR);
+
+  FUNCTION(ftw, int (*f)(const char*, int (*)(const char*, const struct stat*, int), int));
+
+  TYPE(struct stat);
+
+  // POSIX: "The <ftw.h> header shall define the ... the symbolic names for
+  // st_mode and the file type test macros as described in <sys/stat.h>."
+#include "sys_stat_h_mode_constants.h"
+#include "sys_stat_h_file_type_test_macros.h"
+}
diff --git a/tests/headers/posix/glob_h.c b/tests/headers/posix/glob_h.c
new file mode 100644
index 0000000..b399e52
--- /dev/null
+++ b/tests/headers/posix/glob_h.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <glob.h>
+
+#include "header_checks.h"
+
+static void glob_h() {
+  TYPE(glob_t);
+  STRUCT_MEMBER(glob_t, size_t, gl_pathc);
+  STRUCT_MEMBER(glob_t, char**, gl_pathv);
+  STRUCT_MEMBER(glob_t, size_t, gl_offs);
+  TYPE(size_t);
+
+  MACRO(GLOB_APPEND);
+  MACRO(GLOB_DOOFFS);
+  MACRO(GLOB_ERR);
+  MACRO(GLOB_MARK);
+  MACRO(GLOB_NOCHECK);
+  MACRO(GLOB_NOESCAPE);
+  MACRO(GLOB_NOSORT);
+
+  MACRO(GLOB_ABORTED);
+  MACRO(GLOB_NOMATCH);
+  MACRO(GLOB_NOSPACE);
+
+  FUNCTION(glob, int (*f)(const char*, int, int (*)(const char*, int), glob_t*));
+  FUNCTION(globfree, void (*f)(glob_t*));
+}
diff --git a/tests/headers/posix/grp_h.c b/tests/headers/posix/grp_h.c
new file mode 100644
index 0000000..7042e83
--- /dev/null
+++ b/tests/headers/posix/grp_h.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <grp.h>
+
+#include "header_checks.h"
+
+static void grp_h() {
+  TYPE(struct group);
+  STRUCT_MEMBER(struct group, char*, gr_name);
+  STRUCT_MEMBER(struct group, gid_t, gr_gid);
+  STRUCT_MEMBER(struct group, char**, gr_mem);
+
+  TYPE(gid_t);
+  TYPE(size_t);
+
+  FUNCTION(endgrent, void (*f)(void));
+  FUNCTION(getgrent, struct group* (*f)(void));
+  FUNCTION(getgrgid, struct group* (*f)(gid_t));
+  FUNCTION(getgrgid_r, int (*f)(gid_t, struct group*, char*, size_t, struct group**));
+  FUNCTION(getgrnam, struct group* (*f)(const char*));
+  FUNCTION(getgrnam_r, int (*f)(const char*, struct group*, char*, size_t, struct group**));
+  FUNCTION(setgrent, void (*f)(void));
+}
diff --git a/tests/headers/posix/header_checks.h b/tests/headers/posix/header_checks.h
new file mode 100644
index 0000000..2ce6da9
--- /dev/null
+++ b/tests/headers/posix/header_checks.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#define FUNCTION(f_, t_) { t_ = f_; }
+#define MACRO(m_) { typeof(m_) v = m_; }
+#define MACRO_VALUE(m_, v_) _Static_assert((m_)==(v_),#m_)
+#define MACRO_TYPE(t_, m_) { t_ v = m_; }
+#define TYPE(t_) { t_ value; }
+#define INCOMPLETE_TYPE(t_) { t_* value; }
+#define STRUCT_MEMBER(s_, t_, n_) { s_ s; t_* ptr = &(s.n_); }
+#define STRUCT_MEMBER_ARRAY(s_, t_, n_) { s_ s; t_* ptr = &(s.n_[0]); }
+#define STRUCT_MEMBER_FUNCTION_POINTER(s_, t_, n_) { s_ s; t_ = (s.n_); }
diff --git a/tests/headers/posix/iconv_h.c b/tests/headers/posix/iconv_h.c
new file mode 100644
index 0000000..d92d873
--- /dev/null
+++ b/tests/headers/posix/iconv_h.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <iconv.h>
+
+#include "header_checks.h"
+
+static void iconv_h() {
+  TYPE(iconv_t);
+  TYPE(size_t);
+
+  FUNCTION(iconv, size_t (*f)(iconv_t, char**, size_t*, char**, size_t*));
+  FUNCTION(iconv_close, int (*f)(iconv_t));
+  FUNCTION(iconv_open, iconv_t (*f)(const char*, const char*));
+}
diff --git a/tests/headers/posix/inttypes_h.c b/tests/headers/posix/inttypes_h.c
new file mode 100644
index 0000000..1eba4b8
--- /dev/null
+++ b/tests/headers/posix/inttypes_h.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+
+#include "header_checks.h"
+
+static void inttypes_h() {
+  TYPE(imaxdiv_t);
+#if defined(__GLIBC__)
+  // Despite POSIX, glibc goes out of its way to avoid defining wchar_t. Fix that.
+  typedef __WCHAR_TYPE__ wchar_t;
+#endif
+  TYPE(wchar_t);
+
+  // TODO: PRI macros
+  // TODO: SCN macros
+
+  FUNCTION(imaxabs, intmax_t (*f)(intmax_t));
+  FUNCTION(imaxdiv, imaxdiv_t (*f)(intmax_t, intmax_t));
+  FUNCTION(strtoimax, intmax_t (*f)(const char*, char**, int));
+  FUNCTION(strtoumax, uintmax_t (*f)(const char*, char**, int));
+  FUNCTION(wcstoimax, intmax_t (*f)(const wchar_t*, wchar_t**, int));
+  FUNCTION(wcstoumax, uintmax_t (*f)(const wchar_t*, wchar_t**, int));
+}
diff --git a/tests/headers/posix/iso646_h.c b/tests/headers/posix/iso646_h.c
new file mode 100644
index 0000000..be2a189
--- /dev/null
+++ b/tests/headers/posix/iso646_h.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <iso646.h>
+
+#include "header_checks.h"
+
+static void iso646_h() {
+#if !defined(and)
+#error and
+#endif
+#if !defined(and_eq)
+#error and_eq
+#endif
+#if !defined(bitand)
+#error bitand
+#endif
+#if !defined(bitor)
+#error bitor
+#endif
+#if !defined(compl)
+#error compl
+#endif
+#if !defined(not)
+#error not
+#endif
+#if !defined(not_eq)
+#error not_eq
+#endif
+#if !defined(or)
+#error or
+#endif
+#if !defined(or_eq)
+#error or_eq
+#endif
+#if !defined(xor)
+#error xor
+#endif
+#if !defined(xor_eq)
+#error xor_eq
+#endif
+}
diff --git a/tests/headers/posix/langinfo_h.c b/tests/headers/posix/langinfo_h.c
new file mode 100644
index 0000000..d38d41b
--- /dev/null
+++ b/tests/headers/posix/langinfo_h.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <langinfo.h>
+
+#include "header_checks.h"
+
+static void langinfo_h() {
+  TYPE(locale_t);
+  TYPE(nl_item);
+
+  MACRO_TYPE(nl_item, CODESET);
+  MACRO_TYPE(nl_item, D_T_FMT);
+  MACRO_TYPE(nl_item, D_FMT);
+  MACRO_TYPE(nl_item, T_FMT);
+  MACRO_TYPE(nl_item, T_FMT_AMPM);
+  MACRO_TYPE(nl_item, AM_STR);
+  MACRO_TYPE(nl_item, PM_STR);
+  MACRO_TYPE(nl_item, DAY_1);
+  MACRO_TYPE(nl_item, DAY_2);
+  MACRO_TYPE(nl_item, DAY_3);
+  MACRO_TYPE(nl_item, DAY_4);
+  MACRO_TYPE(nl_item, DAY_5);
+  MACRO_TYPE(nl_item, DAY_6);
+  MACRO_TYPE(nl_item, DAY_7);
+  MACRO_TYPE(nl_item, ABDAY_1);
+  MACRO_TYPE(nl_item, ABDAY_2);
+  MACRO_TYPE(nl_item, ABDAY_3);
+  MACRO_TYPE(nl_item, ABDAY_4);
+  MACRO_TYPE(nl_item, ABDAY_5);
+  MACRO_TYPE(nl_item, ABDAY_6);
+  MACRO_TYPE(nl_item, ABDAY_7);
+  MACRO_TYPE(nl_item, MON_1);
+  MACRO_TYPE(nl_item, MON_2);
+  MACRO_TYPE(nl_item, MON_3);
+  MACRO_TYPE(nl_item, MON_4);
+  MACRO_TYPE(nl_item, MON_5);
+  MACRO_TYPE(nl_item, MON_6);
+  MACRO_TYPE(nl_item, MON_7);
+  MACRO_TYPE(nl_item, MON_8);
+  MACRO_TYPE(nl_item, MON_9);
+  MACRO_TYPE(nl_item, MON_10);
+  MACRO_TYPE(nl_item, MON_11);
+  MACRO_TYPE(nl_item, MON_12);
+  MACRO_TYPE(nl_item, ABMON_1);
+  MACRO_TYPE(nl_item, ABMON_2);
+  MACRO_TYPE(nl_item, ABMON_3);
+  MACRO_TYPE(nl_item, ABMON_4);
+  MACRO_TYPE(nl_item, ABMON_5);
+  MACRO_TYPE(nl_item, ABMON_6);
+  MACRO_TYPE(nl_item, ABMON_7);
+  MACRO_TYPE(nl_item, ABMON_8);
+  MACRO_TYPE(nl_item, ABMON_9);
+  MACRO_TYPE(nl_item, ABMON_10);
+  MACRO_TYPE(nl_item, ABMON_11);
+  MACRO_TYPE(nl_item, ABMON_12);
+  MACRO_TYPE(nl_item, ERA);
+  MACRO_TYPE(nl_item, ERA_D_FMT);
+  MACRO_TYPE(nl_item, ERA_D_T_FMT);
+  MACRO_TYPE(nl_item, ERA_T_FMT);
+  MACRO_TYPE(nl_item, ALT_DIGITS);
+  MACRO_TYPE(nl_item, RADIXCHAR);
+  MACRO_TYPE(nl_item, THOUSEP);
+  MACRO_TYPE(nl_item, YESEXPR);
+  MACRO_TYPE(nl_item, NOEXPR);
+  MACRO_TYPE(nl_item, CRNCYSTR);
+
+  FUNCTION(nl_langinfo, char* (*f)(nl_item));
+  FUNCTION(nl_langinfo_l, char* (*f)(nl_item, locale_t));
+}
diff --git a/tests/headers/posix/libgen_h.c b/tests/headers/posix/libgen_h.c
new file mode 100644
index 0000000..d839a06
--- /dev/null
+++ b/tests/headers/posix/libgen_h.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <libgen.h>
+
+#include "header_checks.h"
+
+static void libgen_h() {
+#if defined(__BIONIC__) // bionic doesn't modify its argument, and admits as much.
+  FUNCTION(basename, char* (*f)(const char*));
+  FUNCTION(dirname, char* (*f)(const char*));
+#else
+  FUNCTION(basename, char* (*f)(char*));
+  FUNCTION(dirname, char* (*f)(char*));
+#endif
+}
diff --git a/tests/headers/posix/limits_h.c b/tests/headers/posix/limits_h.c
new file mode 100644
index 0000000..143f717
--- /dev/null
+++ b/tests/headers/posix/limits_h.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <limits.h>
+
+#include "header_checks.h"
+
+static void limits_h() {
+  // These are only defined if they're constants.
+#if !defined(__BIONIC__) && !defined(__GLIBC__)
+  MACRO(AIO_LISTIO_MAX);
+  MACRO(AIO_MAX);
+#endif
+#if !defined(__BIONIC__)
+  MACRO(AIO_PRIO_DELTA_MAX);
+#endif
+#if !defined(__BIONIC__) && !defined(__GLIBC__)
+  MACRO(ARG_MAX);
+  MACRO(ATEXIT_MAX);
+  MACRO(CHILD_MAX);
+#endif
+#if !defined(__BIONIC__)
+  MACRO(DELAYTIMER_MAX);
+#endif
+  MACRO(HOST_NAME_MAX);
+  MACRO(IOV_MAX);
+  MACRO(LOGIN_NAME_MAX);
+#if !defined(__BIONIC__) && !defined(__GLIBC__)
+  MACRO(MQ_OPEN_MAX);
+#endif
+#if !defined(__BIONIC__)
+  MACRO(MQ_PRIO_MAX);
+#endif
+#if !defined(__BIONIC__) && !defined(__GLIBC__)
+  MACRO(OPEN_MAX);
+  MACRO(PAGESIZE);
+  MACRO(PAGE_SIZE);
+#endif
+  MACRO(PTHREAD_DESTRUCTOR_ITERATIONS);
+  MACRO(PTHREAD_KEYS_MAX);
+#if !defined(__BIONIC__)
+  MACRO(PTHREAD_STACK_MIN);
+#endif
+#if !defined(__BIONIC__) && !defined(__GLIBC__)
+  MACRO(PTHREAD_THREADS_MAX);
+#endif
+  MACRO(RTSIG_MAX);
+#if !defined(__BIONIC__) && !defined(__GLIBC__)
+  MACRO(SEM_NSEMS_MAX);
+#endif
+  MACRO(SEM_VALUE_MAX);
+#if !defined(__BIONIC__) && !defined(__GLIBC__)
+  MACRO(SIGQUEUE_MAX);
+  MACRO(SS_REPL_MAX);
+  MACRO(STREAM_MAX);
+  MACRO(SYMLOOP_MAX);
+  MACRO(TIMER_MAX);
+#endif
+#if !defined(__BIONIC__)
+  MACRO(TTY_NAME_MAX);
+#endif
+#if !defined(__BIONIC__) && !defined(__GLIBC__)
+  MACRO(TZNAME_MAX);
+#endif
+
+#if !defined(__BIONIC__) && !defined(__GLIBC__)
+  MACRO(FILESIZEBITS);
+  MACRO(LINK_MAX);
+#endif
+  MACRO(MAX_CANON);
+  MACRO(MAX_INPUT);
+  MACRO(NAME_MAX);
+  MACRO(PATH_MAX);
+  MACRO(PIPE_BUF);
+#if 0 // No libc has these.
+  MACRO(POSIX_ALLOC_SIZE_MIN);
+  MACRO(POSIX_REC_INCR_XFER_SIZE);
+  MACRO(POSIX_REC_MAX_XFER_SIZE);
+  MACRO(POSIX_REC_MIN_XFER_SIZE);
+  MACRO(POSIX_REC_XFER_ALIGN);
+#endif
+#if !defined(__BIONIC__) && !defined(__GLIBC__)
+  MACRO(SYMLINK_MAX);
+#endif
+
+#if !defined(__BIONIC__)
+  MACRO(BC_BASE_MAX);
+  MACRO(BC_DIM_MAX);
+  MACRO(BC_SCALE_MAX);
+  MACRO(BC_STRING_MAX);
+  MACRO(CHARCLASS_NAME_MAX);
+  MACRO(COLL_WEIGHTS_MAX);
+  MACRO(EXPR_NEST_MAX);
+  MACRO(LINE_MAX);
+  MACRO(NGROUPS_MAX);
+  MACRO(RE_DUP_MAX);
+#endif
+
+  MACRO_VALUE(_POSIX_CLOCKRES_MIN, 20000000);
+
+  MACRO_VALUE(_POSIX_AIO_LISTIO_MAX, 2);
+  MACRO_VALUE(_POSIX_AIO_MAX, 1);
+  MACRO_VALUE(_POSIX_ARG_MAX, 4096);
+  MACRO_VALUE(_POSIX_CHILD_MAX, 25);
+  MACRO_VALUE(_POSIX_DELAYTIMER_MAX, 32);
+  MACRO_VALUE(_POSIX_HOST_NAME_MAX, 255);
+  MACRO_VALUE(_POSIX_LINK_MAX, 8);
+  MACRO_VALUE(_POSIX_LOGIN_NAME_MAX, 9);
+  MACRO_VALUE(_POSIX_MAX_CANON, 255);
+  MACRO_VALUE(_POSIX_MAX_INPUT, 255);
+  MACRO_VALUE(_POSIX_MQ_OPEN_MAX, 8);
+  MACRO_VALUE(_POSIX_MQ_PRIO_MAX, 32);
+  MACRO_VALUE(_POSIX_NAME_MAX, 14);
+  MACRO_VALUE(_POSIX_NGROUPS_MAX, 8);
+  MACRO_VALUE(_POSIX_OPEN_MAX, 20);
+  MACRO_VALUE(_POSIX_PATH_MAX, 256);
+  MACRO_VALUE(_POSIX_PIPE_BUF, 512);
+  MACRO_VALUE(_POSIX_RE_DUP_MAX, 255);
+  MACRO_VALUE(_POSIX_RTSIG_MAX, 8);
+  MACRO_VALUE(_POSIX_SEM_NSEMS_MAX, 256);
+  MACRO_VALUE(_POSIX_SEM_VALUE_MAX, 32767);
+  MACRO_VALUE(_POSIX_SIGQUEUE_MAX, 32);
+  MACRO_VALUE(_POSIX_SSIZE_MAX, 32767);
+#if !defined(__GLIBC__)
+  MACRO_VALUE(_POSIX_SS_REPL_MAX, 4);
+#endif
+  MACRO_VALUE(_POSIX_STREAM_MAX, 8);
+  MACRO_VALUE(_POSIX_SYMLINK_MAX, 255);
+  MACRO_VALUE(_POSIX_SYMLOOP_MAX, 8);
+  MACRO_VALUE(_POSIX_THREAD_DESTRUCTOR_ITERATIONS, 4);
+  MACRO_VALUE(_POSIX_THREAD_KEYS_MAX, 128);
+  MACRO_VALUE(_POSIX_THREAD_THREADS_MAX, 64);
+  MACRO_VALUE(_POSIX_TIMER_MAX, 32);
+#if !defined(__GLIBC__)
+  MACRO_VALUE(_POSIX_TRACE_EVENT_NAME_MAX, 30);
+  MACRO_VALUE(_POSIX_TRACE_NAME_MAX, 8);
+  MACRO_VALUE(_POSIX_TRACE_SYS_MAX, 8);
+  MACRO_VALUE(_POSIX_TRACE_USER_EVENT_MAX, 32);
+#endif
+  MACRO_VALUE(_POSIX_TTY_NAME_MAX, 9);
+  MACRO_VALUE(_POSIX_TZNAME_MAX, 6);
+  MACRO_VALUE(_POSIX2_BC_BASE_MAX, 99);
+  MACRO_VALUE(_POSIX2_BC_DIM_MAX, 2048);
+  MACRO_VALUE(_POSIX2_BC_SCALE_MAX, 99);
+  MACRO_VALUE(_POSIX2_BC_STRING_MAX, 1000);
+  MACRO_VALUE(_POSIX2_CHARCLASS_NAME_MAX, 14);
+  MACRO_VALUE(_POSIX2_COLL_WEIGHTS_MAX, 2);
+  MACRO_VALUE(_POSIX2_EXPR_NEST_MAX, 32);
+  MACRO_VALUE(_POSIX2_LINE_MAX, 2048);
+  MACRO_VALUE(_POSIX2_RE_DUP_MAX, 255);
+#if !defined(__GLIBC__)
+  MACRO_VALUE(_XOPEN_IOV_MAX, 16);
+  MACRO_VALUE(_XOPEN_NAME_MAX, 255);
+  MACRO_VALUE(_XOPEN_PATH_MAX, 1024);
+#endif
+
+  MACRO_VALUE(CHAR_BIT, 8);
+  MACRO(CHAR_MAX);
+  MACRO(CHAR_MIN);
+  MACRO(INT_MAX);
+  MACRO(INT_MIN);
+  MACRO(LLONG_MAX);
+  MACRO(LLONG_MIN);
+  MACRO(LONG_BIT);
+  MACRO(LONG_MAX);
+  MACRO(LONG_MIN);
+  MACRO(MB_LEN_MAX);
+  MACRO_VALUE(SCHAR_MAX, 127);
+  MACRO_VALUE(SCHAR_MIN, -128);
+  MACRO(SHRT_MAX);
+  MACRO(SHRT_MIN);
+  MACRO(SSIZE_MAX);
+  MACRO_VALUE(UCHAR_MAX, 255);
+  MACRO(UINT_MAX);
+  MACRO(ULLONG_MAX);
+  MACRO(ULONG_MAX);
+  MACRO(USHRT_MAX);
+  MACRO(WORD_BIT);
+
+  MACRO(NL_ARGMAX);
+  MACRO(NL_LANGMAX);
+  MACRO(NL_MSGMAX);
+  MACRO(NL_SETMAX);
+  MACRO(NL_TEXTMAX);
+  MACRO(NZERO);
+}
diff --git a/tests/headers/posix/locale_h.c b/tests/headers/posix/locale_h.c
new file mode 100644
index 0000000..68051c8
--- /dev/null
+++ b/tests/headers/posix/locale_h.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <locale.h>
+
+#include "header_checks.h"
+
+static void locale_h() {
+  TYPE(struct lconv);
+  STRUCT_MEMBER(struct lconv, char*, currency_symbol);
+  STRUCT_MEMBER(struct lconv, char*, decimal_point);
+  STRUCT_MEMBER(struct lconv, char, frac_digits);
+  STRUCT_MEMBER(struct lconv, char*, grouping);
+  STRUCT_MEMBER(struct lconv, char*, int_curr_symbol);
+  STRUCT_MEMBER(struct lconv, char, int_frac_digits);
+  STRUCT_MEMBER(struct lconv, char, int_n_cs_precedes);
+  STRUCT_MEMBER(struct lconv, char, int_n_sep_by_space);
+  STRUCT_MEMBER(struct lconv, char, int_n_sign_posn);
+  STRUCT_MEMBER(struct lconv, char, int_p_cs_precedes);
+  STRUCT_MEMBER(struct lconv, char, int_p_sep_by_space);
+  STRUCT_MEMBER(struct lconv, char, int_p_sign_posn);
+  STRUCT_MEMBER(struct lconv, char*, mon_decimal_point);
+  STRUCT_MEMBER(struct lconv, char*, mon_grouping);
+  STRUCT_MEMBER(struct lconv, char*, mon_thousands_sep);
+  STRUCT_MEMBER(struct lconv, char*, negative_sign);
+  STRUCT_MEMBER(struct lconv, char, n_cs_precedes);
+  STRUCT_MEMBER(struct lconv, char, n_sep_by_space);
+  STRUCT_MEMBER(struct lconv, char, n_sign_posn);
+  STRUCT_MEMBER(struct lconv, char*, positive_sign);
+  STRUCT_MEMBER(struct lconv, char, p_cs_precedes);
+  STRUCT_MEMBER(struct lconv, char, p_sep_by_space);
+  STRUCT_MEMBER(struct lconv, char, p_sign_posn);
+  STRUCT_MEMBER(struct lconv, char*, thousands_sep);
+
+  MACRO(NULL);
+
+  MACRO(LC_ALL);
+  MACRO(LC_COLLATE);
+  MACRO(LC_CTYPE);
+  MACRO(LC_MONETARY);
+  MACRO(LC_NUMERIC);
+  MACRO(LC_TIME);
+
+  MACRO(LC_COLLATE_MASK);
+  MACRO(LC_CTYPE_MASK);
+  MACRO(LC_MESSAGES_MASK);
+  MACRO(LC_MONETARY_MASK);
+  MACRO(LC_NUMERIC_MASK);
+  MACRO(LC_TIME_MASK);
+  MACRO(LC_ALL_MASK);
+
+  MACRO_TYPE(locale_t, LC_GLOBAL_LOCALE);
+  TYPE(locale_t);
+
+  FUNCTION(duplocale, locale_t (*f)(locale_t));
+  FUNCTION(freelocale, void (*f)(locale_t));
+  FUNCTION(localeconv, struct lconv* (*f)(void));
+  FUNCTION(newlocale, locale_t (*f)(int, const char*, locale_t));
+  FUNCTION(setlocale, char* (*f)(int, const char*));
+  FUNCTION(uselocale, locale_t (*f)(locale_t));
+}
diff --git a/tests/headers/posix/math_h.c b/tests/headers/posix/math_h.c
new file mode 100644
index 0000000..0f8ad2b
--- /dev/null
+++ b/tests/headers/posix/math_h.c
@@ -0,0 +1,346 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <math.h>
+
+#include "header_checks.h"
+
+static void math_h() {
+  TYPE(float_t);
+  TYPE(double_t);
+
+#if !defined(fpclassify)
+#error fpclassify
+#endif
+#if !defined(isfinite)
+#error isfinite
+#endif
+#if !defined(isgreater)
+#error isgreater
+#endif
+#if !defined(isgreaterequal)
+#error isgreaterequal
+#endif
+#if !defined(isinf)
+#error isinf
+#endif
+#if !defined(isless)
+#error isless
+#endif
+#if !defined(islessequal)
+#error islessequal
+#endif
+#if !defined(islessgreater)
+#error islessgreater
+#endif
+#if !defined(isnan)
+#error isnan
+#endif
+#if !defined(isnormal)
+#error isnormal
+#endif
+#if !defined(isunordered)
+#error isunordered
+#endif
+#if !defined(signbit)
+#error signbit
+#endif
+
+  MACRO(M_E);
+  MACRO(M_LOG2E);
+  MACRO(M_LOG10E);
+  MACRO(M_LN2);
+  MACRO(M_LN10);
+  MACRO(M_PI);
+  MACRO(M_PI_2);
+  MACRO(M_PI_4);
+  MACRO(M_1_PI);
+  MACRO(M_2_PI);
+  MACRO(M_2_SQRTPI);
+  MACRO(M_SQRT2);
+  MACRO(M_SQRT1_2);
+
+  MACRO(MAXFLOAT);
+
+  MACRO(HUGE_VAL);
+  MACRO(HUGE_VALF);
+  MACRO(HUGE_VALL);
+  MACRO(INFINITY);
+  MACRO(NAN);
+
+  MACRO(FP_INFINITE);
+  MACRO(FP_NAN);
+  MACRO(FP_NORMAL);
+  MACRO(FP_SUBNORMAL);
+  MACRO(FP_ZERO);
+
+#if defined(FP_FAST_FMA) && FP_FAST_FMA != 1
+#error FP_FAST_FMA
+#endif
+#if defined(FP_FAST_FMAF) && FP_FAST_FMAF != 1
+#error FP_FAST_FMAF
+#endif
+#if defined(FP_FAST_FMAL) && FP_FAST_FMAL != 1
+#error FP_FAST_FMAL
+#endif
+
+  MACRO(FP_ILOGB0);
+  MACRO(FP_ILOGBNAN);
+
+  MACRO_VALUE(MATH_ERRNO, 1);
+  MACRO_VALUE(MATH_ERREXCEPT, 2);
+
+#if !defined(math_errhandling)
+#error math_errhandling
+#endif
+  MACRO_TYPE(int, math_errhandling);
+
+  FUNCTION(acos, double (*f)(double));
+  FUNCTION(acosf, float (*f)(float));
+  FUNCTION(acosh, double (*f)(double));
+  FUNCTION(acoshf, float (*f)(float));
+  FUNCTION(acoshl, long double (*f)(long double));
+  FUNCTION(acosl, long double (*f)(long double));
+
+  FUNCTION(asin, double (*f)(double));
+  FUNCTION(asinf, float (*f)(float));
+  FUNCTION(asinh, double (*f)(double));
+  FUNCTION(asinhf, float (*f)(float));
+  FUNCTION(asinhl, long double (*f)(long double));
+  FUNCTION(asinl, long double (*f)(long double));
+
+  FUNCTION(atan, double (*f)(double));
+  FUNCTION(atan2, double (*f)(double, double));
+  FUNCTION(atan2f, float (*f)(float, float));
+  FUNCTION(atan2l, long double (*f)(long double, long double));
+  FUNCTION(atanf, float (*f)(float));
+  FUNCTION(atanh, double (*f)(double));
+  FUNCTION(atanhf, float (*f)(float));
+  FUNCTION(atanhl, long double (*f)(long double));
+  FUNCTION(atanl, long double (*f)(long double));
+
+  FUNCTION(cbrt, double (*f)(double));
+  FUNCTION(cbrtf, float (*f)(float));
+  FUNCTION(cbrtl, long double (*f)(long double));
+
+  FUNCTION(ceil, double (*f)(double));
+  FUNCTION(ceilf, float (*f)(float));
+  FUNCTION(ceill, long double (*f)(long double));
+
+  FUNCTION(copysign, double (*f)(double, double));
+  FUNCTION(copysignf, float (*f)(float, float));
+  FUNCTION(copysignl, long double (*f)(long double, long double));
+
+  FUNCTION(cos, double (*f)(double));
+  FUNCTION(cosf, float (*f)(float));
+  FUNCTION(cosh, double (*f)(double));
+  FUNCTION(coshf, float (*f)(float));
+  FUNCTION(coshl, long double (*f)(long double));
+  FUNCTION(cosl, long double (*f)(long double));
+
+  FUNCTION(erf, double (*f)(double));
+  FUNCTION(erfc, double (*f)(double));
+  FUNCTION(erfcf, float (*f)(float));
+  FUNCTION(erfcl, long double (*f)(long double));
+  FUNCTION(erff, float (*f)(float));
+  FUNCTION(erfl, long double (*f)(long double));
+
+  FUNCTION(exp, double (*f)(double));
+  FUNCTION(exp2, double (*f)(double));
+  FUNCTION(exp2f, float (*f)(float));
+  FUNCTION(exp2l, long double (*f)(long double));
+  FUNCTION(expf, float (*f)(float));
+  FUNCTION(expl, long double (*f)(long double));
+  FUNCTION(expm1, double (*f)(double));
+  FUNCTION(expm1f, float (*f)(float));
+  FUNCTION(expm1l, long double (*f)(long double));
+
+  FUNCTION(fabs, double (*f)(double));
+  FUNCTION(fabsf, float (*f)(float));
+  FUNCTION(fabsl, long double (*f)(long double));
+
+  FUNCTION(fdim, double (*f)(double, double));
+  FUNCTION(fdimf, float (*f)(float, float));
+  FUNCTION(fdiml, long double (*f)(long double, long double));
+
+  FUNCTION(floor, double (*f)(double));
+  FUNCTION(floorf, float (*f)(float));
+  FUNCTION(floorl, long double (*f)(long double));
+
+  FUNCTION(fma, double (*f)(double, double, double));
+  FUNCTION(fmaf, float (*f)(float, float, float));
+  FUNCTION(fmal, long double (*f)(long double, long double, long double));
+
+  FUNCTION(fmax, double (*f)(double, double));
+  FUNCTION(fmaxf, float (*f)(float, float));
+  FUNCTION(fmaxl, long double (*f)(long double, long double));
+
+  FUNCTION(fmin, double (*f)(double, double));
+  FUNCTION(fminf, float (*f)(float, float));
+  FUNCTION(fminl, long double (*f)(long double, long double));
+
+  FUNCTION(fmod, double (*f)(double, double));
+  FUNCTION(fmodf, float (*f)(float, float));
+  FUNCTION(fmodl, long double (*f)(long double, long double));
+
+  FUNCTION(frexp, double (*f)(double, int*));
+  FUNCTION(frexpf, float (*f)(float, int*));
+  FUNCTION(frexpl, long double (*f)(long double, int*));
+
+  FUNCTION(hypot, double (*f)(double, double));
+  FUNCTION(hypotf, float (*f)(float, float));
+  FUNCTION(hypotl, long double (*f)(long double, long double));
+
+  FUNCTION(ilogb, int (*f)(double));
+  FUNCTION(ilogbf, int (*f)(float));
+  FUNCTION(ilogbl, int (*f)(long double));
+
+  FUNCTION(j0, double (*f)(double));
+  FUNCTION(j1, double (*f)(double));
+  FUNCTION(jn, double (*f)(int, double));
+
+  FUNCTION(ldexp, double (*f)(double, int));
+  FUNCTION(ldexpf, float (*f)(float, int));
+  FUNCTION(ldexpl, long double (*f)(long double, int));
+
+  FUNCTION(lgamma, double (*f)(double));
+  FUNCTION(lgammaf, float (*f)(float));
+  FUNCTION(lgammal, long double (*f)(long double));
+
+  FUNCTION(llrint, long long (*f)(double));
+  FUNCTION(llrintf, long long (*f)(float));
+  FUNCTION(llrintl, long long (*f)(long double));
+
+  FUNCTION(llround, long long (*f)(double));
+  FUNCTION(llroundf, long long (*f)(float));
+  FUNCTION(llroundl, long long (*f)(long double));
+
+  FUNCTION(log, double (*f)(double));
+  FUNCTION(log10, double (*f)(double));
+  FUNCTION(log10f, float (*f)(float));
+  FUNCTION(log10l, long double (*f)(long double));
+  FUNCTION(log1p, double (*f)(double));
+  FUNCTION(log1pf, float (*f)(float));
+  FUNCTION(log1pl, long double (*f)(long double));
+  FUNCTION(log2, double (*f)(double));
+  FUNCTION(log2f, float (*f)(float));
+  FUNCTION(log2l, long double (*f)(long double));
+  FUNCTION(logb, double (*f)(double));
+  FUNCTION(logbf, float (*f)(float));
+  FUNCTION(logbl, long double (*f)(long double));
+  FUNCTION(logf, float (*f)(float));
+  FUNCTION(logl, long double (*f)(long double));
+
+  FUNCTION(lrint, long (*f)(double));
+  FUNCTION(lrintf, long (*f)(float));
+  FUNCTION(lrintl, long (*f)(long double));
+
+  FUNCTION(lround, long (*f)(double));
+  FUNCTION(lroundf, long (*f)(float));
+  FUNCTION(lroundl, long (*f)(long double));
+
+  FUNCTION(modf, double (*f)(double, double*));
+  FUNCTION(modff, float (*f)(float, float*));
+  FUNCTION(modfl, long double (*f)(long double, long double*));
+
+  FUNCTION(nan, double (*f)(const char*));
+  FUNCTION(nanf, float (*f)(const char*));
+  FUNCTION(nanl, long double (*f)(const char*));
+
+  FUNCTION(nearbyint, double (*f)(double));
+  FUNCTION(nearbyintf, float (*f)(float));
+  FUNCTION(nearbyintl, long double (*f)(long double));
+
+  FUNCTION(nextafter, double (*f)(double, double));
+  FUNCTION(nextafterf, float (*f)(float, float));
+  FUNCTION(nextafterl, long double (*f)(long double, long double));
+
+  FUNCTION(nexttoward, double (*f)(double, long double));
+  FUNCTION(nexttowardf, float (*f)(float, long double));
+  FUNCTION(nexttowardl, long double (*f)(long double, long double));
+
+  FUNCTION(pow, double (*f)(double, double));
+  FUNCTION(powf, float (*f)(float, float));
+  FUNCTION(powl, long double (*f)(long double, long double));
+
+  FUNCTION(remainder, double (*f)(double, double));
+  FUNCTION(remainderf, float (*f)(float, float));
+  FUNCTION(remainderl, long double (*f)(long double, long double));
+
+  FUNCTION(remquo, double (*f)(double, double, int*));
+  FUNCTION(remquof, float (*f)(float, float, int*));
+  FUNCTION(remquol, long double (*f)(long double, long double, int*));
+
+  FUNCTION(rint, double (*f)(double));
+  FUNCTION(rintf, float (*f)(float));
+  FUNCTION(rintl, long double (*f)(long double));
+
+  FUNCTION(round, double (*f)(double));
+  FUNCTION(roundf, float (*f)(float));
+  FUNCTION(roundl, long double (*f)(long double));
+
+  FUNCTION(scalbln, double (*f)(double, long));
+  FUNCTION(scalblnf, float (*f)(float, long));
+  FUNCTION(scalblnl, long double (*f)(long double, long));
+
+  FUNCTION(scalbn, double (*f)(double, int));
+  FUNCTION(scalbnf, float (*f)(float, int));
+  FUNCTION(scalbnl, long double (*f)(long double, int));
+
+  FUNCTION(sin, double (*f)(double));
+  FUNCTION(sinf, float (*f)(float));
+  FUNCTION(sinh, double (*f)(double));
+  FUNCTION(sinhf, float (*f)(float));
+  FUNCTION(sinhl, long double (*f)(long double));
+  FUNCTION(sinl, long double (*f)(long double));
+
+  FUNCTION(sqrt, double (*f)(double));
+  FUNCTION(sqrtf, float (*f)(float));
+  FUNCTION(sqrtl, long double (*f)(long double));
+
+  FUNCTION(tan, double (*f)(double));
+  FUNCTION(tanf, float (*f)(float));
+  FUNCTION(tanh, double (*f)(double));
+  FUNCTION(tanhf, float (*f)(float));
+  FUNCTION(tanhl, long double (*f)(long double));
+  FUNCTION(tanl, long double (*f)(long double));
+
+  FUNCTION(tgamma, double (*f)(double));
+  FUNCTION(tgammaf, float (*f)(float));
+  FUNCTION(tgammal, long double (*f)(long double));
+
+  FUNCTION(trunc, double (*f)(double));
+  FUNCTION(truncf, float (*f)(float));
+  FUNCTION(truncl, long double (*f)(long double));
+
+  FUNCTION(y0, double (*f)(double));
+  FUNCTION(y1, double (*f)(double));
+  FUNCTION(yn, double (*f)(int, double));
+
+  int s = signgam;
+}
diff --git a/tests/headers/posix/net_if_h.c b/tests/headers/posix/net_if_h.c
new file mode 100644
index 0000000..4b3df18
--- /dev/null
+++ b/tests/headers/posix/net_if_h.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <net/if.h>
+
+#include "header_checks.h"
+
+static void net_if_h() {
+  TYPE(struct if_nameindex);
+  STRUCT_MEMBER(struct if_nameindex, unsigned, if_index);
+  STRUCT_MEMBER(struct if_nameindex, char*, if_name);
+
+  MACRO(IF_NAMESIZE);
+
+  FUNCTION(if_freenameindex, void (*f)(struct if_nameindex*));
+  FUNCTION(if_indextoname, char* (*f)(unsigned, char*));
+  FUNCTION(if_nameindex, struct if_nameindex* (*f)(void));
+  FUNCTION(if_nametoindex, unsigned (*f)(const char*));
+}
diff --git a/tests/headers/posix/netdb_h.c b/tests/headers/posix/netdb_h.c
new file mode 100644
index 0000000..62fd083
--- /dev/null
+++ b/tests/headers/posix/netdb_h.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <netdb.h>
+
+#include "header_checks.h"
+
+static void netdb_h() {
+  TYPE(struct hostent);
+  STRUCT_MEMBER(struct hostent, char*, h_name);
+  STRUCT_MEMBER(struct hostent, char**, h_aliases);
+  STRUCT_MEMBER(struct hostent, int, h_addrtype);
+  STRUCT_MEMBER(struct hostent, int, h_length);
+  STRUCT_MEMBER(struct hostent, char**, h_addr_list);
+
+  TYPE(struct netent);
+  STRUCT_MEMBER(struct netent, char*, n_name);
+  STRUCT_MEMBER(struct netent, char**, n_aliases);
+  STRUCT_MEMBER(struct netent, int, n_addrtype);
+  STRUCT_MEMBER(struct netent, uint32_t, n_net);
+
+  TYPE(uint32_t);
+
+  TYPE(struct protoent);
+  STRUCT_MEMBER(struct protoent, char*, p_name);
+  STRUCT_MEMBER(struct protoent, char**, p_aliases);
+  STRUCT_MEMBER(struct protoent, int, p_proto);
+
+
+  TYPE(struct servent);
+  STRUCT_MEMBER(struct servent, char*, s_name);
+  STRUCT_MEMBER(struct servent, char**, s_aliases);
+  STRUCT_MEMBER(struct servent, int, s_port);
+  STRUCT_MEMBER(struct servent, char*, s_proto);
+
+  MACRO(IPPORT_RESERVED);
+
+  TYPE(struct addrinfo);
+  STRUCT_MEMBER(struct addrinfo, int, ai_flags);
+  STRUCT_MEMBER(struct addrinfo, int, ai_family);
+  STRUCT_MEMBER(struct addrinfo, int, ai_socktype);
+  STRUCT_MEMBER(struct addrinfo, int, ai_protocol);
+  STRUCT_MEMBER(struct addrinfo, socklen_t, ai_addrlen);
+  STRUCT_MEMBER(struct addrinfo, struct sockaddr*, ai_addr);
+  STRUCT_MEMBER(struct addrinfo, char*, ai_canonname);
+  STRUCT_MEMBER(struct addrinfo, struct addrinfo*, ai_next);
+
+  MACRO(AI_PASSIVE);
+  MACRO(AI_CANONNAME);
+  MACRO(AI_NUMERICHOST);
+  MACRO(AI_NUMERICSERV);
+  MACRO(AI_V4MAPPED);
+  MACRO(AI_ALL);
+  MACRO(AI_ADDRCONFIG);
+
+  MACRO(NI_NOFQDN);
+  MACRO(NI_NUMERICHOST);
+  MACRO(NI_NAMEREQD);
+  MACRO(NI_NUMERICSERV);
+#if !defined(__BIONIC__) && !defined(__GLIBC__)
+  MACRO(NI_NUMERICSCOPE);
+#endif
+  MACRO(NI_DGRAM);
+
+  MACRO(EAI_AGAIN);
+  MACRO(EAI_BADFLAGS);
+  MACRO(EAI_FAIL);
+  MACRO(EAI_FAMILY);
+  MACRO(EAI_MEMORY);
+  MACRO(EAI_NONAME);
+  MACRO(EAI_SERVICE);
+  MACRO(EAI_SOCKTYPE);
+  MACRO(EAI_SYSTEM);
+  MACRO(EAI_OVERFLOW);
+
+  FUNCTION(endhostent, void (*f)(void));
+  FUNCTION(endnetent, void (*f)(void));
+  FUNCTION(endprotoent, void (*f)(void));
+  FUNCTION(endservent, void (*f)(void));
+  FUNCTION(freeaddrinfo, void (*f)(struct addrinfo*));
+  FUNCTION(gai_strerror, const char* (*f)(int));
+  FUNCTION(getaddrinfo, int (*f)(const char*, const char*, const struct addrinfo*, struct addrinfo**));
+  FUNCTION(gethostent, struct hostent* (*f)(void));
+#if defined(__BIONIC__) // Historical ABI accident.
+  FUNCTION(getnameinfo, int (*f)(const struct sockaddr*, socklen_t, char*, size_t, char*, size_t, int));
+#else
+  FUNCTION(getnameinfo, int (*f)(const struct sockaddr*, socklen_t, char*, socklen_t, char*, socklen_t, int));
+#endif
+  FUNCTION(getnetbyaddr, struct netent* (*f)(uint32_t, int));
+  FUNCTION(getnetbyname, struct netent* (*f)(const char*));
+  FUNCTION(getnetent, struct netent* (*f)(void));
+  FUNCTION(getprotobyname, struct protoent* (*f)(const char*));
+  FUNCTION(getprotobynumber, struct protoent* (*f)(int));
+  FUNCTION(getprotoent, struct protoent* (*f)(void));
+  FUNCTION(getservbyname, struct servent* (*f)(const char*, const char*));
+  FUNCTION(getservbyport, struct servent* (*f)(int, const char*));
+  FUNCTION(getservent, struct servent* (*f)(void));
+  FUNCTION(sethostent, void (*f)(int));
+  FUNCTION(setnetent, void (*f)(int));
+  FUNCTION(setprotoent, void (*f)(int));
+  FUNCTION(setservent, void (*f)(int));
+
+  TYPE(socklen_t);
+}
diff --git a/tests/headers/posix/netinet_in_h.c b/tests/headers/posix/netinet_in_h.c
new file mode 100644
index 0000000..cd89685
--- /dev/null
+++ b/tests/headers/posix/netinet_in_h.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <netinet/in.h>
+
+#include "header_checks.h"
+
+static void netinet_in_h() {
+  TYPE(in_port_t);
+  TYPE(in_addr_t);
+  TYPE(sa_family_t);
+  TYPE(uint8_t);
+  TYPE(uint32_t);
+
+  TYPE(struct in_addr);
+  STRUCT_MEMBER(struct in_addr, in_addr_t, s_addr);
+
+  TYPE(struct sockaddr_in);
+  STRUCT_MEMBER(struct sockaddr_in, sa_family_t, sin_family);
+  STRUCT_MEMBER(struct sockaddr_in, in_port_t, sin_port);
+  STRUCT_MEMBER(struct sockaddr_in, struct in_addr, sin_addr);
+
+  TYPE(struct in6_addr);
+  STRUCT_MEMBER_ARRAY(struct in6_addr, uint8_t/*[]*/, s6_addr);
+
+  TYPE(struct sockaddr_in6);
+  STRUCT_MEMBER(struct sockaddr_in6, sa_family_t, sin6_family);
+  STRUCT_MEMBER(struct sockaddr_in6, in_port_t, sin6_port);
+  STRUCT_MEMBER(struct sockaddr_in6, uint32_t, sin6_flowinfo);
+  STRUCT_MEMBER(struct sockaddr_in6, struct in6_addr, sin6_addr);
+  STRUCT_MEMBER(struct sockaddr_in6, uint32_t, sin6_scope_id);
+
+  struct in6_addr any_global = in6addr_any;
+  struct in6_addr any_macro = IN6ADDR_ANY_INIT;
+  struct in6_addr loop_global = in6addr_loopback;
+  struct in6_addr loop_macro = IN6ADDR_LOOPBACK_INIT;
+
+  TYPE(struct ipv6_mreq);
+  STRUCT_MEMBER(struct ipv6_mreq, struct in6_addr, ipv6mr_multiaddr);
+#if defined(__BIONIC__) // Currently comes from uapi header.
+  STRUCT_MEMBER(struct ipv6_mreq, int, ipv6mr_interface);
+#else
+  STRUCT_MEMBER(struct ipv6_mreq, unsigned, ipv6mr_interface);
+#endif
+
+  MACRO(IPPROTO_IP);
+  MACRO(IPPROTO_IPV6);
+  MACRO(IPPROTO_ICMP);
+  MACRO(IPPROTO_RAW);
+  MACRO(IPPROTO_TCP);
+  MACRO(IPPROTO_UDP);
+
+  MACRO(INADDR_ANY);
+  MACRO(INADDR_BROADCAST);
+
+  MACRO_VALUE(INET_ADDRSTRLEN, 16);
+
+  FUNCTION(htonl, uint32_t (*f)(uint32_t));
+  FUNCTION(htons, uint16_t (*f)(uint16_t));
+  FUNCTION(ntohl, uint32_t (*f)(uint32_t));
+  FUNCTION(ntohs, uint16_t (*f)(uint16_t));
+
+  MACRO_VALUE(INET6_ADDRSTRLEN, 46);
+
+  MACRO(IPV6_JOIN_GROUP);
+  MACRO(IPV6_LEAVE_GROUP);
+  MACRO(IPV6_MULTICAST_HOPS);
+  MACRO(IPV6_MULTICAST_IF);
+  MACRO(IPV6_MULTICAST_LOOP);
+  MACRO(IPV6_UNICAST_HOPS);
+  MACRO(IPV6_V6ONLY);
+
+#if !defined(IN6_IS_ADDR_UNSPECIFIED)
+#error IN6_IS_ADDR_UNSPECIFIED
+#endif
+#if !defined(IN6_IS_ADDR_LOOPBACK)
+#error IN6_IS_ADDR_LOOPBACK
+#endif
+#if !defined(IN6_IS_ADDR_MULTICAST)
+#error IN6_IS_ADDR_MULTICAST
+#endif
+#if !defined(IN6_IS_ADDR_LINKLOCAL)
+#error IN6_IS_ADDR_LINKLOCAL
+#endif
+#if !defined(IN6_IS_ADDR_SITELOCAL)
+#error IN6_IS_ADDR_SITELOCAL
+#endif
+#if !defined(IN6_IS_ADDR_V4MAPPED)
+#error IN6_IS_ADDR_V4MAPPED
+#endif
+#if !defined(IN6_IS_ADDR_V4COMPAT)
+#error IN6_IS_ADDR_V4COMPAT
+#endif
+#if !defined(IN6_IS_ADDR_MC_NODELOCAL)
+#error IN6_IS_ADDR_MC_NODELOCAL
+#endif
+#if !defined(IN6_IS_ADDR_MC_LINKLOCAL)
+#error IN6_IS_ADDR_MC_LINKLOCAL
+#endif
+#if !defined(IN6_IS_ADDR_MC_SITELOCAL)
+#error IN6_IS_ADDR_MC_SITELOCAL
+#endif
+#if !defined(IN6_IS_ADDR_MC_ORGLOCAL)
+#error IN6_IS_ADDR_MC_ORGLOCAL
+#endif
+#if !defined(IN6_IS_ADDR_MC_GLOBAL)
+#error IN6_IS_ADDR_MC_GLOBAL
+#endif
+}
diff --git a/tests/headers/posix/netinet_tcp_h.c b/tests/headers/posix/netinet_tcp_h.c
new file mode 100644
index 0000000..afb6418
--- /dev/null
+++ b/tests/headers/posix/netinet_tcp_h.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <netinet/tcp.h>
+
+#include "header_checks.h"
+
+static void netinet_tcp_h() {
+  MACRO(TCP_NODELAY);
+}
diff --git a/tests/headers/posix/nl_types_h.c b/tests/headers/posix/nl_types_h.c
new file mode 100644
index 0000000..5a3c817
--- /dev/null
+++ b/tests/headers/posix/nl_types_h.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <nl_types.h>
+
+#include "header_checks.h"
+
+static void nl_types_h() {
+  TYPE(nl_catd);
+  TYPE(nl_item);
+
+  MACRO(NL_SETD);
+  MACRO(NL_CAT_LOCALE);
+
+  FUNCTION(catclose, int (*f)(nl_catd));
+  FUNCTION(catgets, char* (*f)(nl_catd, int, int, const char*));
+  FUNCTION(catopen, nl_catd (*f)(const char*, int));
+}
diff --git a/tests/headers/posix/poll_h.c b/tests/headers/posix/poll_h.c
new file mode 100644
index 0000000..4fce5e5
--- /dev/null
+++ b/tests/headers/posix/poll_h.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <poll.h>
+
+#include "header_checks.h"
+
+static void poll_h() {
+  TYPE(struct pollfd);
+  STRUCT_MEMBER(struct pollfd, int, fd);
+  STRUCT_MEMBER(struct pollfd, short, events);
+  STRUCT_MEMBER(struct pollfd, short, revents);
+
+  TYPE(nfds_t);
+
+  MACRO(POLLIN);
+  MACRO(POLLRDNORM);
+  MACRO(POLLRDBAND);
+  MACRO(POLLPRI);
+  MACRO(POLLOUT);
+  MACRO(POLLWRNORM);
+  MACRO(POLLWRBAND);
+  MACRO(POLLERR);
+  MACRO(POLLHUP);
+  MACRO(POLLNVAL);
+
+  FUNCTION(poll, int (*f)(struct pollfd[], nfds_t, int));
+}
diff --git a/tests/headers/posix/pthread_h.c b/tests/headers/posix/pthread_h.c
new file mode 100644
index 0000000..4fa5b9d
--- /dev/null
+++ b/tests/headers/posix/pthread_h.c
@@ -0,0 +1,226 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <pthread.h>
+
+#include "header_checks.h"
+
+static void pthread_h() {
+  MACRO(PTHREAD_BARRIER_SERIAL_THREAD);
+
+#if !defined(__BIONIC__) // No thread cancellation on Android.
+  MACRO(PTHREAD_CANCEL_ASYNCHRONOUS);
+  MACRO(PTHREAD_CANCEL_ENABLE);
+  MACRO(PTHREAD_CANCEL_DEFERRED);
+  MACRO(PTHREAD_CANCEL_DISABLE);
+  MACRO(PTHREAD_CANCELED);
+#endif
+
+  MACRO(PTHREAD_CREATE_DETACHED);
+  MACRO(PTHREAD_CREATE_JOINABLE);
+  MACRO(PTHREAD_EXPLICIT_SCHED);
+  MACRO(PTHREAD_INHERIT_SCHED);
+  MACRO(PTHREAD_MUTEX_DEFAULT);
+  MACRO(PTHREAD_MUTEX_ERRORCHECK);
+  MACRO(PTHREAD_MUTEX_NORMAL);
+  MACRO(PTHREAD_MUTEX_RECURSIVE);
+
+#if !defined(__BIONIC__) // No robust mutexes on Android.
+  MACRO(PTHREAD_MUTEX_ROBUST);
+  MACRO(PTHREAD_MUTEX_STALLED);
+#endif
+
+  MACRO(PTHREAD_ONCE_INIT);
+
+#if !defined(__BIONIC__) // No robust mutexes on Android.
+  MACRO(PTHREAD_PRIO_INHERIT);
+  MACRO(PTHREAD_PRIO_NONE);
+  MACRO(PTHREAD_PRIO_PROTECT);
+#endif
+
+  MACRO(PTHREAD_PROCESS_SHARED);
+  MACRO(PTHREAD_PROCESS_PRIVATE);
+  MACRO(PTHREAD_SCOPE_PROCESS);
+  MACRO(PTHREAD_SCOPE_SYSTEM);
+
+  pthread_cond_t c0 = PTHREAD_COND_INITIALIZER;
+  pthread_mutex_t m0 = PTHREAD_MUTEX_INITIALIZER;
+  pthread_rwlock_t rw0 = PTHREAD_RWLOCK_INITIALIZER;
+
+  TYPE(pthread_attr_t);
+  TYPE(pthread_barrier_t);
+  TYPE(pthread_barrierattr_t);
+  TYPE(pthread_cond_t);
+  TYPE(pthread_condattr_t);
+  TYPE(pthread_key_t);
+  TYPE(pthread_mutex_t);
+  TYPE(pthread_mutexattr_t);
+  TYPE(pthread_once_t);
+  TYPE(pthread_rwlock_t);
+  TYPE(pthread_rwlockattr_t);
+  TYPE(pthread_spinlock_t);
+  TYPE(pthread_t);
+
+  FUNCTION(pthread_atfork, int (*f)(void (*)(void), void (*)(void), void (*)(void)));
+  FUNCTION(pthread_attr_destroy, int (*f)(pthread_attr_t*));
+  FUNCTION(pthread_attr_getdetachstate, int (*f)(const pthread_attr_t*, int*));
+  FUNCTION(pthread_attr_getguardsize, int (*f)(const pthread_attr_t*, size_t*));
+  FUNCTION(pthread_attr_getinheritsched, int (*f)(const pthread_attr_t*, int*));
+  FUNCTION(pthread_attr_getschedparam, int (*f)(const pthread_attr_t*, struct sched_param*));
+  FUNCTION(pthread_attr_getschedpolicy, int (*f)(const pthread_attr_t*, int*));
+  FUNCTION(pthread_attr_getscope, int (*f)(const pthread_attr_t*, int*));
+  FUNCTION(pthread_attr_getstack, int (*f)(const pthread_attr_t*, void**, size_t*));
+  FUNCTION(pthread_attr_getstacksize, int (*f)(const pthread_attr_t*, size_t*));
+  FUNCTION(pthread_attr_init, int (*f)(pthread_attr_t*));
+  FUNCTION(pthread_attr_setdetachstate, int (*f)(pthread_attr_t*, int));
+  FUNCTION(pthread_attr_setguardsize, int (*f)(pthread_attr_t*, size_t));
+  FUNCTION(pthread_attr_setinheritsched, int (*f)(pthread_attr_t*, int));
+  FUNCTION(pthread_attr_setschedparam, int (*f)(pthread_attr_t*, const struct sched_param*));
+  FUNCTION(pthread_attr_setschedpolicy, int (*f)(pthread_attr_t*, int));
+  FUNCTION(pthread_attr_setscope, int (*f)(pthread_attr_t*, int));
+  FUNCTION(pthread_attr_setstack, int (*f)(pthread_attr_t*, void*, size_t));
+  FUNCTION(pthread_attr_setstacksize, int (*f)(pthread_attr_t*, size_t));
+  FUNCTION(pthread_barrier_destroy, int (*f)(pthread_barrier_t*));
+  FUNCTION(pthread_barrier_init, int (*f)(pthread_barrier_t*, const pthread_barrierattr_t*, unsigned));
+  FUNCTION(pthread_barrier_wait, int (*f)(pthread_barrier_t*));
+  FUNCTION(pthread_barrierattr_destroy, int (*f)(pthread_barrierattr_t*));
+  FUNCTION(pthread_barrierattr_getpshared, int (*f)(const pthread_barrierattr_t*, int*));
+  FUNCTION(pthread_barrierattr_init, int (*f)(pthread_barrierattr_t*));
+  FUNCTION(pthread_barrierattr_setpshared, int (*f)(pthread_barrierattr_t*, int));
+#if !defined(__BIONIC__) // No thread cancellation on Android.
+  FUNCTION(pthread_cancel, int (*f)(pthread_t));
+#endif
+  FUNCTION(pthread_cond_broadcast, int (*f)(pthread_cond_t*));
+  FUNCTION(pthread_cond_destroy, int (*f)(pthread_cond_t*));
+  FUNCTION(pthread_cond_init, int (*f)(pthread_cond_t*, const pthread_condattr_t*));
+  FUNCTION(pthread_cond_signal, int (*f)(pthread_cond_t*));
+  FUNCTION(pthread_cond_timedwait, int (*f)(pthread_cond_t*, pthread_mutex_t*, const struct timespec*));
+  FUNCTION(pthread_cond_wait, int (*f)(pthread_cond_t*, pthread_mutex_t*));
+  FUNCTION(pthread_condattr_destroy, int (*f)(pthread_condattr_t*));
+  FUNCTION(pthread_condattr_getclock, int (*f)(const pthread_condattr_t*, clockid_t*));
+  FUNCTION(pthread_condattr_getpshared, int (*f)(const pthread_condattr_t*, int*));
+  FUNCTION(pthread_condattr_init, int (*f)(pthread_condattr_t*));
+  FUNCTION(pthread_condattr_setclock, int (*f)(pthread_condattr_t*, clockid_t));
+  FUNCTION(pthread_condattr_setpshared, int (*f)(pthread_condattr_t*, int));
+  FUNCTION(pthread_create, int (*f)(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*));
+  FUNCTION(pthread_detach, int (*f)(pthread_t));
+  FUNCTION(pthread_equal, int (*f)(pthread_t, pthread_t));
+  FUNCTION(pthread_exit, void (*f)(void*));
+#if !defined(__BIONIC__) // Marked obsolescent.
+  FUNCTION(pthread_getconcurrency, int (*f)(void));
+#endif
+  FUNCTION(pthread_getcpuclockid, int (*f)(pthread_t, clockid_t*));
+  FUNCTION(pthread_getschedparam, int (*f)(pthread_t, int*, struct sched_param*));
+  FUNCTION(pthread_getspecific, void* (*f)(pthread_key_t));
+  FUNCTION(pthread_join, int (*f)(pthread_t, void**));
+  FUNCTION(pthread_key_create, int (*f)(pthread_key_t*, void (*)(void*)));
+  FUNCTION(pthread_key_delete, int (*f)(pthread_key_t));
+#if !defined(__BIONIC__) // No robust mutexes on Android.
+  FUNCTION(pthread_mutex_consistent, int (*f)(pthread_mutex_t*));
+#endif
+  FUNCTION(pthread_mutex_destroy, int (*f)(pthread_mutex_t*));
+#if !defined(__BIONIC__) // No robust mutexes on Android.
+  FUNCTION(pthread_mutex_getprioceiling, int (*f)(const pthread_mutex_t*, int*));
+#endif
+  FUNCTION(pthread_mutex_init, int (*f)(pthread_mutex_t*, const pthread_mutexattr_t*));
+  FUNCTION(pthread_mutex_lock, int (*f)(pthread_mutex_t*));
+#if !defined(__BIONIC__) // No robust mutexes on Android.
+  FUNCTION(pthread_mutex_setprioceiling, int (*f)(pthread_mutex_t*, int, int*));
+#endif
+  FUNCTION(pthread_mutex_timedlock, int (*f)(pthread_mutex_t*, const struct timespec*));
+  FUNCTION(pthread_mutex_trylock, int (*f)(pthread_mutex_t*));
+  FUNCTION(pthread_mutex_unlock, int (*f)(pthread_mutex_t*));
+  FUNCTION(pthread_mutexattr_destroy, int (*f)(pthread_mutexattr_t*));
+#if !defined(__BIONIC__) // No robust mutexes on Android.
+  FUNCTION(pthread_mutexattr_getprioceiling, int (*f)(const pthread_mutexattr_t*, int*));
+  FUNCTION(pthread_mutexattr_getprotocol, int (*f)(const pthread_mutexattr_t*, int*));
+#endif
+  FUNCTION(pthread_mutexattr_getpshared, int (*f)(const pthread_mutexattr_t*, int*));
+#if !defined(__BIONIC__) // No robust mutexes on Android.
+  FUNCTION(pthread_mutexattr_getrobust, int (*f)(const pthread_mutexattr_t*, int*));
+#endif
+  FUNCTION(pthread_mutexattr_gettype, int (*f)(const pthread_mutexattr_t*, int*));
+  FUNCTION(pthread_mutexattr_init, int (*f)(pthread_mutexattr_t*));
+#if !defined(__BIONIC__) // No robust mutexes on Android.
+  FUNCTION(pthread_mutexattr_setprioceiling, int (*f)(pthread_mutexattr_t*, int));
+  FUNCTION(pthread_mutexattr_setprotocol, int (*f)(pthread_mutexattr_t*, int));
+#endif
+  FUNCTION(pthread_mutexattr_setpshared, int (*f)(pthread_mutexattr_t*, int));
+#if !defined(__BIONIC__) // No robust mutexes on Android.
+  FUNCTION(pthread_mutexattr_setrobust, int (*f)(pthread_mutexattr_t*, int));
+#endif
+  FUNCTION(pthread_mutexattr_settype, int (*f)(pthread_mutexattr_t*, int));
+  FUNCTION(pthread_once, int (*f)(pthread_once_t*, void (*)(void)));
+  FUNCTION(pthread_rwlock_destroy, int (*f)(pthread_rwlock_t*));
+  FUNCTION(pthread_rwlock_init, int (*f)(pthread_rwlock_t*, const pthread_rwlockattr_t*));
+  FUNCTION(pthread_rwlock_rdlock, int (*f)(pthread_rwlock_t*));
+  FUNCTION(pthread_rwlock_timedrdlock, int (*f)(pthread_rwlock_t*, const struct timespec*));
+  FUNCTION(pthread_rwlock_timedwrlock, int (*f)(pthread_rwlock_t*, const struct timespec*));
+  FUNCTION(pthread_rwlock_tryrdlock, int (*f)(pthread_rwlock_t*));
+  FUNCTION(pthread_rwlock_trywrlock, int (*f)(pthread_rwlock_t*));
+  FUNCTION(pthread_rwlock_unlock, int (*f)(pthread_rwlock_t*));
+  FUNCTION(pthread_rwlock_wrlock, int (*f)(pthread_rwlock_t*));
+  FUNCTION(pthread_rwlockattr_destroy, int (*f)(pthread_rwlockattr_t*));
+  FUNCTION(pthread_rwlockattr_getpshared, int (*f)(const pthread_rwlockattr_t*, int*));
+  FUNCTION(pthread_rwlockattr_init, int (*f)(pthread_rwlockattr_t*));
+  FUNCTION(pthread_rwlockattr_setpshared, int (*f)(pthread_rwlockattr_t*, int));
+  FUNCTION(pthread_self, pthread_t (*f)(void));
+#if !defined(__BIONIC__) // No thread cancellation on Android.
+  FUNCTION(pthread_setcancelstate, int (*f)(int, int*));
+  FUNCTION(pthread_setcanceltype, int (*f)(int, int*));
+#endif
+#if !defined(__BIONIC__) // Marked obsolescent.
+  FUNCTION(pthread_setconcurrency, int (*f)(int));
+#endif
+  FUNCTION(pthread_setschedparam, int (*f)(pthread_t, int, const struct sched_param*));
+  FUNCTION(pthread_setschedprio, int (*f)(pthread_t, int));
+  FUNCTION(pthread_setspecific, int (*f)(pthread_key_t, const void*));
+  FUNCTION(pthread_spin_destroy, int (*f)(pthread_spinlock_t*));
+  FUNCTION(pthread_spin_init, int (*f)(pthread_spinlock_t*, int));
+  FUNCTION(pthread_spin_lock, int (*f)(pthread_spinlock_t*));
+  FUNCTION(pthread_spin_trylock, int (*f)(pthread_spinlock_t*));
+  FUNCTION(pthread_spin_unlock, int (*f)(pthread_spinlock_t*));
+#if !defined(__BIONIC__) // No thread cancellation on Android.
+  FUNCTION(pthread_testcancel, void (*f)(void));
+#endif
+
+#if !defined(pthread_cleanup_pop)
+#error pthread_cleanup_pop
+#endif
+#if !defined(pthread_cleanup_push)
+#error pthread_cleanup_push
+#endif
+}
+
+// POSIX: "Inclusion of the <pthread.h> header shall make symbols defined in the
+// headers <sched.h> and <time.h> visible."
+
+#define DO_NOT_INCLUDE_SCHED_H
+#include "sched_h.c"
+#define DO_NOT_INCLUDE_TIME_H
+#include "time_h.c"
diff --git a/tests/headers/posix/pwd_h.c b/tests/headers/posix/pwd_h.c
new file mode 100644
index 0000000..3d20865
--- /dev/null
+++ b/tests/headers/posix/pwd_h.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <pwd.h>
+
+#include "header_checks.h"
+
+static void pwd_h() {
+  TYPE(struct passwd);
+  STRUCT_MEMBER(struct passwd, char*, pw_name);
+  STRUCT_MEMBER(struct passwd, uid_t, pw_uid);
+  STRUCT_MEMBER(struct passwd, gid_t, pw_gid);
+  STRUCT_MEMBER(struct passwd, char*, pw_dir);
+  STRUCT_MEMBER(struct passwd, char*, pw_shell);
+
+  TYPE(gid_t);
+  TYPE(uid_t);
+  TYPE(size_t);
+
+  FUNCTION(endpwent, void (*f)(void));
+  FUNCTION(getpwent, struct passwd* (*f)(void));
+  FUNCTION(getpwnam, struct passwd* (*f)(const char*));
+  FUNCTION(getpwnam_r, int (*f)(const char*, struct passwd*, char*, size_t, struct passwd**));
+  FUNCTION(getpwuid, struct passwd* (*f)(uid_t));
+  FUNCTION(getpwuid_r, int (*f)(uid_t, struct passwd*, char*, size_t, struct passwd**));
+  FUNCTION(setpwent, void (*f)(void));
+}
diff --git a/tests/headers/posix/regex_h.c b/tests/headers/posix/regex_h.c
new file mode 100644
index 0000000..381004c
--- /dev/null
+++ b/tests/headers/posix/regex_h.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <regex.h>
+
+#include "header_checks.h"
+
+static void regex_h() {
+  TYPE(regex_t);
+  STRUCT_MEMBER(regex_t, size_t, re_nsub);
+
+  TYPE(size_t);
+
+  TYPE(regmatch_t);
+  STRUCT_MEMBER(regmatch_t, regoff_t, rm_so);
+  STRUCT_MEMBER(regmatch_t, regoff_t, rm_eo);
+
+  MACRO(REG_EXTENDED);
+  MACRO(REG_ICASE);
+  MACRO(REG_NOSUB);
+  MACRO(REG_NEWLINE);
+
+  MACRO(REG_NOTBOL);
+  MACRO(REG_NOTEOL);
+
+  MACRO(REG_NOMATCH);
+  MACRO(REG_BADPAT);
+  MACRO(REG_ECOLLATE);
+  MACRO(REG_ECTYPE);
+  MACRO(REG_EESCAPE);
+  MACRO(REG_ESUBREG);
+  MACRO(REG_EBRACK);
+  MACRO(REG_EPAREN);
+  MACRO(REG_EBRACE);
+  MACRO(REG_BADBR);
+  MACRO(REG_ERANGE);
+  MACRO(REG_ESPACE);
+  MACRO(REG_BADRPT);
+
+  FUNCTION(regcomp, int (*f)(regex_t*, const char*, int));
+  FUNCTION(regerror, size_t (*f)(int, const regex_t*, char*, size_t));
+  FUNCTION(regexec, int (*f)(const regex_t*, const char*, size_t, regmatch_t*, int));
+}
diff --git a/tests/headers/posix/sched_h.c b/tests/headers/posix/sched_h.c
new file mode 100644
index 0000000..e9b98d6
--- /dev/null
+++ b/tests/headers/posix/sched_h.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if !defined(DO_NOT_INCLUDE_SCHED_H)
+#include <sched.h>
+#endif
+
+#include "header_checks.h"
+
+static void sched_h() {
+  TYPE(pid_t);
+  TYPE(time_t);
+  TYPE(struct timespec);
+
+  TYPE(struct sched_param);
+  STRUCT_MEMBER(struct sched_param, int, sched_priority);
+#if !defined(__linux__)
+  STRUCT_MEMBER(struct sched_param, int, sched_ss_low_priority);
+  STRUCT_MEMBER(struct sched_param, struct timespec, sched_ss_repl_period);
+  STRUCT_MEMBER(struct sched_param, struct timespec, sched_ss_init_budget);
+  STRUCT_MEMBER(struct sched_param, int, sched_ss_max_repl);
+#endif
+
+  MACRO(SCHED_FIFO);
+  MACRO(SCHED_RR);
+#if !defined(__linux__)
+  MACRO(SCHED_SPORADIC);
+#endif
+  MACRO(SCHED_OTHER);
+
+  FUNCTION(sched_get_priority_max, int (*f)(int));
+  FUNCTION(sched_get_priority_min, int (*f)(int));
+  FUNCTION(sched_getparam, int (*f)(pid_t, struct sched_param*));
+  FUNCTION(sched_getscheduler, int (*f)(pid_t));
+  FUNCTION(sched_rr_get_interval, int (*f)(pid_t, struct timespec*));
+  FUNCTION(sched_setparam, int (*f)(pid_t, const struct sched_param*));
+  FUNCTION(sched_setscheduler, int (*f)(pid_t, int, const struct sched_param*));
+  FUNCTION(sched_yield, int (*f)(void));
+}
diff --git a/tests/headers/posix/search_h.c b/tests/headers/posix/search_h.c
new file mode 100644
index 0000000..9de079a
--- /dev/null
+++ b/tests/headers/posix/search_h.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <search.h>
+
+#include "header_checks.h"
+
+static void search_h() {
+  TYPE(ENTRY);
+  TYPE(struct entry);
+  STRUCT_MEMBER(ENTRY, char*, key);
+  STRUCT_MEMBER(ENTRY, void*, data);
+
+  ACTION a;
+  a = FIND;
+  a = ENTER;
+
+  VISIT v;
+  v = preorder;
+  v = postorder;
+  v = endorder;
+  v = leaf;
+
+  TYPE(size_t);
+
+  FUNCTION(hcreate, int (*f)(size_t));
+  FUNCTION(hdestroy, void (*f)(void));
+  FUNCTION(hsearch, ENTRY* (*f)(ENTRY, ACTION));
+  FUNCTION(insque, void (*f)(void*, void*));
+  FUNCTION(lfind, void* (*f)(const void*, const void*, size_t*, size_t,
+                             int (*)(const void*, const void*)));
+  FUNCTION(lsearch, void* (*f)(const void*, void*, size_t*, size_t,
+                               int (*)(const void*, const void*)));
+  FUNCTION(remque, void (*f)(void*));
+  FUNCTION(tdelete, void* (*f)(const void*, void**, int (*)(const void*, const void*)));
+  FUNCTION(tfind, void* (*f)(const void*, void* const*, int (*)(const void*, const void*)));
+  FUNCTION(tsearch, void* (*f)(const void*, void**, int (*)(const void*, const void*)));
+  FUNCTION(twalk, void (*f)(const void*, void (*)(const void*, VISIT, int)));
+}
diff --git a/tests/headers/posix/semaphore_h.c b/tests/headers/posix/semaphore_h.c
new file mode 100644
index 0000000..9d5c7e1
--- /dev/null
+++ b/tests/headers/posix/semaphore_h.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <semaphore.h>
+
+#include "header_checks.h"
+
+static void semaphore_h() {
+  TYPE(sem_t);
+
+  MACRO(SEM_FAILED);
+
+  FUNCTION(sem_close, int (*f)(sem_t*));
+  FUNCTION(sem_destroy, int (*f)(sem_t*));
+  FUNCTION(sem_getvalue, int (*f)(sem_t*, int*));
+  FUNCTION(sem_init, int (*f)(sem_t*, int, unsigned));
+  FUNCTION(sem_open, sem_t* (*f)(const char*, int, ...));
+  FUNCTION(sem_post, int (*f)(sem_t*));
+  FUNCTION(sem_timedwait, int (*f)(sem_t*, const struct timespec*));
+  FUNCTION(sem_trywait, int (*f)(sem_t*));
+  FUNCTION(sem_unlink, int (*f)(const char*));
+  FUNCTION(sem_wait, int (*f)(sem_t*));
+}
diff --git a/tests/headers/posix/setjmp_h.c b/tests/headers/posix/setjmp_h.c
new file mode 100644
index 0000000..b6b75ee
--- /dev/null
+++ b/tests/headers/posix/setjmp_h.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <setjmp.h>
+
+#include "header_checks.h"
+
+static void setjmp_h() {
+  TYPE(jmp_buf);
+  TYPE(sigjmp_buf);
+
+  FUNCTION(_longjmp, void (*f)(jmp_buf, int));
+  FUNCTION(longjmp, void (*f)(jmp_buf, int));
+  FUNCTION(siglongjmp, void (*f)(sigjmp_buf, int));
+
+  FUNCTION(_setjmp, int (*f)(jmp_buf));
+  FUNCTION(setjmp, int (*f)(jmp_buf));
+#if defined(__GLIBC__)
+  FUNCTION(__sigsetjmp, int (*f)(sigjmp_buf, int));
+#else
+  FUNCTION(sigsetjmp, int (*f)(sigjmp_buf, int));
+#endif
+}
diff --git a/tests/headers/posix/signal_h.c b/tests/headers/posix/signal_h.c
new file mode 100644
index 0000000..661b55e
--- /dev/null
+++ b/tests/headers/posix/signal_h.c
@@ -0,0 +1,229 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <signal.h>
+
+#include "header_checks.h"
+
+static void signal_h() {
+  void (*h)(int);
+  h = SIG_DFL;
+  h = SIG_ERR;
+  h = SIG_HOLD;
+  h = SIG_IGN;
+
+  TYPE(pthread_t);
+  TYPE(size_t);
+  TYPE(uid_t);
+
+  TYPE(struct timespec);
+
+  TYPE(sig_atomic_t);
+  TYPE(pid_t);
+
+  TYPE(pthread_attr_t);
+
+  TYPE(struct sigevent);
+  STRUCT_MEMBER(struct sigevent, int, sigev_notify);
+  STRUCT_MEMBER(struct sigevent, int, sigev_signo);
+  STRUCT_MEMBER(struct sigevent, union sigval, sigev_value);
+  STRUCT_MEMBER_FUNCTION_POINTER(struct sigevent, void (*f)(union sigval), sigev_notify_function);
+#if defined(__BIONIC__) || defined(__GLIBC__)
+  STRUCT_MEMBER(struct sigevent, void*, sigev_notify_attributes);
+#else
+  STRUCT_MEMBER(struct sigevent, pthread_attr_t*, sigev_notify_attributes);
+#endif
+
+  MACRO(SIGEV_NONE);
+  MACRO(SIGEV_SIGNAL);
+  MACRO(SIGEV_THREAD);
+
+  TYPE(union sigval);
+  STRUCT_MEMBER(union sigval, int, sival_int);
+  STRUCT_MEMBER(union sigval, void*, sival_ptr);
+
+  int i;
+  i = SIGRTMIN;
+  i = SIGRTMAX;
+
+  MACRO(SIGABRT);
+  MACRO(SIGALRM);
+  MACRO(SIGBUS);
+  MACRO(SIGCHLD);
+  MACRO(SIGCONT);
+  MACRO(SIGFPE);
+  MACRO(SIGHUP);
+  MACRO(SIGILL);
+  MACRO(SIGINT);
+  MACRO(SIGKILL);
+  MACRO(SIGPIPE);
+  MACRO(SIGQUIT);
+  MACRO(SIGSEGV);
+  MACRO(SIGSTOP);
+  MACRO(SIGTERM);
+  MACRO(SIGTSTP);
+  MACRO(SIGTTIN);
+  MACRO(SIGTTOU);
+  MACRO(SIGUSR1);
+  MACRO(SIGUSR2);
+  MACRO(SIGPOLL);
+  MACRO(SIGPROF);
+  MACRO(SIGSYS);
+  MACRO(SIGTRAP);
+  MACRO(SIGURG);
+  MACRO(SIGVTALRM);
+  MACRO(SIGXCPU);
+  MACRO(SIGXFSZ);
+
+  TYPE(struct sigaction);
+  STRUCT_MEMBER_FUNCTION_POINTER(struct sigaction, void (*f)(int), sa_handler);
+  STRUCT_MEMBER(struct sigaction, sigset_t, sa_mask);
+  STRUCT_MEMBER(struct sigaction, int, sa_flags);
+  STRUCT_MEMBER_FUNCTION_POINTER(struct sigaction, void (*f)(int, siginfo_t*, void*), sa_sigaction);
+
+  i = SIG_BLOCK;
+  i = SIG_UNBLOCK;
+  i = SIG_SETMASK;
+
+  MACRO(SA_NOCLDSTOP);
+  MACRO(SA_ONSTACK);
+  MACRO(SA_RESETHAND);
+  MACRO(SA_RESTART);
+  MACRO(SA_SIGINFO);
+  MACRO(SA_NOCLDWAIT);
+  MACRO(SA_NODEFER);
+
+  MACRO(SS_ONSTACK);
+  MACRO(SS_DISABLE);
+
+  MACRO(MINSIGSTKSZ);
+  MACRO(SIGSTKSZ);
+
+  TYPE(mcontext_t);
+
+  TYPE(ucontext_t);
+  STRUCT_MEMBER(ucontext_t, ucontext_t*, uc_link);
+  STRUCT_MEMBER(ucontext_t, sigset_t, uc_sigmask);
+  STRUCT_MEMBER(ucontext_t, stack_t, uc_stack);
+  STRUCT_MEMBER(ucontext_t, mcontext_t, uc_mcontext);
+
+  TYPE(stack_t);
+  STRUCT_MEMBER(stack_t, void*, ss_sp);
+  STRUCT_MEMBER(stack_t, size_t, ss_size);
+  STRUCT_MEMBER(stack_t, int, ss_flags);
+
+  TYPE(siginfo_t);
+  STRUCT_MEMBER(siginfo_t, int, si_signo);
+  STRUCT_MEMBER(siginfo_t, int, si_code);
+  STRUCT_MEMBER(siginfo_t, int, si_errno);
+  STRUCT_MEMBER(siginfo_t, pid_t, si_pid);
+  STRUCT_MEMBER(siginfo_t, uid_t, si_uid);
+  STRUCT_MEMBER(siginfo_t, void*, si_addr);
+  STRUCT_MEMBER(siginfo_t, int, si_status);
+  STRUCT_MEMBER(siginfo_t, long, si_band);
+  STRUCT_MEMBER(siginfo_t, union sigval, si_value);
+
+  i = ILL_ILLOPC;
+  i = ILL_ILLOPN;
+  i = ILL_ILLADR;
+  i = ILL_ILLTRP;
+  i = ILL_PRVOPC;
+  i = ILL_PRVREG;
+  i = ILL_COPROC;
+  i = ILL_BADSTK;
+
+  i = FPE_INTDIV;
+  i = FPE_INTOVF;
+  i = FPE_FLTDIV;
+  i = FPE_FLTOVF;
+  i = FPE_FLTUND;
+  i = FPE_FLTRES;
+  i = FPE_FLTINV;
+  i = FPE_FLTSUB;
+
+  i = SEGV_MAPERR;
+  i = SEGV_ACCERR;
+
+  i = BUS_ADRALN;
+  i = BUS_ADRERR;
+  i = BUS_OBJERR;
+
+  i = TRAP_BRKPT;
+  i = TRAP_TRACE;
+
+  i = CLD_EXITED;
+  i = CLD_KILLED;
+  i = CLD_DUMPED;
+  i = CLD_TRAPPED;
+  i = CLD_STOPPED;
+  i = CLD_CONTINUED;
+
+  i = POLL_IN;
+  i = POLL_OUT;
+  i = POLL_MSG;
+  i = POLL_ERR;
+  i = POLL_PRI;
+  i = POLL_HUP;
+
+  i = SI_USER;
+  i = SI_QUEUE;
+  i = SI_TIMER;
+  i = SI_ASYNCIO;
+  i = SI_MESGQ;
+
+  typedef void (*signal_handler_type)(int);
+
+  FUNCTION(kill, int (*f)(pid_t, int));
+  FUNCTION(killpg, int (*f)(pid_t, int));
+  FUNCTION(psiginfo, void (*f)(const siginfo_t*, const char*));
+  FUNCTION(psignal, void (*f)(int, const char*));
+  FUNCTION(pthread_kill, int (*f)(pthread_t, int));
+  FUNCTION(pthread_sigmask, int (*f)(int, const sigset_t*, sigset_t*));
+  FUNCTION(raise, int (*f)(int));
+  FUNCTION(sigaction, int (*f)(int, const struct sigaction*, struct sigaction*));
+  FUNCTION(sigaddset, int (*f)(sigset_t*, int));
+  FUNCTION(sigaltstack, int (*f)(const stack_t*, stack_t*));
+  FUNCTION(sigdelset, int (*f)(sigset_t*, int));
+  FUNCTION(sigemptyset, int (*f)(sigset_t*));
+  FUNCTION(sigfillset, int (*f)(sigset_t*));
+  FUNCTION(sighold, int (*f)(int));
+  FUNCTION(sigignore, int (*f)(int));
+  FUNCTION(siginterrupt, int (*f)(int, int));
+  FUNCTION(sigismember, int (*f)(const sigset_t*, int));
+  FUNCTION(signal, signal_handler_type (*f)(int, signal_handler_type));
+  FUNCTION(sigpause, int (*f)(int));
+  FUNCTION(sigpending, int (*f)(sigset_t*));
+  FUNCTION(sigprocmask, int (*f)(int, const sigset_t*, sigset_t*));
+  FUNCTION(sigqueue, int (*f)(pid_t, int, union sigval));
+  FUNCTION(sigrelse, int (*f)(int));
+  FUNCTION(sigset, signal_handler_type (*f)(int, signal_handler_type));
+  FUNCTION(sigsuspend, int (*f)(const sigset_t*));
+  FUNCTION(sigtimedwait, int (*f)(const sigset_t*, siginfo_t*, const struct timespec*));
+  FUNCTION(sigwait, int (*f)(const sigset_t*, int*));
+  FUNCTION(sigwaitinfo, int (*f)(const sigset_t*, siginfo_t*));
+}
diff --git a/tests/headers/posix/spawn_h.c b/tests/headers/posix/spawn_h.c
new file mode 100644
index 0000000..48f8390
--- /dev/null
+++ b/tests/headers/posix/spawn_h.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <spawn.h>
+
+#include "header_checks.h"
+
+static void spawn_h() {
+  TYPE(posix_spawnattr_t);
+  TYPE(posix_spawn_file_actions_t);
+
+  TYPE(mode_t);
+  TYPE(pid_t);
+
+  TYPE(sigset_t);
+
+  TYPE(struct sched_param*);
+
+  MACRO(POSIX_SPAWN_RESETIDS);
+  MACRO(POSIX_SPAWN_SETPGROUP);
+  MACRO(POSIX_SPAWN_SETSCHEDPARAM);
+  MACRO(POSIX_SPAWN_SETSCHEDULER);
+  MACRO(POSIX_SPAWN_SETSIGDEF);
+  MACRO(POSIX_SPAWN_SETSIGMASK);
+
+  FUNCTION(posix_spawn, int (*f)(pid_t*, const char*, const posix_spawn_file_actions_t*, const posix_spawnattr_t*, char* const[], char* const[]));
+  FUNCTION(posix_spawn_file_actions_addclose, int (*f)(posix_spawn_file_actions_t*, int));
+  FUNCTION(posix_spawn_file_actions_adddup2, int (*f)(posix_spawn_file_actions_t*, int, int));
+  FUNCTION(posix_spawn_file_actions_addopen, int (*f)(posix_spawn_file_actions_t*, int, const char*, int, mode_t));
+  FUNCTION(posix_spawn_file_actions_destroy, int (*f)(posix_spawn_file_actions_t*));
+  FUNCTION(posix_spawn_file_actions_init, int (*f)(posix_spawn_file_actions_t*));
+  FUNCTION(posix_spawnattr_destroy, int (*f)(posix_spawnattr_t*));
+  FUNCTION(posix_spawnattr_getflags, int (*f)(const posix_spawnattr_t*, short*));
+  FUNCTION(posix_spawnattr_getpgroup, int (*f)(const posix_spawnattr_t*, pid_t*));
+  FUNCTION(posix_spawnattr_getschedparam, int (*f)(const posix_spawnattr_t*, struct sched_param*));
+  FUNCTION(posix_spawnattr_getschedpolicy, int (*f)(const posix_spawnattr_t*, int*));
+  FUNCTION(posix_spawnattr_getsigdefault, int (*f)(const posix_spawnattr_t*, sigset_t*));
+  FUNCTION(posix_spawnattr_getsigmask, int (*f)(const posix_spawnattr_t*, sigset_t*));
+  FUNCTION(posix_spawnattr_init, int (*f)(posix_spawnattr_t*));
+  FUNCTION(posix_spawnattr_setflags, int (*f)(posix_spawnattr_t*, short));
+  FUNCTION(posix_spawnattr_setpgroup, int (*f)(posix_spawnattr_t*, pid_t));
+  FUNCTION(posix_spawnattr_setschedparam, int (*f)(posix_spawnattr_t*, const struct sched_param*));
+  FUNCTION(posix_spawnattr_setsigdefault, int (*f)(posix_spawnattr_t*, const sigset_t*));
+  FUNCTION(posix_spawnattr_setsigmask, int (*f)(posix_spawnattr_t*, const sigset_t*));
+  FUNCTION(posix_spawnp, int (*f)(pid_t*, const char*, const posix_spawn_file_actions_t*, const posix_spawnattr_t*, char* const[], char* const[]));
+}
diff --git a/tests/headers/posix/stdarg_h.c b/tests/headers/posix/stdarg_h.c
new file mode 100644
index 0000000..ef1e8af
--- /dev/null
+++ b/tests/headers/posix/stdarg_h.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdarg.h>
+
+#include "header_checks.h"
+
+static void stdarg_h() {
+  TYPE(va_list);
+
+#if !defined(va_start)
+#error va_start
+#endif
+#if !defined(va_copy)
+#error va_copy
+#endif
+#if !defined(va_arg)
+#error va_arg
+#endif
+#if !defined(va_end)
+#error va_end
+#endif
+}
diff --git a/tests/headers/posix/stdbool_h.c b/tests/headers/posix/stdbool_h.c
new file mode 100644
index 0000000..f891a73
--- /dev/null
+++ b/tests/headers/posix/stdbool_h.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdbool.h>
+
+#include "header_checks.h"
+
+static void stdbool_h() {
+#if !defined(bool)
+#error bool
+#endif
+  MACRO_VALUE(true, 1);
+  MACRO_VALUE(false, 0);
+  MACRO_VALUE(__bool_true_false_are_defined, 1);
+}
diff --git a/tests/headers/posix/stddef_h.c b/tests/headers/posix/stddef_h.c
new file mode 100644
index 0000000..7cdfd76
--- /dev/null
+++ b/tests/headers/posix/stddef_h.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stddef.h>
+
+#include "header_checks.h"
+
+static void stddef_h() {
+  void* null = NULL;
+
+#if !defined(offsetof)
+#error offsetof
+#endif
+
+  TYPE(ptrdiff_t);
+  TYPE(wchar_t);
+  TYPE(size_t);
+}
diff --git a/tests/headers/posix/stdint_h.c b/tests/headers/posix/stdint_h.c
new file mode 100644
index 0000000..a8f3346
--- /dev/null
+++ b/tests/headers/posix/stdint_h.c
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+
+#include "header_checks.h"
+
+static void stdint_h() {
+  TYPE(int8_t);
+  TYPE(int16_t);
+  TYPE(int32_t);
+  TYPE(uint8_t);
+  TYPE(uint16_t);
+  TYPE(uint32_t);
+
+  TYPE(int64_t);
+  TYPE(uint64_t);
+
+  TYPE(int_least8_t);
+  TYPE(int_least16_t);
+  TYPE(int_least32_t);
+  TYPE(int_least64_t);
+  TYPE(uint_least8_t);
+  TYPE(uint_least16_t);
+  TYPE(uint_least32_t);
+  TYPE(uint_least64_t);
+
+  TYPE(int_fast8_t);
+  TYPE(int_fast16_t);
+  TYPE(int_fast32_t);
+  TYPE(int_fast64_t);
+  TYPE(uint_fast8_t);
+  TYPE(uint_fast16_t);
+  TYPE(uint_fast32_t);
+  TYPE(uint_fast64_t);
+
+  TYPE(intptr_t);
+  TYPE(uintptr_t);
+
+  TYPE(intmax_t);
+  TYPE(uintmax_t);
+
+  MACRO(INT8_MIN);
+  MACRO(INT16_MIN);
+  MACRO(INT32_MIN);
+  MACRO(INT64_MIN);
+  MACRO(INT8_MAX);
+  MACRO(INT16_MAX);
+  MACRO(INT32_MAX);
+  MACRO(INT64_MAX);
+  MACRO(UINT8_MAX);
+  MACRO(UINT16_MAX);
+  MACRO(UINT32_MAX);
+  MACRO(UINT64_MAX);
+
+  MACRO(INT_LEAST8_MIN);
+  MACRO(INT_LEAST16_MIN);
+  MACRO(INT_LEAST32_MIN);
+  MACRO(INT_LEAST64_MIN);
+  MACRO(INT_LEAST8_MAX);
+  MACRO(INT_LEAST16_MAX);
+  MACRO(INT_LEAST32_MAX);
+  MACRO(INT_LEAST64_MAX);
+  MACRO(UINT_LEAST8_MAX);
+  MACRO(UINT_LEAST16_MAX);
+  MACRO(UINT_LEAST32_MAX);
+  MACRO(UINT_LEAST64_MAX);
+
+  MACRO(INT_FAST8_MIN);
+  MACRO(INT_FAST16_MIN);
+  MACRO(INT_FAST32_MIN);
+  MACRO(INT_FAST64_MIN);
+  MACRO(INT_FAST8_MAX);
+  MACRO(INT_FAST16_MAX);
+  MACRO(INT_FAST32_MAX);
+  MACRO(INT_FAST64_MAX);
+  MACRO(UINT_FAST8_MAX);
+  MACRO(UINT_FAST16_MAX);
+  MACRO(UINT_FAST32_MAX);
+  MACRO(UINT_FAST64_MAX);
+
+  MACRO(INTPTR_MIN);
+  MACRO(INTPTR_MAX);
+  MACRO(UINTPTR_MAX);
+
+  MACRO(INTMAX_MIN);
+  MACRO(INTMAX_MAX);
+  MACRO(UINTMAX_MAX);
+
+  MACRO(PTRDIFF_MIN);
+  MACRO(PTRDIFF_MAX);
+
+  MACRO(SIG_ATOMIC_MIN);
+  MACRO(SIG_ATOMIC_MAX);
+
+  MACRO(SIZE_MAX);
+
+  MACRO(WCHAR_MIN);
+  MACRO(WCHAR_MAX);
+
+  MACRO(WINT_MIN);
+  MACRO(WINT_MAX);
+
+#if !defined(INT8_C)
+#error INT8_C
+#endif
+#if !defined(INT16_C)
+#error INT16_C
+#endif
+#if !defined(INT32_C)
+#error INT32_C
+#endif
+#if !defined(INT32_C)
+#error INT32_C
+#endif
+
+#if !defined(UINT8_C)
+#error UINT8_C
+#endif
+#if !defined(UINT16_C)
+#error UINT16_C
+#endif
+#if !defined(UINT32_C)
+#error UINT32_C
+#endif
+#if !defined(UINT32_C)
+#error UINT32_C
+#endif
+
+#if !defined(INTMAX_C)
+#error INTMAX_C
+#endif
+#if !defined(UINTMAX_C)
+#error UINTMAX_C
+#endif
+}
diff --git a/tests/headers/posix/stdio_h.c b/tests/headers/posix/stdio_h.c
new file mode 100644
index 0000000..cbeb0bc
--- /dev/null
+++ b/tests/headers/posix/stdio_h.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "header_checks.h"
+
+static void stdio_h() {
+  TYPE(FILE*);
+  TYPE(fpos_t);
+  TYPE(off_t);
+  TYPE(size_t);
+  TYPE(ssize_t);
+  TYPE(va_list);
+
+  MACRO(BUFSIZ);
+  MACRO(L_ctermid);
+  MACRO(L_tmpnam);
+
+  MACRO(_IOFBF);
+  MACRO(_IOLBF);
+  MACRO(_IONBF);
+
+  MACRO(SEEK_CUR);
+  MACRO(SEEK_END);
+  MACRO(SEEK_SET);
+
+  MACRO(FILENAME_MAX);
+  MACRO(FOPEN_MAX);
+  MACRO(TMP_MAX);
+
+  MACRO(EOF);
+
+  MACRO(NULL);
+
+  const char* s;
+  s = P_tmpdir;
+
+#if !defined(stderr)
+#error stderr
+#endif
+#if !defined(stdin)
+#error stdin
+#endif
+#if !defined(stdout)
+#error stdout
+#endif
+  FILE* fp;
+  fp = stderr;
+  fp = stdin;
+  fp = stdout;
+
+  FUNCTION(clearerr, void (*f)(FILE*));
+  FUNCTION(ctermid, char* (*f)(char*));
+  FUNCTION(dprintf, int (*f)(int, const char*, ...));
+  FUNCTION(fclose, int (*f)(FILE*));
+  FUNCTION(fdopen, FILE* (*f)(int, const char*));
+  FUNCTION(feof, int (*f)(FILE*));
+  FUNCTION(ferror, int (*f)(FILE*));
+  FUNCTION(fflush, int (*f)(FILE*));
+  FUNCTION(fgetc, int (*f)(FILE*));
+  FUNCTION(fgetpos, int (*f)(FILE*, fpos_t*));
+  FUNCTION(fgets, char* (*f)(char*, int, FILE*));
+  FUNCTION(fileno, int (*f)(FILE*));
+  FUNCTION(flockfile, void (*f)(FILE*));
+  FUNCTION(fmemopen, FILE* (*f)(void*, size_t, const char*));
+  FUNCTION(fopen, FILE* (*f)(const char*, const char*));
+  FUNCTION(fprintf, int (*f)(FILE*, const char*, ...));
+  FUNCTION(fputc, int (*f)(int, FILE*));
+  FUNCTION(fputs, int (*f)(const char*, FILE*));
+  FUNCTION(fread, size_t (*f)(void*, size_t, size_t, FILE*));
+  FUNCTION(freopen, FILE* (*f)(const char*, const char*, FILE*));
+  FUNCTION(fscanf, int (*f)(FILE*, const char*, ...));
+  FUNCTION(fseek, int (*f)(FILE*, long, int));
+  FUNCTION(fseeko, int (*f)(FILE*, off_t, int));
+  FUNCTION(fsetpos, int (*f)(FILE*, const fpos_t*));
+  FUNCTION(ftell, long (*f)(FILE*));
+  FUNCTION(ftello, off_t (*f)(FILE*));
+  FUNCTION(ftrylockfile, int (*f)(FILE*));
+  FUNCTION(funlockfile, void (*f)(FILE*));
+  FUNCTION(fwrite, size_t (*f)(const void*, size_t, size_t, FILE*));
+  FUNCTION(getc, int (*f)(FILE*));
+  FUNCTION(getchar, int (*f)(void));
+  FUNCTION(getc_unlocked, int (*f)(FILE*));
+  FUNCTION(getchar_unlocked, int (*f)(void));
+  FUNCTION(getdelim, ssize_t (*f)(char**, size_t*, int, FILE*));
+  FUNCTION(getline, ssize_t (*f)(char**, size_t*, FILE*));
+  FUNCTION(gets, char* (*f)(char*));
+  FUNCTION(open_memstream, FILE* (*f)(char**, size_t*));
+  FUNCTION(pclose, int (*f)(FILE*));
+  FUNCTION(perror, void (*f)(const char*));
+  FUNCTION(popen, FILE* (*f)(const char*, const char*));
+  FUNCTION(printf, int (*f)(const char*, ...));
+  FUNCTION(putc, int (*f)(int, FILE*));
+  FUNCTION(putchar, int (*f)(int));
+  FUNCTION(putc_unlocked, int (*f)(int, FILE*));
+  FUNCTION(putchar_unlocked, int (*f)(int));
+  FUNCTION(puts, int (*f)(const char*));
+  FUNCTION(remove, int (*f)(const char*));
+  FUNCTION(rename, int (*f)(const char*, const char*));
+  FUNCTION(renameat, int (*f)(int, const char*, int, const char*));
+  FUNCTION(rewind, void (*f)(FILE*));
+  FUNCTION(scanf, int (*f)(const char*, ...));
+  FUNCTION(setbuf, void (*f)(FILE*, char*));
+  FUNCTION(setvbuf, int (*f)(FILE*, char*, int, size_t));
+  FUNCTION(snprintf, int (*f)(char*, size_t, const char*, ...));
+  FUNCTION(sprintf, int (*f)(char*, const char*, ...));
+  FUNCTION(sscanf, int (*f)(const char*, const char*, ...));
+  FUNCTION(tempnam, char* (*f)(const char*, const char*));
+  FUNCTION(tmpfile, FILE* (*f)(void));
+  FUNCTION(tmpnam, char* (*f)(char*));
+  FUNCTION(ungetc, int (*f)(int, FILE*));
+  FUNCTION(vdprintf, int (*f)(int, const char*, va_list));
+  FUNCTION(vfprintf, int (*f)(FILE*, const char*, va_list));
+  FUNCTION(vfscanf, int (*f)(FILE*, const char*, va_list));
+  FUNCTION(vprintf, int (*f)(const char*, va_list));
+  FUNCTION(vscanf, int (*f)(const char*, va_list));
+  FUNCTION(vsnprintf, int (*f)(char*, size_t, const char*, va_list));
+  FUNCTION(vsprintf, int (*f)(char*, const char*, va_list));
+  FUNCTION(vsscanf, int (*f)(const char*, const char*, va_list));
+}
diff --git a/tests/headers/posix/stdlib_h.c b/tests/headers/posix/stdlib_h.c
new file mode 100644
index 0000000..52580cf
--- /dev/null
+++ b/tests/headers/posix/stdlib_h.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+
+#include "header_checks.h"
+
+static void stdlib_h() {
+  MACRO(EXIT_FAILURE);
+  MACRO_VALUE(EXIT_SUCCESS, 0);
+
+  MACRO(RAND_MAX);
+
+  MACRO(MB_CUR_MAX);
+
+  MACRO(NULL);
+
+  TYPE(div_t);
+  TYPE(ldiv_t);
+  TYPE(lldiv_t);
+  TYPE(size_t);
+  TYPE(wchar_t);
+
+#if !defined(WEXITSTATUS)
+#error WEXITSTATUS
+#endif
+#if !defined(WIFEXITED)
+#error WIFEXITED
+#endif
+#if !defined(WIFSIGNALED)
+#error WIFSIGNALED
+#endif
+#if !defined(WIFSTOPPED)
+#error WIFSTOPPED
+#endif
+  MACRO(WNOHANG);
+#if !defined(WSTOPSIG)
+#error WSTOPSIG
+#endif
+#if !defined(WTERMSIG)
+#error WTERMSIG
+#endif
+  MACRO(WUNTRACED);
+
+  FUNCTION(_Exit, void (*f)(int));
+#if !defined(__BIONIC__)
+  FUNCTION(a64l, long (*f)(const char*));
+#endif
+  FUNCTION(abort, void (*f)(void));
+  FUNCTION(abs, int (*f)(int));
+  FUNCTION(atexit, int (*f)(void (*)(void)));
+  FUNCTION(atof, double (*f)(const char*));
+  FUNCTION(atoi, int (*f)(const char*));
+  FUNCTION(atol, long (*f)(const char*));
+  FUNCTION(atoll, long long (*f)(const char*));
+  FUNCTION(bsearch, void* (*f)(const void*, const void*, size_t, size_t, int (*)(const void*, const void*)));
+  FUNCTION(calloc, void* (*f)(size_t, size_t));
+  FUNCTION(div, div_t (*f)(int, int));
+  FUNCTION(drand48, double (*f)(void));
+  FUNCTION(erand48, double (*f)(unsigned short[3]));
+  FUNCTION(exit, void (*f)(int));
+  FUNCTION(free, void (*f)(void*));
+  FUNCTION(getenv, char* (*f)(const char*));
+  FUNCTION(getsubopt, int (*f)(char**, char* const*, char**));
+  FUNCTION(grantpt, int (*f)(int));
+  FUNCTION(initstate, char* (*f)(unsigned, char*, size_t));
+  FUNCTION(jrand48, long (*f)(unsigned short[3]));
+#if !defined(__BIONIC__)
+  FUNCTION(l64a, char* (*f)(long));
+#endif
+  FUNCTION(labs, long (*f)(long));
+  FUNCTION(lcong48, void (*f)(unsigned short[7]));
+  FUNCTION(ldiv, ldiv_t (*f)(long, long));
+  FUNCTION(llabs, long long (*f)(long long));
+  FUNCTION(lldiv, lldiv_t (*f)(long long, long long));
+  FUNCTION(lrand48, long (*f)(void));
+  FUNCTION(malloc, void* (*f)(size_t));
+  FUNCTION(mblen, int (*f)(const char*, size_t));
+  FUNCTION(mbstowcs, size_t (*f)(wchar_t*, const char*, size_t));
+  FUNCTION(mbtowc, int (*f)(wchar_t*, const char*, size_t));
+  FUNCTION(mkdtemp, char* (*f)(char*));
+  FUNCTION(mkstemp, int (*f)(char*));
+  FUNCTION(mrand48, long (*f)(void));
+  FUNCTION(nrand48, long (*f)(unsigned short[3]));
+  FUNCTION(posix_memalign, int (*f)(void**, size_t, size_t));
+  FUNCTION(posix_openpt, int (*f)(int));
+  FUNCTION(ptsname, char* (*f)(int));
+  FUNCTION(putenv, int (*f)(char*));
+  FUNCTION(qsort, void (*f)(void*, size_t, size_t, int (*)(const void*, const void*)));
+  FUNCTION(rand, int (*f)(void));
+  FUNCTION(rand_r, int (*f)(unsigned*));
+  FUNCTION(random, long (*f)(void));
+  FUNCTION(realloc, void* (*f)(void*, size_t));
+  FUNCTION(realpath, char* (*f)(const char*, char*));
+  FUNCTION(seed48, unsigned short* (*f)(unsigned short[3]));
+  FUNCTION(setenv, int (*f)(const char*, const char*, int));
+#if !defined(__BIONIC__)
+  FUNCTION(setkey, void (*f)(const char*));
+#endif
+  FUNCTION(setstate, char* (*f)(char*));
+  FUNCTION(srand, void (*f)(unsigned));
+  FUNCTION(srand48, void (*f)(long));
+  FUNCTION(srandom, void (*f)(unsigned));
+  FUNCTION(strtod, double (*f)(const char*, char**));
+  FUNCTION(strtof, float (*f)(const char*, char**));
+  FUNCTION(strtol, long (*f)(const char*, char**, int));
+  FUNCTION(strtold, long double (*f)(const char*, char**));
+  FUNCTION(strtoll, long long (*f)(const char*, char**, int));
+  FUNCTION(strtoul, unsigned long (*f)(const char*, char**, int));
+  FUNCTION(strtoull, unsigned long long (*f)(const char*, char**, int));
+  FUNCTION(system, int (*f)(const char*));
+  FUNCTION(unlockpt, int (*f)(int));
+  FUNCTION(unsetenv, int (*f)(const char*));
+  FUNCTION(wcstombs, size_t (*f)(char*, const wchar_t*, size_t));
+  FUNCTION(wctomb, int (*f)(char*, wchar_t));
+}
diff --git a/tests/headers/posix/string_h.c b/tests/headers/posix/string_h.c
new file mode 100644
index 0000000..2440050
--- /dev/null
+++ b/tests/headers/posix/string_h.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+#include "header_checks.h"
+
+static void string_h() {
+  MACRO(NULL);
+  TYPE(size_t);
+  TYPE(locale_t);
+
+  FUNCTION(memccpy, void* (*f)(void*, const void*, int, size_t));
+  FUNCTION(memchr, void* (*f)(const void*, int, size_t));
+  FUNCTION(memcmp, int (*f)(const void*, const void*, size_t));
+  FUNCTION(memcpy, void* (*f)(void*, const void*, size_t));
+  FUNCTION(memmove, void* (*f)(void*, const void*, size_t));
+  FUNCTION(memset, void* (*f)(void*, int, size_t));
+  FUNCTION(stpcpy, char* (*f)(char*, const char*));
+  FUNCTION(stpncpy, char* (*f)(char*, const char*, size_t));
+  FUNCTION(strcat, char* (*f)(char*, const char*));
+  FUNCTION(strchr, char* (*f)(const char*, int));
+  FUNCTION(strcmp, int (*f)(const char*, const char*));
+  FUNCTION(strcoll, int (*f)(const char*, const char*));
+  FUNCTION(strcoll_l, int (*f)(const char*, const char*, locale_t));
+  FUNCTION(strcpy, char* (*f)(char*, const char*));
+  FUNCTION(strcspn, size_t (*f)(const char*, const char*));
+  FUNCTION(strdup, char* (*f)(const char*));
+  FUNCTION(strerror, char* (*f)(int));
+  FUNCTION(strerror_l, char* (*f)(int, locale_t));
+  FUNCTION(strerror_r, int (*f)(int, char*, size_t));
+  FUNCTION(strlen, size_t (*f)(const char*));
+  FUNCTION(strncat, char* (*f)(char*, const char*, size_t));
+  FUNCTION(strncmp, int (*f)(const char*, const char*, size_t));
+  FUNCTION(strncpy, char* (*f)(char*, const char*, size_t));
+  FUNCTION(strndup, char* (*f)(const char*, size_t));
+  FUNCTION(strnlen, size_t (*f)(const char*, size_t));
+  FUNCTION(strpbrk, char* (*f)(const char*, const char*));
+  FUNCTION(strrchr, char* (*f)(const char*, int));
+  FUNCTION(strsignal, char* (*f)(int));
+  FUNCTION(strspn, size_t (*f)(const char*, const char*));
+  FUNCTION(strstr, char* (*f)(const char*, const char*));
+  FUNCTION(strtok, char* (*f)(char*, const char*));
+  FUNCTION(strtok_r, char* (*f)(char*, const char*, char**));
+  FUNCTION(strxfrm, size_t (*f)(char*, const char*, size_t));
+  FUNCTION(strxfrm_l, size_t (*f)(char*, const char*, size_t, locale_t));
+}
diff --git a/tests/headers/posix/strings_h.c b/tests/headers/posix/strings_h.c
new file mode 100644
index 0000000..0a2fa84
--- /dev/null
+++ b/tests/headers/posix/strings_h.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <strings.h>
+
+#include "header_checks.h"
+
+static void strings_h() {
+  FUNCTION(ffs, int (*f)(int));
+  FUNCTION(strcasecmp, int (*f)(const char*, const char*));
+  FUNCTION(strcasecmp_l, int (*f)(const char*, const char*, locale_t));
+  FUNCTION(strncasecmp, int (*f)(const char*, const char*, size_t));
+  FUNCTION(strncasecmp_l, int (*f)(const char*, const char*, size_t, locale_t));
+
+  TYPE(locale_t);
+  TYPE(size_t);
+}
diff --git a/tests/headers/posix/sys_ipc_h.c b/tests/headers/posix/sys_ipc_h.c
new file mode 100644
index 0000000..48273e4
--- /dev/null
+++ b/tests/headers/posix/sys_ipc_h.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/ipc.h>
+
+#include "header_checks.h"
+
+static void sys_ipc_h() {
+  TYPE(struct ipc_perm);
+  STRUCT_MEMBER(struct ipc_perm, uid_t, uid);
+  STRUCT_MEMBER(struct ipc_perm, gid_t, gid);
+  STRUCT_MEMBER(struct ipc_perm, uid_t, cuid);
+  STRUCT_MEMBER(struct ipc_perm, gid_t, cgid);
+#if defined(__GLIBC__)
+  STRUCT_MEMBER(struct ipc_perm, unsigned short, mode);
+#else
+  STRUCT_MEMBER(struct ipc_perm, mode_t, mode);
+#endif
+
+  TYPE(uid_t);
+  TYPE(gid_t);
+  TYPE(mode_t);
+  TYPE(key_t);
+
+  MACRO(IPC_CREAT);
+  MACRO(IPC_EXCL);
+  MACRO(IPC_NOWAIT);
+
+  MACRO(IPC_PRIVATE);
+
+  MACRO(IPC_RMID);
+  MACRO(IPC_SET);
+  MACRO(IPC_STAT);
+
+  FUNCTION(ftok, key_t (*f)(const char*, int));
+}
diff --git a/tests/headers/posix/sys_mman_h.c b/tests/headers/posix/sys_mman_h.c
new file mode 100644
index 0000000..5ec889c
--- /dev/null
+++ b/tests/headers/posix/sys_mman_h.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/mman.h>
+
+#include "header_checks.h"
+
+static void sys_mman_h() {
+  MACRO(PROT_EXEC);
+  MACRO(PROT_NONE);
+  MACRO(PROT_READ);
+  MACRO(PROT_WRITE);
+
+  MACRO(MAP_FIXED);
+  MACRO(MAP_PRIVATE);
+  MACRO(MAP_SHARED);
+
+  MACRO(MS_ASYNC);
+  MACRO(MS_INVALIDATE);
+  MACRO(MS_SYNC);
+
+  MACRO(MCL_CURRENT);
+  MACRO(MCL_FUTURE);
+
+  void* p;
+  p = MAP_FAILED;
+
+  MACRO(POSIX_MADV_DONTNEED);
+  MACRO(POSIX_MADV_NORMAL);
+  MACRO(POSIX_MADV_RANDOM);
+  MACRO(POSIX_MADV_SEQUENTIAL);
+  MACRO(POSIX_MADV_WILLNEED);
+
+#if !defined(__linux__)
+  MACRO(POSIX_TYPED_MEM_ALLOCATE);
+  MACRO(POSIX_TYPED_MEM_ALLOCATE_CONTIG);
+  MACRO(POSIX_TYPED_MEM_ALLOCATABLE);
+#endif
+
+  TYPE(mode_t);
+  TYPE(off_t);
+  TYPE(size_t);
+
+#if !defined(__linux__)
+  TYPE(struct posix_typed_mem_info);
+  STRUCT_MEMBER(struct posix_typed_mem_info, size_t, posix_tmi_length);
+#endif
+
+  FUNCTION(mlock, int (*f)(const void*, size_t));
+  FUNCTION(mlockall, int (*f)(int));
+  FUNCTION(mmap, void* (*f)(void*, size_t, int, int, int, off_t));
+  FUNCTION(mprotect, int (*f)(void*, size_t, int));
+  FUNCTION(msync, int (*f)(void*, size_t, int));
+  FUNCTION(munlock, int (*f)(const void*, size_t));
+  FUNCTION(munlockall, int (*f)(void));
+  FUNCTION(munmap, int (*f)(void*, size_t));
+  FUNCTION(posix_madvise, int (*f)(void*, size_t, int));
+#if !defined(__linux__)
+  FUNCTION(posix_mem_offset, int (*f)(const void*, size_t, off_t*, size_t*, int*));
+  FUNCTION(posix_typed_mem_get_info, int (*f)(int, struct posix_typed_mem_info*));
+  FUNCTION(posix_typed_mem_open, int (*f)(const char*, int, int));
+#endif
+#if !defined(__BIONIC__) // Disallowed by SELinux, so not implemented.
+  FUNCTION(shm_open, int (*f)(const char*, int, mode_t));
+  FUNCTION(shm_unlink, int (*f)(const char*));
+#endif
+}
diff --git a/tests/headers/posix/sys_msg_h.c b/tests/headers/posix/sys_msg_h.c
new file mode 100644
index 0000000..b908188
--- /dev/null
+++ b/tests/headers/posix/sys_msg_h.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/msg.h>
+
+#include "header_checks.h"
+
+static void sys_msg_h() {
+  TYPE(msgqnum_t);
+  TYPE(msglen_t);
+
+  MACRO(MSG_NOERROR);
+
+  TYPE(struct msqid_ds);
+  STRUCT_MEMBER(struct msqid_ds, struct ipc_perm, msg_perm);
+  STRUCT_MEMBER(struct msqid_ds, msgqnum_t, msg_qnum);
+  STRUCT_MEMBER(struct msqid_ds, msglen_t, msg_qbytes);
+  STRUCT_MEMBER(struct msqid_ds, pid_t, msg_lspid);
+  STRUCT_MEMBER(struct msqid_ds, pid_t, msg_lrpid);
+  STRUCT_MEMBER(struct msqid_ds, time_t, msg_stime);
+  STRUCT_MEMBER(struct msqid_ds, time_t, msg_rtime);
+  STRUCT_MEMBER(struct msqid_ds, time_t, msg_ctime);
+
+  TYPE(pid_t);
+  TYPE(size_t);
+  TYPE(ssize_t);
+  TYPE(time_t);
+
+  FUNCTION(msgctl, int (*f)(int, int, struct msqid_ds*));
+  FUNCTION(msgget, int (*f)(key_t, int));
+  FUNCTION(msgrcv, ssize_t (*f)(int, void*, size_t, long, int));
+  FUNCTION(msgsnd, int (*f)(int, const void*, size_t, int));
+}
diff --git a/tests/headers/posix/sys_resource_h.c b/tests/headers/posix/sys_resource_h.c
new file mode 100644
index 0000000..0e95fd5
--- /dev/null
+++ b/tests/headers/posix/sys_resource_h.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/resource.h>
+
+#include "header_checks.h"
+
+static void sys_resource_h() {
+  MACRO(PRIO_PROCESS);
+  MACRO(PRIO_PGRP);
+  MACRO(PRIO_USER);
+
+  TYPE(rlim_t);
+
+  MACRO(RLIM_INFINITY);
+  MACRO(RLIM_SAVED_MAX);
+  MACRO(RLIM_SAVED_CUR);
+
+  MACRO(RUSAGE_SELF);
+  MACRO(RUSAGE_CHILDREN);
+
+  TYPE(struct rlimit);
+  STRUCT_MEMBER(struct rlimit, rlim_t, rlim_cur);
+  STRUCT_MEMBER(struct rlimit, rlim_t, rlim_max);
+
+  TYPE(struct rusage);
+  STRUCT_MEMBER(struct rusage, struct timeval, ru_utime);
+  STRUCT_MEMBER(struct rusage, struct timeval, ru_stime);
+
+  TYPE(struct timeval);
+
+  MACRO(RLIMIT_CORE);
+  MACRO(RLIMIT_CPU);
+  MACRO(RLIMIT_DATA);
+  MACRO(RLIMIT_FSIZE);
+  MACRO(RLIMIT_NOFILE);
+  MACRO(RLIMIT_STACK);
+  MACRO(RLIMIT_AS);
+
+  FUNCTION(getpriority, int (*f)(int, id_t));
+  FUNCTION(getrlimit, int (*f)(int, struct rlimit*));
+  FUNCTION(getrusage, int (*f)(int, struct rusage*));
+  FUNCTION(setpriority, int (*f)(int, id_t, int));
+  FUNCTION(setrlimit, int (*f)(int, const struct rlimit*));
+}
diff --git a/tests/headers/posix/sys_select_h.c b/tests/headers/posix/sys_select_h.c
new file mode 100644
index 0000000..32c6f57
--- /dev/null
+++ b/tests/headers/posix/sys_select_h.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/select.h>
+
+#include "header_checks.h"
+
+static void sys_select_h() {
+  TYPE(struct timeval);
+  STRUCT_MEMBER(struct timeval, time_t, tv_sec);
+  STRUCT_MEMBER(struct timeval, suseconds_t, tv_usec);
+
+  TYPE(time_t);
+  TYPE(suseconds_t);
+
+  TYPE(sigset_t);
+  TYPE(struct timespec);
+  TYPE(fd_set);
+
+  MACRO(FD_SETSIZE);
+
+#if !defined(FD_CLR)
+#error FD_CLR
+#endif
+#if !defined(FD_ISSET)
+#error FD_ISSET
+#endif
+#if !defined(FD_SET)
+#error FD_SET
+#endif
+#if !defined(FD_ZERO)
+#error FD_ZERO
+#endif
+
+  FUNCTION(pselect, int (*f)(int, fd_set*, fd_set*, fd_set*, const struct timespec*, const sigset_t*));
+  FUNCTION(select, int (*f)(int, fd_set*, fd_set*, fd_set*, struct timeval*));
+}
diff --git a/tests/headers/posix/sys_sem_h.c b/tests/headers/posix/sys_sem_h.c
new file mode 100644
index 0000000..1b1b16d
--- /dev/null
+++ b/tests/headers/posix/sys_sem_h.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/sem.h>
+
+#include "header_checks.h"
+
+static void sys_sem_h() {
+  MACRO(SEM_UNDO);
+
+  MACRO(GETNCNT);
+  MACRO(GETPID);
+  MACRO(GETVAL);
+  MACRO(GETALL);
+  MACRO(GETZCNT);
+  MACRO(SETVAL);
+  MACRO(SETALL);
+
+  TYPE(struct semid_ds);
+  STRUCT_MEMBER(struct semid_ds, struct ipc_perm, sem_perm);
+#if defined(__linux__) // POSIX says short, Linux says long.
+  STRUCT_MEMBER(struct semid_ds, unsigned long, sem_nsems);
+#else
+  STRUCT_MEMBER(struct semid_ds, unsigned short, sem_nsems);
+#endif
+  STRUCT_MEMBER(struct semid_ds, time_t, sem_otime);
+  STRUCT_MEMBER(struct semid_ds, time_t, sem_ctime);
+
+  TYPE(pid_t);
+  TYPE(size_t);
+  TYPE(time_t);
+
+  TYPE(struct sembuf);
+  STRUCT_MEMBER(struct sembuf, unsigned short, sem_num);
+  STRUCT_MEMBER(struct sembuf, short, sem_op);
+  STRUCT_MEMBER(struct sembuf, short, sem_flg);
+
+  FUNCTION(semctl, int (*f)(int, int, int, ...));
+  FUNCTION(semget, int (*f)(key_t, int, int));
+  FUNCTION(semop, int (*f)(int, struct sembuf*, size_t));
+}
diff --git a/tests/headers/posix/sys_shm_h.c b/tests/headers/posix/sys_shm_h.c
new file mode 100644
index 0000000..4ecd6d3
--- /dev/null
+++ b/tests/headers/posix/sys_shm_h.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/shm.h>
+
+#include "header_checks.h"
+
+static void sys_shm_h() {
+  MACRO(SHM_RDONLY);
+  MACRO(SHM_RND);
+  MACRO(SHMLBA);
+
+  TYPE(shmatt_t);
+
+  TYPE(struct shmid_ds);
+  STRUCT_MEMBER(struct shmid_ds, struct ipc_perm, shm_perm);
+  STRUCT_MEMBER(struct shmid_ds, size_t, shm_segsz);
+  STRUCT_MEMBER(struct shmid_ds, pid_t, shm_lpid);
+  STRUCT_MEMBER(struct shmid_ds, pid_t, shm_cpid);
+  STRUCT_MEMBER(struct shmid_ds, shmatt_t, shm_nattch);
+  STRUCT_MEMBER(struct shmid_ds, time_t, shm_atime);
+  STRUCT_MEMBER(struct shmid_ds, time_t, shm_dtime);
+  STRUCT_MEMBER(struct shmid_ds, time_t, shm_ctime);
+
+  TYPE(pid_t);
+  TYPE(size_t);
+  TYPE(time_t);
+
+  FUNCTION(shmat, void* (*f)(int, const void*, int));
+  FUNCTION(shmctl, int (*f)(int, int, struct shmid_ds*));
+  FUNCTION(shmdt, int (*f)(const void*));
+  FUNCTION(shmget, int (*f)(key_t, size_t, int));
+}
diff --git a/tests/headers/posix/sys_socket_h.c b/tests/headers/posix/sys_socket_h.c
new file mode 100644
index 0000000..ed437f3
--- /dev/null
+++ b/tests/headers/posix/sys_socket_h.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/socket.h>
+
+#include "header_checks.h"
+
+static void sys_socket_h() {
+  TYPE(socklen_t);
+  TYPE(sa_family_t);
+
+  TYPE(struct sockaddr);
+  STRUCT_MEMBER(struct sockaddr, sa_family_t, sa_family);
+  STRUCT_MEMBER_ARRAY(struct sockaddr, char/*[]*/, sa_data);
+
+  TYPE(struct sockaddr_storage);
+  STRUCT_MEMBER(struct sockaddr_storage, sa_family_t, ss_family);
+
+  TYPE(struct msghdr);
+  STRUCT_MEMBER(struct msghdr, void*, msg_name);
+  STRUCT_MEMBER(struct msghdr, socklen_t, msg_namelen);
+  STRUCT_MEMBER(struct msghdr, struct iovec*, msg_iov);
+#if defined(__BIONIC__) || defined(__GLIBC__)
+  STRUCT_MEMBER(struct msghdr, size_t, msg_iovlen);
+#else
+  STRUCT_MEMBER(struct msghdr, int, msg_iovlen);
+#endif
+  STRUCT_MEMBER(struct msghdr, void*, msg_control);
+#if defined(__BIONIC__) || defined(__GLIBC__)
+  STRUCT_MEMBER(struct msghdr, size_t, msg_controllen);
+#else
+  STRUCT_MEMBER(struct msghdr, socklen_t, msg_controllen);
+#endif
+  STRUCT_MEMBER(struct msghdr, int, msg_flags);
+
+  TYPE(struct iovec);
+
+  TYPE(struct cmsghdr);
+#if defined(__BIONIC__) || defined(__GLIBC__)
+  STRUCT_MEMBER(struct cmsghdr, size_t, cmsg_len);
+#else
+  STRUCT_MEMBER(struct cmsghdr, socklen_t, cmsg_len);
+#endif
+  STRUCT_MEMBER(struct cmsghdr, int, cmsg_level);
+  STRUCT_MEMBER(struct cmsghdr, int, cmsg_type);
+
+  MACRO(SCM_RIGHTS);
+
+#if !defined(CMSG_DATA)
+#error CMSG_DATA
+#endif
+#if !defined(CMSG_NXTHDR)
+#error CMSG_NXTHDR
+#endif
+#if !defined(CMSG_FIRSTHDR)
+#error CMSG_FIRSTHDR
+#endif
+
+  TYPE(struct linger);
+  STRUCT_MEMBER(struct linger, int, l_onoff);
+  STRUCT_MEMBER(struct linger, int, l_linger);
+
+  MACRO(SOCK_DGRAM);
+  MACRO(SOCK_RAW);
+  MACRO(SOCK_SEQPACKET);
+  MACRO(SOCK_STREAM);
+
+  MACRO(SOL_SOCKET);
+
+  MACRO(SO_ACCEPTCONN);
+  MACRO(SO_BROADCAST);
+  MACRO(SO_DEBUG);
+  MACRO(SO_DONTROUTE);
+  MACRO(SO_ERROR);
+  MACRO(SO_KEEPALIVE);
+  MACRO(SO_LINGER);
+  MACRO(SO_OOBINLINE);
+  MACRO(SO_RCVBUF);
+  MACRO(SO_RCVLOWAT);
+  MACRO(SO_RCVTIMEO);
+  MACRO(SO_REUSEADDR);
+  MACRO(SO_SNDBUF);
+  MACRO(SO_SNDLOWAT);
+  MACRO(SO_SNDTIMEO);
+  MACRO(SO_TYPE);
+
+  MACRO(SOMAXCONN);
+
+  MACRO(MSG_CTRUNC);
+  MACRO(MSG_DONTROUTE);
+  MACRO(MSG_EOR);
+  MACRO(MSG_OOB);
+  MACRO(MSG_NOSIGNAL);
+  MACRO(MSG_PEEK);
+  MACRO(MSG_TRUNC);
+  MACRO(MSG_WAITALL);
+
+  MACRO(AF_INET);
+  MACRO(AF_INET6);
+  MACRO(AF_UNIX);
+  MACRO_VALUE(AF_UNSPEC, 0);
+
+  MACRO(SHUT_RD);
+  MACRO(SHUT_RDWR);
+  MACRO(SHUT_WR);
+
+  TYPE(size_t);
+  TYPE(ssize_t);
+
+  FUNCTION(accept, int (*f)(int, struct sockaddr*, socklen_t*));
+  FUNCTION(bind, int (*f)(int, const struct sockaddr*, socklen_t));
+  FUNCTION(connect, int (*f)(int, const struct sockaddr*, socklen_t));
+  FUNCTION(getpeername, int (*f)(int, struct sockaddr*, socklen_t*));
+  FUNCTION(getsockname, int (*f)(int, struct sockaddr*, socklen_t*));
+  FUNCTION(getsockopt, int (*f)(int, int, int, void*, socklen_t*));
+  FUNCTION(listen, int (*f)(int, int));
+  FUNCTION(recv, ssize_t (*f)(int, void*, size_t, int));
+  FUNCTION(recvfrom, ssize_t (*f)(int, void*, size_t, int, struct sockaddr*, socklen_t*));
+  FUNCTION(send, ssize_t (*f)(int, const void*, size_t, int));
+  FUNCTION(sendmsg, ssize_t (*f)(int, const struct msghdr*, int));
+  FUNCTION(sendto, ssize_t (*f)(int, const void*, size_t, int, const struct sockaddr*, socklen_t));
+  FUNCTION(setsockopt, int (*f)(int, int, int, const void*, socklen_t));
+  FUNCTION(shutdown, int (*f)(int, int));
+#if !defined(__BIONIC__) // Obsolete, plus ioctl disallowed by SELinux.
+  FUNCTION(sockatmark, int (*f)(int));
+#endif
+  FUNCTION(socket, int (*f)(int, int, int));
+  FUNCTION(socketpair, int (*f)(int, int, int, int[2]));
+}
diff --git a/tests/headers/posix/sys_stat_h.c b/tests/headers/posix/sys_stat_h.c
new file mode 100644
index 0000000..5764dfb
--- /dev/null
+++ b/tests/headers/posix/sys_stat_h.c
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/stat.h>
+
+#include "header_checks.h"
+
+static void sys_stat_h() {
+  TYPE(struct stat);
+#if defined(__BIONIC__) && (defined(__arm__) || defined(__i386__))
+  STRUCT_MEMBER(struct stat, unsigned long long, st_dev);
+#else
+  STRUCT_MEMBER(struct stat, dev_t, st_dev);
+#endif
+#if defined(__BIONIC__) && !defined(__LP64__)
+  STRUCT_MEMBER(struct stat, unsigned long long, st_ino);
+#else
+  STRUCT_MEMBER(struct stat, ino_t, st_ino);
+#endif
+#if defined(__BIONIC__) && (defined(__arm__) || defined(__i386__))
+  STRUCT_MEMBER(struct stat, unsigned int, st_mode);
+#else
+  STRUCT_MEMBER(struct stat, mode_t, st_mode);
+#endif
+#if defined(__BIONIC__) && defined(__x86_64__)
+  // We can't just fix the x86_64 nlink_t because it's ABI via <fts.h>.
+  STRUCT_MEMBER(struct stat, unsigned long, st_nlink);
+#else
+  STRUCT_MEMBER(struct stat, nlink_t, st_nlink);
+#endif
+  STRUCT_MEMBER(struct stat, uid_t, st_uid);
+  STRUCT_MEMBER(struct stat, gid_t, st_gid);
+#if defined(__BIONIC__) && (defined(__arm__) || defined(__i386__))
+  STRUCT_MEMBER(struct stat, unsigned long long, st_rdev);
+#else
+  STRUCT_MEMBER(struct stat, dev_t, st_rdev);
+#endif
+#if defined(__BIONIC__) && !defined(__LP64__)
+  STRUCT_MEMBER(struct stat, long long, st_size);
+#else
+  STRUCT_MEMBER(struct stat, off_t, st_size);
+#endif
+  STRUCT_MEMBER(struct stat, struct timespec, st_atim);
+  STRUCT_MEMBER(struct stat, struct timespec, st_mtim);
+  STRUCT_MEMBER(struct stat, struct timespec, st_ctim);
+#if defined(__BIONIC__)
+#if defined(__aarch64__) || (defined(__mips__) && defined(__LP64__))
+  STRUCT_MEMBER(struct stat, int, st_blksize);
+#elif defined(__mips__) && !defined(__LP64__)
+  STRUCT_MEMBER(struct stat, unsigned int, st_blksize);
+#elif defined(__x86_64__)
+  STRUCT_MEMBER(struct stat, long, st_blksize);
+#else
+  STRUCT_MEMBER(struct stat, unsigned long, st_blksize);
+#endif
+#else
+  STRUCT_MEMBER(struct stat, blksize_t, st_blksize);
+#endif
+#if defined(__BIONIC__)
+#if defined(__LP64__)
+  STRUCT_MEMBER(struct stat, long, st_blocks);
+#else
+  STRUCT_MEMBER(struct stat, unsigned long long, st_blocks);
+#endif
+#else
+  STRUCT_MEMBER(struct stat, blkcnt_t, st_blocks);
+#endif
+
+  TYPE(blkcnt_t);
+  TYPE(blksize_t);
+  TYPE(dev_t);
+  TYPE(ino_t);
+  TYPE(mode_t);
+  TYPE(nlink_t);
+  TYPE(uid_t);
+  TYPE(gid_t);
+  TYPE(off_t);
+  TYPE(time_t);
+
+  TYPE(struct timespec);
+
+#if !defined(st_atime)
+#error st_atime
+#endif
+#if !defined(st_ctime)
+#error st_ctime
+#endif
+#if !defined(st_mtime)
+#error st_mtime
+#endif
+
+#include "sys_stat_h_mode_constants.h"
+#include "sys_stat_h_file_type_test_macros.h"
+
+#if !defined(S_TYPEISMQ)
+#error S_TYPEISMQ
+#endif
+#if !defined(S_TYPEISSEM)
+#error S_TYPEISSEM
+#endif
+#if !defined(S_TYPEISSHM)
+#error S_TYPEISSHM
+#endif
+
+#if !defined(__BIONIC__) && !defined(__GLIBC__)
+#if !defined(S_TYPEISTMO)
+#error S_TYPEISTMO
+#endif
+#endif
+
+  MACRO(UTIME_NOW);
+  MACRO(UTIME_OMIT);
+
+  FUNCTION(chmod, int (*f)(const char*, mode_t));
+  FUNCTION(fchmod, int (*f)(int, mode_t));
+  FUNCTION(fchmodat, int (*f)(int, const char*, mode_t, int));
+  FUNCTION(fstat, int (*f)(int, struct stat*));
+  FUNCTION(fstatat, int (*f)(int, const char*, struct stat*, int));
+  FUNCTION(futimens, int (*f)(int, const struct timespec[2]));
+  FUNCTION(lstat, int (*f)(const char*, struct stat*));
+  FUNCTION(lstat, int (*f)(const char*, struct stat*));
+  FUNCTION(mkdir, int (*f)(const char*, mode_t));
+  FUNCTION(mkdirat, int (*f)(int, const char*, mode_t));
+  FUNCTION(mkfifo, int (*f)(const char*, mode_t));
+  FUNCTION(mkfifoat, int (*f)(int, const char*, mode_t));
+  FUNCTION(mknod, int (*f)(const char*, mode_t, dev_t));
+  FUNCTION(mknodat, int (*f)(int, const char*, mode_t, dev_t));
+  FUNCTION(stat, int (*f)(const char*, struct stat*));
+  FUNCTION(umask, mode_t (*f)(mode_t));
+  FUNCTION(utimensat, int (*f)(int, const char*, const struct timespec[2], int));
+}
diff --git a/tests/headers/posix/sys_stat_h_file_type_test_macros.h b/tests/headers/posix/sys_stat_h_file_type_test_macros.h
new file mode 100644
index 0000000..5e09fdb
--- /dev/null
+++ b/tests/headers/posix/sys_stat_h_file_type_test_macros.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if !defined(S_ISBLK)
+#error S_ISBLK
+#endif
+#if !defined(S_ISCHR)
+#error S_ISCHR
+#endif
+#if !defined(S_ISDIR)
+#error S_ISDIR
+#endif
+#if !defined(S_ISFIFO)
+#error S_ISFIFO
+#endif
+#if !defined(S_ISREG)
+#error S_ISREG
+#endif
+#if !defined(S_ISLNK)
+#error S_ISLNK
+#endif
+#if !defined(S_ISSOCK)
+#error S_ISSOCK
+#endif
diff --git a/tests/headers/posix/sys_stat_h_mode_constants.h b/tests/headers/posix/sys_stat_h_mode_constants.h
new file mode 100644
index 0000000..cce8469
--- /dev/null
+++ b/tests/headers/posix/sys_stat_h_mode_constants.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+  MACRO(S_IFMT);
+  MACRO(S_IFBLK);
+  MACRO(S_IFCHR);
+  MACRO(S_IFIFO);
+  MACRO(S_IFREG);
+  MACRO(S_IFDIR);
+  MACRO(S_IFLNK);
+  MACRO(S_IFSOCK);
+
+  MACRO_VALUE(S_IRWXU, 0700);
+  MACRO_VALUE(S_IRUSR, 0400);
+  MACRO_VALUE(S_IWUSR, 0200);
+  MACRO_VALUE(S_IXUSR, 0100);
+
+  MACRO_VALUE(S_IRWXG, 070);
+  MACRO_VALUE(S_IRGRP, 040);
+  MACRO_VALUE(S_IWGRP, 020);
+  MACRO_VALUE(S_IXGRP, 010);
+
+  MACRO_VALUE(S_IRWXO, 07);
+  MACRO_VALUE(S_IROTH, 04);
+  MACRO_VALUE(S_IWOTH, 02);
+  MACRO_VALUE(S_IXOTH, 01);
+
+  MACRO_VALUE(S_ISUID, 04000);
+  MACRO_VALUE(S_ISGID, 02000);
+  MACRO_VALUE(S_ISVTX, 01000);
diff --git a/tests/headers/posix/sys_statvfs_h.c b/tests/headers/posix/sys_statvfs_h.c
new file mode 100644
index 0000000..b44a93a
--- /dev/null
+++ b/tests/headers/posix/sys_statvfs_h.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/statvfs.h>
+
+#include "header_checks.h"
+
+static void sys_statvfs_h() {
+  TYPE(struct statvfs);
+  STRUCT_MEMBER(struct statvfs, unsigned long, f_bsize);
+  STRUCT_MEMBER(struct statvfs, unsigned long, f_frsize);
+  STRUCT_MEMBER(struct statvfs, fsblkcnt_t, f_blocks);
+  STRUCT_MEMBER(struct statvfs, fsblkcnt_t, f_bfree);
+  STRUCT_MEMBER(struct statvfs, fsblkcnt_t, f_bavail);
+  STRUCT_MEMBER(struct statvfs, fsfilcnt_t, f_files);
+  STRUCT_MEMBER(struct statvfs, fsfilcnt_t, f_ffree);
+  STRUCT_MEMBER(struct statvfs, fsfilcnt_t, f_favail);
+  STRUCT_MEMBER(struct statvfs, unsigned long, f_fsid);
+  STRUCT_MEMBER(struct statvfs, unsigned long, f_flag);
+  STRUCT_MEMBER(struct statvfs, unsigned long, f_namemax);
+
+  TYPE(fsblkcnt_t);
+  TYPE(fsfilcnt_t);
+
+  MACRO(ST_RDONLY);
+  MACRO(ST_NOSUID);
+
+  FUNCTION(fstatvfs, int (*f)(int, struct statvfs*));
+  FUNCTION(statvfs, int (*f)(const char*, struct statvfs*));
+}
diff --git a/tests/headers/posix/sys_time_h.c b/tests/headers/posix/sys_time_h.c
new file mode 100644
index 0000000..394abd2
--- /dev/null
+++ b/tests/headers/posix/sys_time_h.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/time.h>
+
+#include "header_checks.h"
+
+static void sys_time_h() {
+  TYPE(struct timeval);
+  STRUCT_MEMBER(struct timeval, time_t, tv_sec);
+  STRUCT_MEMBER(struct timeval, suseconds_t, tv_usec);
+
+  TYPE(struct itimerval);
+  STRUCT_MEMBER(struct itimerval, struct timeval, it_interval);
+  STRUCT_MEMBER(struct itimerval, struct timeval, it_value);
+
+  TYPE(time_t);
+  TYPE(suseconds_t);
+
+  TYPE(fd_set);
+
+  MACRO(ITIMER_REAL);
+  MACRO(ITIMER_VIRTUAL);
+  MACRO(ITIMER_PROF);
+
+#if !defined(FD_CLR)
+#error FD_CLR
+#endif
+#if !defined(FD_ISSET)
+#error FD_ISSET
+#endif
+#if !defined(FD_SET)
+#error FD_SET
+#endif
+#if !defined(FD_ZERO)
+#error FD_ZERO
+#endif
+  MACRO(FD_SETSIZE);
+
+  FUNCTION(getitimer, int (*f)(int, struct itimerval*));
+#if defined(__BIONIC__)
+  FUNCTION(gettimeofday, int (*f)(struct timeval*, struct timezone*));
+#else
+  FUNCTION(gettimeofday, int (*f)(struct timeval*, void*));
+#endif
+  FUNCTION(setitimer, int (*f)(int, const struct itimerval*, struct itimerval*));
+  FUNCTION(select, int (*f)(int, fd_set*, fd_set*, fd_set*, struct timeval*));
+  FUNCTION(utimes, int (*f)(const char*, const struct timeval[2]));
+}
diff --git a/tests/headers/posix/sys_times_h.c b/tests/headers/posix/sys_times_h.c
new file mode 100644
index 0000000..195d11b
--- /dev/null
+++ b/tests/headers/posix/sys_times_h.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/times.h>
+
+#include "header_checks.h"
+
+static void sys_times_h() {
+  TYPE(struct tms);
+  STRUCT_MEMBER(struct tms, clock_t, tms_utime);
+  STRUCT_MEMBER(struct tms, clock_t, tms_stime);
+  STRUCT_MEMBER(struct tms, clock_t, tms_cutime);
+  STRUCT_MEMBER(struct tms, clock_t, tms_cstime);
+
+  TYPE(clock_t);
+
+  FUNCTION(times, clock_t (*f)(struct tms*));
+}
diff --git a/tests/headers/posix/sys_types_h.c b/tests/headers/posix/sys_types_h.c
new file mode 100644
index 0000000..3b0f55f
--- /dev/null
+++ b/tests/headers/posix/sys_types_h.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#include "header_checks.h"
+
+static void sys_types_h() {
+  TYPE(blkcnt_t);
+  TYPE(blksize_t);
+  TYPE(clock_t);
+  TYPE(clockid_t);
+  TYPE(dev_t);
+  TYPE(fsblkcnt_t);
+  TYPE(fsfilcnt_t);
+  TYPE(gid_t);
+  TYPE(id_t);
+  TYPE(ino_t);
+  TYPE(key_t);
+  TYPE(mode_t);
+  TYPE(nlink_t);
+  TYPE(off_t);
+  TYPE(pid_t);
+  TYPE(pthread_attr_t);
+  TYPE(pthread_barrier_t);
+  TYPE(pthread_barrierattr_t);
+  TYPE(pthread_cond_t);
+  TYPE(pthread_condattr_t);
+  TYPE(pthread_key_t);
+  TYPE(pthread_mutex_t);
+  TYPE(pthread_mutexattr_t);
+  TYPE(pthread_once_t);
+  TYPE(pthread_rwlock_t);
+  TYPE(pthread_rwlockattr_t);
+  TYPE(pthread_spinlock_t);
+  TYPE(pthread_t);
+  TYPE(size_t);
+  TYPE(ssize_t);
+  TYPE(suseconds_t);
+  TYPE(time_t);
+  TYPE(timer_t);
+  TYPE(uid_t);
+}
diff --git a/tests/headers/posix/sys_uio_h.c b/tests/headers/posix/sys_uio_h.c
new file mode 100644
index 0000000..90b210d
--- /dev/null
+++ b/tests/headers/posix/sys_uio_h.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/uio.h>
+
+#include "header_checks.h"
+
+static void sys_uio_h() {
+  TYPE(struct iovec);
+  STRUCT_MEMBER(struct iovec, void*, iov_base);
+  STRUCT_MEMBER(struct iovec, size_t, iov_len);
+
+  TYPE(ssize_t);
+  TYPE(size_t);
+
+  FUNCTION(readv, ssize_t (*f)(int, const struct iovec*, int));
+  FUNCTION(writev, ssize_t (*f)(int, const struct iovec*, int));
+}
diff --git a/tests/headers/posix/sys_un_h.c b/tests/headers/posix/sys_un_h.c
new file mode 100644
index 0000000..d48ac61
--- /dev/null
+++ b/tests/headers/posix/sys_un_h.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/un.h>
+
+#include "header_checks.h"
+
+static void sys_un_h() {
+  TYPE(struct sockaddr_un);
+  STRUCT_MEMBER(struct sockaddr_un, sa_family_t, sun_family);
+  STRUCT_MEMBER_ARRAY(struct sockaddr_un, char/*[]*/, sun_path);
+
+  TYPE(sa_family_t);
+}
diff --git a/tests/headers/posix/sys_utsname_h.c b/tests/headers/posix/sys_utsname_h.c
new file mode 100644
index 0000000..5ebd703
--- /dev/null
+++ b/tests/headers/posix/sys_utsname_h.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/utsname.h>
+
+#include "header_checks.h"
+
+static void sys_utsname_h() {
+  TYPE(struct utsname);
+  STRUCT_MEMBER_ARRAY(struct utsname, char/*[]*/, sysname);
+  STRUCT_MEMBER_ARRAY(struct utsname, char/*[]*/, nodename);
+  STRUCT_MEMBER_ARRAY(struct utsname, char/*[]*/, release);
+  STRUCT_MEMBER_ARRAY(struct utsname, char/*[]*/, version);
+  STRUCT_MEMBER_ARRAY(struct utsname, char/*[]*/, machine);
+
+  FUNCTION(uname, int (*f)(struct utsname*));
+}
diff --git a/tests/headers/posix/sys_wait_h.c b/tests/headers/posix/sys_wait_h.c
new file mode 100644
index 0000000..406e051
--- /dev/null
+++ b/tests/headers/posix/sys_wait_h.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/wait.h>
+
+#include "header_checks.h"
+
+static void sys_wait_h() {
+  MACRO(WCONTINUED);
+  MACRO(WNOHANG);
+  MACRO(WUNTRACED);
+
+#if !defined(WEXITSTATUS)
+#error WEXITSTATUS
+#endif
+#if !defined(WIFCONTINUED)
+#error WIFCONTINUED
+#endif
+#if !defined(WIFEXITED)
+#error WIFEXITED
+#endif
+#if !defined(WIFSIGNALED)
+#error WIFSIGNALED
+#endif
+#if !defined(WIFSTOPPED)
+#error WIFSTOPPED
+#endif
+#if !defined(WSTOPSIG)
+#error WSTOPSIG
+#endif
+#if !defined(WTERMSIG)
+#error WTERMSIG
+#endif
+
+  MACRO(WEXITED);
+  MACRO(WNOWAIT);
+  MACRO(WSTOPPED);
+
+  TYPE(idtype_t);
+  MACRO(P_ALL);
+  MACRO(P_PGID);
+  MACRO(P_PID);
+
+  TYPE(id_t);
+  TYPE(pid_t);
+  TYPE(siginfo_t);
+  TYPE(union sigval);
+
+  FUNCTION(wait, pid_t (*f)(int*));
+  FUNCTION(waitid, int (*f)(idtype_t, id_t, siginfo_t*, int));
+  FUNCTION(waitpid, pid_t (*f)(pid_t, int*, int));
+}
diff --git a/tests/headers/posix/syslog_h.c b/tests/headers/posix/syslog_h.c
new file mode 100644
index 0000000..b43f49e
--- /dev/null
+++ b/tests/headers/posix/syslog_h.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <syslog.h>
+
+#include "header_checks.h"
+
+static void syslog_h() {
+  MACRO(LOG_PID);
+  MACRO(LOG_CONS);
+  MACRO(LOG_NDELAY);
+  MACRO(LOG_ODELAY);
+  MACRO(LOG_NOWAIT);
+
+  MACRO(LOG_KERN);
+  MACRO(LOG_USER);
+  MACRO(LOG_MAIL);
+  MACRO(LOG_NEWS);
+  MACRO(LOG_UUCP);
+  MACRO(LOG_DAEMON);
+  MACRO(LOG_AUTH);
+  MACRO(LOG_CRON);
+  MACRO(LOG_LPR);
+  MACRO(LOG_LOCAL0);
+  MACRO(LOG_LOCAL1);
+  MACRO(LOG_LOCAL2);
+  MACRO(LOG_LOCAL3);
+  MACRO(LOG_LOCAL4);
+  MACRO(LOG_LOCAL5);
+  MACRO(LOG_LOCAL6);
+  MACRO(LOG_LOCAL7);
+
+#if !defined(LOG_MASK)
+#error LOG_MASK
+#endif
+
+  MACRO(LOG_EMERG);
+  MACRO(LOG_ALERT);
+  MACRO(LOG_CRIT);
+  MACRO(LOG_ERR);
+  MACRO(LOG_WARNING);
+  MACRO(LOG_NOTICE);
+  MACRO(LOG_INFO);
+  MACRO(LOG_DEBUG);
+
+  FUNCTION(closelog, void (*f)(void));
+  FUNCTION(openlog, void (*f)(const char*, int, int));
+  FUNCTION(setlogmask, int (*f)(int));
+  FUNCTION(syslog, void (*f)(int, const char*, ...));
+}
diff --git a/tests/headers/posix/tar_h.c b/tests/headers/posix/tar_h.c
new file mode 100644
index 0000000..bd22c17
--- /dev/null
+++ b/tests/headers/posix/tar_h.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <tar.h>
+
+#include "header_checks.h"
+
+static void tar_h() {
+  MACRO(TMAGIC);
+  MACRO_VALUE(TMAGLEN, 6);
+  MACRO(TVERSION);
+  MACRO_VALUE(TVERSLEN, 2);
+
+  MACRO_VALUE(REGTYPE, '0');
+  MACRO_VALUE(AREGTYPE, '\0');
+  MACRO_VALUE(LNKTYPE, '1');
+  MACRO_VALUE(SYMTYPE, '2');
+  MACRO_VALUE(CHRTYPE, '3');
+  MACRO_VALUE(BLKTYPE, '4');
+  MACRO_VALUE(DIRTYPE, '5');
+  MACRO_VALUE(FIFOTYPE, '6');
+  MACRO_VALUE(CONTTYPE, '7');
+
+  MACRO_VALUE(TSUID, 04000);
+  MACRO_VALUE(TSGID, 02000);
+  MACRO_VALUE(TSVTX, 01000);
+  MACRO_VALUE(TUREAD, 0400);
+  MACRO_VALUE(TUWRITE, 0200);
+  MACRO_VALUE(TUEXEC, 0100);
+  MACRO_VALUE(TGREAD, 040);
+  MACRO_VALUE(TGWRITE, 020);
+  MACRO_VALUE(TGEXEC, 010);
+  MACRO_VALUE(TOREAD, 04);
+  MACRO_VALUE(TOWRITE, 02);
+  MACRO_VALUE(TOEXEC, 01);
+}
diff --git a/tests/headers/posix/termios_h.c b/tests/headers/posix/termios_h.c
new file mode 100644
index 0000000..1255c16
--- /dev/null
+++ b/tests/headers/posix/termios_h.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <termios.h>
+
+#include "header_checks.h"
+
+static void termios_h() {
+  TYPE(cc_t);
+  TYPE(speed_t);
+  TYPE(tcflag_t);
+
+  TYPE(struct termios);
+  STRUCT_MEMBER(struct termios, tcflag_t, c_iflag);
+  STRUCT_MEMBER(struct termios, tcflag_t, c_oflag);
+  STRUCT_MEMBER(struct termios, tcflag_t, c_cflag);
+  STRUCT_MEMBER(struct termios, tcflag_t, c_lflag);
+  STRUCT_MEMBER_ARRAY(struct termios, cc_t/*[]*/, c_cc);
+
+  MACRO(NCCS);
+
+  MACRO(VEOF);
+  MACRO(VEOL);
+  MACRO(VERASE);
+  MACRO(VINTR);
+  MACRO(VKILL);
+  MACRO(VMIN);
+  MACRO(VQUIT);
+  MACRO(VSTART);
+  MACRO(VSTOP);
+  MACRO(VSUSP);
+  MACRO(VTIME);
+
+  MACRO(BRKINT);
+  MACRO(ICRNL);
+  MACRO(IGNBRK);
+  MACRO(IGNCR);
+  MACRO(IGNPAR);
+  MACRO(INLCR);
+  MACRO(INPCK);
+  MACRO(ISTRIP);
+  MACRO(IXANY);
+  MACRO(IXOFF);
+  MACRO(IXON);
+  MACRO(PARMRK);
+
+  MACRO(OPOST);
+  MACRO(ONLCR);
+  MACRO(OCRNL);
+  MACRO(ONOCR);
+  MACRO(ONLRET);
+  MACRO(OFDEL);
+  MACRO(OFILL);
+  MACRO(NLDLY);
+  MACRO(NL0);
+  MACRO(NL1);
+  MACRO(CRDLY);
+  MACRO(CR0);
+  MACRO(CR1);
+  MACRO(CR2);
+  MACRO(CR3);
+  MACRO(TABDLY);
+  MACRO(TAB0);
+  MACRO(TAB1);
+  MACRO(TAB2);
+  MACRO(TAB3);
+  MACRO(BSDLY);
+  MACRO(BS0);
+  MACRO(BS1);
+  MACRO(VTDLY);
+  MACRO(VT0);
+  MACRO(VT1);
+  MACRO(FFDLY);
+  MACRO(FF0);
+  MACRO(FF1);
+
+  MACRO(B0);
+  MACRO(B50);
+  MACRO(B75);
+  MACRO(B110);
+  MACRO(B134);
+  MACRO(B150);
+  MACRO(B200);
+  MACRO(B300);
+  MACRO(B600);
+  MACRO(B1200);
+  MACRO(B1800);
+  MACRO(B2400);
+  MACRO(B4800);
+  MACRO(B9600);
+  MACRO(B19200);
+  MACRO(B38400);
+
+  MACRO(CSIZE);
+  MACRO(CS5);
+  MACRO(CS6);
+  MACRO(CS7);
+  MACRO(CS8);
+  MACRO(CSTOPB);
+  MACRO(CREAD);
+  MACRO(PARENB);
+  MACRO(PARODD);
+  MACRO(HUPCL);
+  MACRO(CLOCAL);
+
+  MACRO(ECHO);
+  MACRO(ECHOE);
+  MACRO(ECHOK);
+  MACRO(ECHONL);
+  MACRO(ICANON);
+  MACRO(IEXTEN);
+  MACRO(ISIG);
+  MACRO(NOFLSH);
+  MACRO(TOSTOP);
+
+  MACRO(TCSANOW);
+  MACRO(TCSADRAIN);
+  MACRO(TCSAFLUSH);
+
+  MACRO(TCIFLUSH);
+  MACRO(TCIOFLUSH);
+  MACRO(TCOFLUSH);
+
+  MACRO(TCIOFF);
+  MACRO(TCION);
+  MACRO(TCOOFF);
+  MACRO(TCOON);
+
+  TYPE(pid_t);
+
+  FUNCTION(cfgetispeed, speed_t (*f)(const struct termios*));
+  FUNCTION(cfgetospeed, speed_t (*f)(const struct termios*));
+  FUNCTION(cfsetispeed, int (*f)(struct termios*, speed_t));
+  FUNCTION(cfsetospeed, int (*f)(struct termios*, speed_t));
+  FUNCTION(tcdrain, int (*f)(int));
+  FUNCTION(tcflow, int (*f)(int, int));
+  FUNCTION(tcflush, int (*f)(int, int));
+  FUNCTION(tcgetattr, int (*f)(int, struct termios*));
+  FUNCTION(tcgetsid, pid_t (*f)(int));
+  FUNCTION(tcsendbreak, int (*f)(int, int));
+  FUNCTION(tcsetattr, int (*f)(int, int, const struct termios*));
+}
diff --git a/tests/headers/posix/tgmath_h.c b/tests/headers/posix/tgmath_h.c
new file mode 100644
index 0000000..c3a4311
--- /dev/null
+++ b/tests/headers/posix/tgmath_h.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <tgmath.h>
+
+#include "header_checks.h"
+
+#define TGMATH(f_) f_(f1); f_(d1); f_(ld1);
+#define TGMATHC(f_) f_(f1); f_(d1); f_(ld1); f_(fc1); f_(dc1); f_(ldc1);
+#define TGMATHCONLY(f_) f_(fc1); f_(dc1); f_(ldc1);
+#define TGMATH2(f_) f_(f1, f2); f_(d1, d2); f_(ld1, ld2);
+#define TGMATH2C(f_) f_(f1, f2); f_(d1, d2); f_(ld1, ld2); f_(fc1, fc2); f_(dc1, dc2); f_(ldc1, ldc2);
+#define TGMATH3(f_) f_(f1, f2, f3); f_(d1, d2, d3); f_(ld1, ld2, ld3);
+
+static void tgmath_h() {
+  float f1, f2, f3;
+  f1 = f2 = f3 = 0;
+  float complex fc1, fc2, fc3;
+  fc1 = fc2 = fc3 = 0;
+  double d1, d2, d3;
+  d1 = d2 = d3 = 0;
+  double complex dc1, dc2, dc3;
+  dc1 = dc2 = dc3 = 0;
+  long double ld1, ld2, ld3;
+  ld1 = ld2 = ld3 = 0;
+  long double complex ldc1, ldc2, ldc3;
+  ldc1 = ldc2 = ldc3 = 0;
+  int i = 0;
+  long l = 0;
+
+  TGMATHC(acos);
+  TGMATHC(asin);
+  TGMATHC(atan);
+  TGMATHC(acosh);
+  TGMATHC(asinh);
+  TGMATHC(atanh);
+  TGMATHC(cos);
+  TGMATHC(sin);
+  TGMATHC(tan);
+  TGMATHC(cosh);
+  TGMATHC(sinh);
+  TGMATHC(tanh);
+  TGMATHC(exp);
+  TGMATHC(log);
+  TGMATH2C(pow);
+  TGMATHC(sqrt);
+  TGMATHC(fabs);
+
+  TGMATH2(atan2);
+  TGMATH(cbrt);
+  TGMATH(ceil);
+  TGMATH2(copysign);
+  TGMATH(erf);
+  TGMATH(erfc);
+  TGMATH(exp2);
+  TGMATH(expm1);
+  TGMATH2(fdim);
+  TGMATH(floor);
+  TGMATH3(fma);
+  TGMATH2(fmax);
+  TGMATH2(fmin);
+  TGMATH2(fmod);
+  frexp(f1, &i); frexp(d1, &i); frexp(ld1, &i);
+  TGMATH2(hypot);
+  TGMATH(ilogb);
+  ldexp(f1, i); ldexp(d1, i); ldexp(ld1, i);
+  TGMATH(lgamma);
+  TGMATH(llrint);
+  TGMATH(llround);
+  TGMATH(log10);
+  TGMATH(log1p);
+  TGMATH(log2);
+  TGMATH(logb);
+  TGMATH(lrint);
+  TGMATH(lround);
+  TGMATH(nearbyint);
+  TGMATH2(nextafter);
+  TGMATH2(nexttoward);
+  TGMATH2(remainder);
+  remquo(f1, f2, &i); remquo(d1, d2, &i); remquo(ld1, ld2, &i);
+  TGMATH(rint);
+  TGMATH(round);
+  scalbln(f1, l); scalbln(d1, l); scalbln(ld1, l);
+  scalbn(f1, i); scalbn(d1, i); scalbn(ld1, i);
+  TGMATH(tgamma);
+  TGMATH(trunc);
+
+  TGMATHCONLY(carg);
+  TGMATHCONLY(cimag);
+  TGMATHCONLY(conj);
+  TGMATHCONLY(cproj);
+  TGMATHCONLY(creal);
+}
diff --git a/tests/headers/posix/time_h.c b/tests/headers/posix/time_h.c
new file mode 100644
index 0000000..d3e088a
--- /dev/null
+++ b/tests/headers/posix/time_h.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if !defined(DO_NOT_INCLUDE_TIME_H)
+#include <time.h>
+#endif
+
+#include "header_checks.h"
+
+static void time_h() {
+  TYPE(clock_t);
+  TYPE(size_t);
+  TYPE(time_t);
+
+  TYPE(clockid_t);
+  TYPE(timer_t);
+
+  TYPE(locale_t);
+
+  TYPE(pid_t);
+
+  TYPE(struct tm);
+  STRUCT_MEMBER(struct tm, int, tm_sec);
+  STRUCT_MEMBER(struct tm, int, tm_min);
+  STRUCT_MEMBER(struct tm, int, tm_hour);
+  STRUCT_MEMBER(struct tm, int, tm_mday);
+  STRUCT_MEMBER(struct tm, int, tm_mon);
+  STRUCT_MEMBER(struct tm, int, tm_year);
+  STRUCT_MEMBER(struct tm, int, tm_wday);
+  STRUCT_MEMBER(struct tm, int, tm_yday);
+  STRUCT_MEMBER(struct tm, int, tm_isdst);
+
+  TYPE(struct timespec);
+  STRUCT_MEMBER(struct timespec, time_t, tv_sec);
+  STRUCT_MEMBER(struct timespec, long, tv_nsec);
+
+  TYPE(struct itimerspec);
+  STRUCT_MEMBER(struct itimerspec, struct timespec, it_interval);
+  STRUCT_MEMBER(struct itimerspec, struct timespec, it_value);
+
+  MACRO(NULL);
+  MACRO(CLOCKS_PER_SEC);
+
+  MACRO(CLOCK_MONOTONIC);
+  MACRO(CLOCK_PROCESS_CPUTIME_ID);
+  MACRO(CLOCK_REALTIME);
+  MACRO(CLOCK_THREAD_CPUTIME_ID);
+
+  MACRO(TIMER_ABSTIME);
+
+  FUNCTION(asctime, char* (*f)(const struct tm*));
+  FUNCTION(asctime_r, char* (*f)(const struct tm*, char*));
+  FUNCTION(clock, clock_t (*f)(void));
+  FUNCTION(clock_getcpuclockid, int (*f)(pid_t, clockid_t*));
+  FUNCTION(clock_getres, int (*f)(clockid_t, struct timespec*));
+  FUNCTION(clock_gettime, int (*f)(clockid_t, struct timespec*));
+  FUNCTION(clock_nanosleep, int (*f)(clockid_t, int, const struct timespec*, struct timespec*));
+  FUNCTION(clock_settime, int (*f)(clockid_t, const struct timespec*));
+  FUNCTION(ctime, char* (*f)(const time_t*));
+  FUNCTION(ctime_r, char* (*f)(const time_t*, char*));
+  FUNCTION(difftime, double (*f)(time_t, time_t));
+#if !defined(__BIONIC__)
+  FUNCTION(getdate, struct tm* (*f)(const char*));
+#endif
+  FUNCTION(gmtime, struct tm* (*f)(const time_t*));
+  FUNCTION(gmtime_r, struct tm* (*f)(const time_t*, struct tm*));
+  FUNCTION(localtime, struct tm* (*f)(const time_t*));
+  FUNCTION(localtime_r, struct tm* (*f)(const time_t*, struct tm*));
+  FUNCTION(mktime, time_t (*f)(struct tm*));
+  FUNCTION(nanosleep, int (*f)(const struct timespec*, struct timespec*));
+  FUNCTION(strftime, size_t (*f)(char*, size_t, const char*, const struct tm*));
+  FUNCTION(strftime_l, size_t (*f)(char*, size_t, const char*, const struct tm*, locale_t));
+  FUNCTION(strptime, char* (*f)(const char*, const char*, struct tm*));
+  FUNCTION(time, time_t (*f)(time_t*));
+  FUNCTION(timer_create, int (*f)(clockid_t, struct sigevent*, timer_t*));
+  FUNCTION(timer_delete, int (*f)(timer_t));
+  FUNCTION(timer_getoverrun, int (*f)(timer_t));
+  FUNCTION(timer_gettime, int (*f)(timer_t, struct itimerspec*));
+  FUNCTION(timer_settime, int (*f)(timer_t, int, const struct itimerspec*, struct itimerspec*));
+  FUNCTION(tzset, void (*f)(void));
+
+  int i = daylight;
+  long l = timezone;
+  char** sp = tzname;
+}
diff --git a/tests/headers/posix/unistd_h.c b/tests/headers/posix/unistd_h.c
new file mode 100644
index 0000000..b713f53
--- /dev/null
+++ b/tests/headers/posix/unistd_h.c
@@ -0,0 +1,383 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <unistd.h>
+
+#include "header_checks.h"
+
+static void unistd_h() {
+  MACRO(_POSIX_VERSION);
+  MACRO(_POSIX2_VERSION);
+  MACRO(_XOPEN_VERSION);
+
+  MACRO(_POSIX_ADVISORY_INFO);
+  MACRO(_POSIX_ASYNCHRONOUS_IO);
+  MACRO(_POSIX_BARRIERS);
+  MACRO(_POSIX_CHOWN_RESTRICTED);
+  MACRO(_POSIX_CLOCK_SELECTION);
+  MACRO(_POSIX_CPUTIME);
+  MACRO(_POSIX_FSYNC);
+  MACRO(_POSIX_IPV6);
+  MACRO(_POSIX_JOB_CONTROL);
+  MACRO(_POSIX_MAPPED_FILES);
+  MACRO(_POSIX_MEMLOCK);
+  MACRO(_POSIX_MEMLOCK_RANGE);
+  MACRO(_POSIX_MEMORY_PROTECTION);
+  MACRO(_POSIX_MESSAGE_PASSING);
+  MACRO(_POSIX_MONOTONIC_CLOCK);
+  MACRO(_POSIX_NO_TRUNC);
+  MACRO(_POSIX_PRIORITIZED_IO);
+  MACRO(_POSIX_PRIORITY_SCHEDULING);
+  MACRO(_POSIX_RAW_SOCKETS);
+  MACRO(_POSIX_READER_WRITER_LOCKS);
+  MACRO(_POSIX_REALTIME_SIGNALS);
+  MACRO(_POSIX_REGEXP);
+  MACRO(_POSIX_SAVED_IDS);
+  MACRO(_POSIX_SEMAPHORES);
+  MACRO(_POSIX_SHARED_MEMORY_OBJECTS);
+  MACRO(_POSIX_SHELL);
+  MACRO(_POSIX_SPAWN);
+  MACRO(_POSIX_SPIN_LOCKS);
+  MACRO(_POSIX_SPORADIC_SERVER);
+  MACRO(_POSIX_SYNCHRONIZED_IO);
+  MACRO(_POSIX_THREAD_ATTR_STACKADDR);
+  MACRO(_POSIX_THREAD_ATTR_STACKSIZE);
+  MACRO(_POSIX_THREAD_CPUTIME);
+  MACRO(_POSIX_THREAD_PRIO_INHERIT);
+  MACRO(_POSIX_THREAD_PRIO_PROTECT);
+  MACRO(_POSIX_THREAD_PRIORITY_SCHEDULING);
+  MACRO(_POSIX_THREAD_PROCESS_SHARED);
+  MACRO(_POSIX_THREAD_ROBUST_PRIO_INHERIT);
+  MACRO(_POSIX_THREAD_ROBUST_PRIO_PROTECT);
+  MACRO(_POSIX_THREAD_SAFE_FUNCTIONS);
+  MACRO(_POSIX_THREAD_SPORADIC_SERVER);
+  MACRO(_POSIX_THREADS);
+  MACRO(_POSIX_TIMEOUTS);
+  MACRO(_POSIX_TIMERS);
+  MACRO(_POSIX_TYPED_MEMORY_OBJECTS);
+  MACRO(_POSIX2_C_BIND);
+  MACRO(_POSIX2_CHAR_TERM);
+  MACRO(_POSIX2_LOCALEDEF);
+  MACRO(_POSIX2_SW_DEV);
+#if 0 // No libc I can find actually has this.
+  MACRO(_POSIX2_UPE);
+#endif
+  MACRO(_XOPEN_CRYPT);
+  MACRO(_XOPEN_ENH_I18N);
+  MACRO(_XOPEN_REALTIME);
+  MACRO(_XOPEN_REALTIME_THREADS);
+  MACRO(_XOPEN_SHM);
+  MACRO(_XOPEN_UNIX);
+#if defined(_XOPEN_UUCP)
+#if _XOPEN_UUCP != -1 && _XOPEN_UUCP != 0 && _XOPEN_UUCP != 200809L
+#error _XOPEN_UUCP
+#endif
+#endif
+
+  MACRO(NULL);
+
+  MACRO(F_OK);
+  MACRO(R_OK);
+  MACRO(W_OK);
+  MACRO(X_OK);
+
+#if !defined(__BIONIC__) // No confstr on Android.
+  MACRO(_CS_PATH);
+  MACRO(_CS_POSIX_V7_ILP32_OFF32_CFLAGS);
+  MACRO(_CS_POSIX_V7_ILP32_OFF32_LDFLAGS);
+  MACRO(_CS_POSIX_V7_ILP32_OFF32_LIBS);
+  MACRO(_CS_POSIX_V7_ILP32_OFFBIG_CFLAGS);
+  MACRO(_CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS);
+  MACRO(_CS_POSIX_V7_ILP32_OFFBIG_LIBS);
+  MACRO(_CS_POSIX_V7_LP64_OFF64_CFLAGS);
+  MACRO(_CS_POSIX_V7_LP64_OFF64_LDFLAGS);
+  MACRO(_CS_POSIX_V7_LP64_OFF64_LIBS);
+  MACRO(_CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS);
+  MACRO(_CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS);
+  MACRO(_CS_POSIX_V7_LPBIG_OFFBIG_LIBS);
+  MACRO(_CS_POSIX_V7_WIDTH_RESTRICTED_ENVS);
+  MACRO(_CS_V7_ENV);
+#endif
+
+  MACRO(SEEK_CUR);
+  MACRO(SEEK_END);
+  MACRO(SEEK_SET);
+
+  MACRO(F_LOCK);
+  MACRO(F_TEST);
+  MACRO(F_TLOCK);
+  MACRO(F_ULOCK);
+
+  MACRO(_PC_2_SYMLINKS);
+  MACRO(_PC_ALLOC_SIZE_MIN);
+  MACRO(_PC_ASYNC_IO);
+  MACRO(_PC_CHOWN_RESTRICTED);
+  MACRO(_PC_FILESIZEBITS);
+  MACRO(_PC_LINK_MAX);
+  MACRO(_PC_MAX_CANON);
+  MACRO(_PC_MAX_INPUT);
+  MACRO(_PC_NAME_MAX);
+  MACRO(_PC_NO_TRUNC);
+  MACRO(_PC_PATH_MAX);
+  MACRO(_PC_PIPE_BUF);
+  MACRO(_PC_PRIO_IO);
+  MACRO(_PC_REC_INCR_XFER_SIZE);
+  MACRO(_PC_REC_MAX_XFER_SIZE);
+  MACRO(_PC_REC_MIN_XFER_SIZE);
+  MACRO(_PC_REC_XFER_ALIGN);
+  MACRO(_PC_SYMLINK_MAX);
+  MACRO(_PC_SYNC_IO);
+#if 0 // No libc I can find actually has this.
+  MACRO(_PC_TIMESTAMP_RESOLUTION);
+#endif
+  MACRO(_PC_VDISABLE);
+
+  MACRO(_SC_2_C_BIND);
+  MACRO(_SC_2_C_DEV);
+  MACRO(_SC_2_CHAR_TERM);
+  MACRO(_SC_2_FORT_DEV);
+  MACRO(_SC_2_FORT_RUN);
+  MACRO(_SC_2_LOCALEDEF);
+  MACRO(_SC_2_SW_DEV);
+  MACRO(_SC_2_UPE);
+  MACRO(_SC_2_VERSION);
+  MACRO(_SC_ADVISORY_INFO);
+  MACRO(_SC_AIO_LISTIO_MAX);
+  MACRO(_SC_AIO_MAX);
+  MACRO(_SC_AIO_PRIO_DELTA_MAX);
+  MACRO(_SC_ARG_MAX);
+  MACRO(_SC_ASYNCHRONOUS_IO);
+  MACRO(_SC_ATEXIT_MAX);
+  MACRO(_SC_BARRIERS);
+  MACRO(_SC_BC_BASE_MAX);
+  MACRO(_SC_BC_DIM_MAX);
+  MACRO(_SC_BC_SCALE_MAX);
+  MACRO(_SC_BC_STRING_MAX);
+  MACRO(_SC_CHILD_MAX);
+  MACRO(_SC_CLK_TCK);
+  MACRO(_SC_CLOCK_SELECTION);
+  MACRO(_SC_COLL_WEIGHTS_MAX);
+  MACRO(_SC_CPUTIME);
+  MACRO(_SC_DELAYTIMER_MAX);
+  MACRO(_SC_EXPR_NEST_MAX);
+  MACRO(_SC_FSYNC);
+  MACRO(_SC_GETGR_R_SIZE_MAX);
+  MACRO(_SC_GETPW_R_SIZE_MAX);
+  MACRO(_SC_HOST_NAME_MAX);
+  MACRO(_SC_IOV_MAX);
+  MACRO(_SC_IPV6);
+  MACRO(_SC_JOB_CONTROL);
+  MACRO(_SC_LINE_MAX);
+  MACRO(_SC_LOGIN_NAME_MAX);
+  MACRO(_SC_MAPPED_FILES);
+  MACRO(_SC_MEMLOCK);
+  MACRO(_SC_MEMLOCK_RANGE);
+  MACRO(_SC_MEMORY_PROTECTION);
+  MACRO(_SC_MESSAGE_PASSING);
+  MACRO(_SC_MONOTONIC_CLOCK);
+  MACRO(_SC_MQ_OPEN_MAX);
+  MACRO(_SC_MQ_PRIO_MAX);
+  MACRO(_SC_NGROUPS_MAX);
+  MACRO(_SC_OPEN_MAX);
+  MACRO(_SC_PAGE_SIZE);
+  MACRO(_SC_PAGESIZE);
+  MACRO(_SC_PRIORITIZED_IO);
+  MACRO(_SC_PRIORITY_SCHEDULING);
+  MACRO(_SC_RAW_SOCKETS);
+  MACRO(_SC_RE_DUP_MAX);
+  MACRO(_SC_READER_WRITER_LOCKS);
+  MACRO(_SC_REALTIME_SIGNALS);
+  MACRO(_SC_REGEXP);
+  MACRO(_SC_RTSIG_MAX);
+  MACRO(_SC_SAVED_IDS);
+  MACRO(_SC_SEM_NSEMS_MAX);
+  MACRO(_SC_SEM_VALUE_MAX);
+  MACRO(_SC_SEMAPHORES);
+  MACRO(_SC_SHARED_MEMORY_OBJECTS);
+  MACRO(_SC_SHELL);
+  MACRO(_SC_SIGQUEUE_MAX);
+  MACRO(_SC_SPAWN);
+  MACRO(_SC_SPIN_LOCKS);
+  MACRO(_SC_SPORADIC_SERVER);
+  MACRO(_SC_SS_REPL_MAX);
+  MACRO(_SC_STREAM_MAX);
+  MACRO(_SC_SYMLOOP_MAX);
+  MACRO(_SC_SYNCHRONIZED_IO);
+  MACRO(_SC_THREAD_ATTR_STACKADDR);
+  MACRO(_SC_THREAD_ATTR_STACKSIZE);
+  MACRO(_SC_THREAD_CPUTIME);
+  MACRO(_SC_THREAD_DESTRUCTOR_ITERATIONS);
+  MACRO(_SC_THREAD_KEYS_MAX);
+  MACRO(_SC_THREAD_PRIO_INHERIT);
+  MACRO(_SC_THREAD_PRIO_PROTECT);
+  MACRO(_SC_THREAD_PRIORITY_SCHEDULING);
+  MACRO(_SC_THREAD_PROCESS_SHARED);
+  MACRO(_SC_THREAD_ROBUST_PRIO_INHERIT);
+  MACRO(_SC_THREAD_ROBUST_PRIO_PROTECT);
+  MACRO(_SC_THREAD_SAFE_FUNCTIONS);
+  MACRO(_SC_THREAD_SPORADIC_SERVER);
+  MACRO(_SC_THREAD_STACK_MIN);
+  MACRO(_SC_THREAD_THREADS_MAX);
+  MACRO(_SC_THREADS);
+  MACRO(_SC_TIMEOUTS);
+  MACRO(_SC_TIMER_MAX);
+  MACRO(_SC_TIMERS);
+  MACRO(_SC_TRACE);
+  MACRO(_SC_TRACE_EVENT_FILTER);
+  MACRO(_SC_TRACE_EVENT_NAME_MAX);
+  MACRO(_SC_TRACE_INHERIT);
+  MACRO(_SC_TRACE_LOG);
+  MACRO(_SC_TRACE_NAME_MAX);
+  MACRO(_SC_TRACE_SYS_MAX);
+  MACRO(_SC_TRACE_USER_EVENT_MAX);
+  MACRO(_SC_TYPED_MEMORY_OBJECTS);
+  MACRO(_SC_TZNAME_MAX);
+  MACRO(_SC_V7_ILP32_OFF32);
+  MACRO(_SC_VERSION);
+  MACRO(_SC_XOPEN_CRYPT);
+  MACRO(_SC_XOPEN_ENH_I18N);
+  MACRO(_SC_XOPEN_REALTIME);
+  MACRO(_SC_XOPEN_REALTIME_THREADS);
+  MACRO(_SC_XOPEN_SHM);
+  MACRO(_SC_XOPEN_STREAMS);
+  MACRO(_SC_XOPEN_UNIX);
+#if 0 // No libc I can find actually has this.
+  MACRO(_SC_XOPEN_UUCP);
+#endif
+  MACRO(_SC_XOPEN_VERSION);
+
+  MACRO_VALUE(STDERR_FILENO, 2);
+  MACRO_VALUE(STDIN_FILENO, 0);
+  MACRO_VALUE(STDOUT_FILENO, 1);
+
+  MACRO(_POSIX_VDISABLE);
+
+  TYPE(size_t);
+  TYPE(ssize_t);
+  TYPE(uid_t);
+  TYPE(gid_t);
+  TYPE(off_t);
+  TYPE(pid_t);
+  TYPE(intptr_t);
+
+  FUNCTION(access, int (*f)(const char*, int));
+  FUNCTION(alarm, unsigned (*f)(unsigned));
+  FUNCTION(chdir, int (*f)(const char*));
+  FUNCTION(chown, int (*f)(const char*, uid_t, gid_t));
+  FUNCTION(close, int (*f)(int));
+#if !defined(__BIONIC__)
+  FUNCTION(confstr, size_t (*f)(int, char*, size_t));
+  FUNCTION(crypt, char* (*f)(const char*, const char*));
+#endif
+  FUNCTION(dup, int (*f)(int));
+  FUNCTION(dup2, int (*f)(int, int));
+  FUNCTION(_exit, void (*f)(int));
+#if !defined(__BIONIC__)
+  FUNCTION(encrypt, void (*f)(char[64], int));
+#endif
+  FUNCTION(execl, int (*f)(const char*, const char*, ...));
+  FUNCTION(execle, int (*f)(const char*, const char*, ...));
+  FUNCTION(execlp, int (*f)(const char*, const char*, ...));
+  FUNCTION(execv, int (*f)(const char*, char* const[]));
+  FUNCTION(execve, int (*f)(const char*, char* const[], char* const[]));
+  FUNCTION(execvp, int (*f)(const char*, char* const[]));
+  FUNCTION(faccessat, int (*f)(int, const char*, int, int));
+  FUNCTION(fchdir, int (*f)(int));
+  FUNCTION(fchown, int (*f)(int, uid_t, gid_t));
+  FUNCTION(fchownat, int (*f)(int, const char*, uid_t, gid_t, int));
+  FUNCTION(fdatasync, int (*f)(int));
+  FUNCTION(fexecve, int (*f)(int, char* const[], char* const[]));
+  FUNCTION(fork, pid_t (*f)(void));
+  FUNCTION(fpathconf, long (*f)(int, int));
+  FUNCTION(fsync, int (*f)(int));
+  FUNCTION(ftruncate, int (*f)(int, off_t));
+  FUNCTION(getcwd, char* (*f)(char*, size_t));
+  FUNCTION(getegid, gid_t (*f)(void));
+  FUNCTION(geteuid, uid_t (*f)(void));
+  FUNCTION(getgid, gid_t (*f)(void));
+  FUNCTION(getgroups, int (*f)(int, gid_t[]));
+#if !defined(__BIONIC__)
+  FUNCTION(gethostid, long (*f)(void));
+#endif
+  FUNCTION(gethostname, int (*f)(char*, size_t));
+  FUNCTION(getlogin, char* (*f)(void));
+  FUNCTION(getlogin_r, int (*f)(char*, size_t));
+  FUNCTION(getopt, int (*f)(int, char* const[], const char*));
+  FUNCTION(getpgid, pid_t (*f)(pid_t));
+  FUNCTION(getpgrp, pid_t (*f)(void));
+  FUNCTION(getpid, pid_t (*f)(void));
+  FUNCTION(getppid, pid_t (*f)(void));
+  FUNCTION(getsid, pid_t (*f)(pid_t));
+  FUNCTION(getuid, uid_t (*f)(void));
+  FUNCTION(isatty, int (*f)(int));
+  FUNCTION(lchown, int (*f)(const char*, uid_t, gid_t));
+  FUNCTION(link, int (*f)(const char*, const char*));
+  FUNCTION(linkat, int (*f)(int, const char*, int, const char*, int));
+  FUNCTION(lockf, int (*f)(int, int, off_t));
+  FUNCTION(lseek, off_t (*f)(int, off_t, int));
+  FUNCTION(nice, int (*f)(int));
+  FUNCTION(pathconf, long (*f)(const char*, int));
+  FUNCTION(pause, int (*f)(void));
+  FUNCTION(pipe, int (*f)(int[2]));
+  FUNCTION(pread, ssize_t (*f)(int, void*, size_t, off_t));
+  FUNCTION(pwrite, ssize_t (*f)(int, const void*, size_t, off_t));
+  FUNCTION(read, ssize_t (*f)(int, void*, size_t));
+  FUNCTION(readlink, ssize_t (*f)(const char*, char*, size_t));
+  FUNCTION(readlinkat, ssize_t (*f)(int, const char*, char*, size_t));
+  FUNCTION(rmdir, int (*f)(const char*));
+  FUNCTION(setegid, int (*f)(gid_t));
+  FUNCTION(seteuid, int (*f)(uid_t));
+  FUNCTION(setgid, int (*f)(gid_t));
+  FUNCTION(setpgid, int (*f)(pid_t, pid_t));
+  FUNCTION(setpgrp, pid_t (*f)(void));
+  FUNCTION(setregid, int (*f)(gid_t, gid_t));
+  FUNCTION(setreuid, int (*f)(uid_t, uid_t));
+  FUNCTION(setsid, pid_t (*f)(void));
+  FUNCTION(setuid, int (*f)(uid_t));
+  FUNCTION(sleep, unsigned (*f)(unsigned));
+  FUNCTION(swab, void (*f)(const void*, void*, ssize_t));
+  FUNCTION(symlink, int (*f)(const char*, const char*));
+  FUNCTION(symlinkat, int (*f)(const char*, int, const char*));
+  FUNCTION(sync, void (*f)(void));
+  FUNCTION(sysconf, long (*f)(int));
+  FUNCTION(tcgetpgrp, pid_t (*f)(int));
+  FUNCTION(tcsetpgrp, int (*f)(int, pid_t));
+  FUNCTION(truncate, int (*f)(const char*, off_t));
+  FUNCTION(ttyname, char* (*f)(int));
+  FUNCTION(ttyname_r, int (*f)(int, char*, size_t));
+  FUNCTION(unlink, int (*f)(const char*));
+  FUNCTION(unlinkat, int (*f)(int, const char*, int));
+  FUNCTION(write, ssize_t (*f)(int, const void*, size_t));
+
+  char* cp;
+  cp = optarg;
+  int i;
+  i = opterr;
+  i = optind;
+  i = optopt;
+}
diff --git a/tests/headers/posix/utime_h.c b/tests/headers/posix/utime_h.c
new file mode 100644
index 0000000..c5b304b
--- /dev/null
+++ b/tests/headers/posix/utime_h.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <utime.h>
+
+#include "header_checks.h"
+
+static void utime_h() {
+  TYPE(struct utimbuf);
+  STRUCT_MEMBER(struct utimbuf, time_t, actime);
+  STRUCT_MEMBER(struct utimbuf, time_t, modtime);
+
+  TYPE(time_t);
+
+  FUNCTION(utime, int (*f)(const char*, const struct utimbuf*));
+}
diff --git a/tests/headers/posix/wchar_h.c b/tests/headers/posix/wchar_h.c
new file mode 100644
index 0000000..48b3b92
--- /dev/null
+++ b/tests/headers/posix/wchar_h.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <wchar.h>
+
+#include "header_checks.h"
+
+static void wchar_h() {
+  TYPE(FILE*);
+  TYPE(locale_t);
+  TYPE(mbstate_t);
+  TYPE(size_t);
+  TYPE(va_list);
+  TYPE(wchar_t);
+  TYPE(wctype_t);
+  TYPE(wint_t);
+
+  MACRO(WCHAR_MAX);
+  MACRO(WCHAR_MIN);
+  MACRO(WEOF);
+  MACRO(NULL);
+
+  FUNCTION(btowc, wint_t (*f)(int));
+  FUNCTION(fgetwc, wint_t (*f)(FILE*));
+  FUNCTION(fgetws, wchar_t* (*f)(wchar_t*, int, FILE*));
+  FUNCTION(fputwc, wint_t (*f)(wchar_t, FILE*));
+  FUNCTION(fputws, int (*f)(const wchar_t*, FILE*));
+  FUNCTION(fwide, int (*f)(FILE*, int));
+  FUNCTION(fwprintf, int (*f)(FILE*, const wchar_t*, ...));
+  FUNCTION(fwscanf, int (*f)(FILE*, const wchar_t*, ...));
+  FUNCTION(getwc, wint_t (*f)(FILE*));
+  FUNCTION(getwchar, wint_t (*f)(void));
+  FUNCTION(mbrlen, size_t (*f)(const char*, size_t, mbstate_t*));
+  FUNCTION(mbrtowc, size_t (*f)(wchar_t*, const char*, size_t, mbstate_t*));
+  FUNCTION(mbsinit, int (*f)(const mbstate_t*));
+  FUNCTION(mbsnrtowcs, size_t (*f)(wchar_t*, const char**, size_t, size_t, mbstate_t*));
+  FUNCTION(mbsrtowcs, size_t (*f)(wchar_t*, const char**, size_t, mbstate_t*));
+  FUNCTION(open_wmemstream, FILE* (*f)(wchar_t**, size_t*));
+  FUNCTION(putwc, wint_t (*f)(wchar_t, FILE*));
+  FUNCTION(putwchar, wint_t (*f)(wchar_t));
+  FUNCTION(swprintf, int (*f)(wchar_t*, size_t, const wchar_t*, ...));
+  FUNCTION(swscanf, int (*f)(const wchar_t*, const wchar_t*, ...));
+  FUNCTION(ungetwc, wint_t (*f)(wint_t, FILE*));
+  FUNCTION(vfwprintf, int (*f)(FILE*, const wchar_t*, va_list));
+  FUNCTION(vfwscanf, int (*f)(FILE*, const wchar_t*, va_list));
+  FUNCTION(vswprintf, int (*f)(wchar_t*, size_t, const wchar_t*, va_list));
+  FUNCTION(vswscanf, int (*f)(const wchar_t*, const wchar_t*, va_list));
+  FUNCTION(vwprintf, int (*f)(const wchar_t*, va_list));
+  FUNCTION(vwscanf, int (*f)(const wchar_t*, va_list));
+  FUNCTION(wcpcpy, wchar_t* (*f)(wchar_t*, const wchar_t*));
+  FUNCTION(wcpncpy, wchar_t* (*f)(wchar_t*, const wchar_t*, size_t));
+  FUNCTION(wcrtomb, size_t (*f)(char*, wchar_t, mbstate_t*));
+  FUNCTION(wcscasecmp, int (*f)(const wchar_t*, const wchar_t*));
+  FUNCTION(wcscasecmp_l, int (*f)(const wchar_t*, const wchar_t*, locale_t));
+  FUNCTION(wcscat, wchar_t* (*f)(wchar_t*, const wchar_t*));
+  FUNCTION(wcschr, wchar_t* (*f)(const wchar_t*, wchar_t));
+  FUNCTION(wcscmp, int (*f)(const wchar_t*, const wchar_t*));
+  FUNCTION(wcscoll, int (*f)(const wchar_t*, const wchar_t*));
+  FUNCTION(wcscoll_l, int (*f)(const wchar_t*, const wchar_t*, locale_t));
+  FUNCTION(wcscpy, wchar_t* (*f)(wchar_t*, const wchar_t*));
+  FUNCTION(wcscspn, size_t (*f)(const wchar_t*, const wchar_t*));
+  FUNCTION(wcsdup, wchar_t* (*f)(const wchar_t*));
+  FUNCTION(wcsftime, size_t (*f)(wchar_t*, size_t, const wchar_t*, const struct tm*));
+  FUNCTION(wcslen, size_t (*f)(const wchar_t*));
+  FUNCTION(wcsncasecmp, int (*f)(const wchar_t*, const wchar_t*, size_t));
+  FUNCTION(wcsncasecmp_l, int (*f)(const wchar_t*, const wchar_t*, size_t, locale_t));
+  FUNCTION(wcsncat, wchar_t* (*f)(wchar_t*, const wchar_t*, size_t));
+  FUNCTION(wcsncmp, int (*f)(const wchar_t*, const wchar_t*, size_t));
+  FUNCTION(wcsncpy, wchar_t* (*f)(wchar_t*, const wchar_t*, size_t));
+  FUNCTION(wcsnlen, size_t (*f)(const wchar_t*, size_t));
+  FUNCTION(wcsnrtombs, size_t (*f)(char*, const wchar_t**, size_t, size_t, mbstate_t*));
+  FUNCTION(wcspbrk, wchar_t* (*f)(const wchar_t*, const wchar_t*));
+  FUNCTION(wcsrchr, wchar_t* (*f)(const wchar_t*, wchar_t));
+  FUNCTION(wcsrtombs, size_t (*f)(char*, const wchar_t**, size_t, mbstate_t*));
+  FUNCTION(wcsspn, size_t (*f)(const wchar_t*, const wchar_t*));
+  FUNCTION(wcsstr, wchar_t* (*f)(const wchar_t*, const wchar_t*));
+  FUNCTION(wcstod, double (*f)(const wchar_t*, wchar_t**));
+  FUNCTION(wcstof, float (*f)(const wchar_t*, wchar_t**));
+  FUNCTION(wcstok, wchar_t* (*f)(wchar_t*, const wchar_t*, wchar_t**));
+  FUNCTION(wcstol, long (*f)(const wchar_t*, wchar_t**, int));
+  FUNCTION(wcstold, long double (*f)(const wchar_t*, wchar_t**));
+  FUNCTION(wcstoll, long long (*f)(const wchar_t*, wchar_t**, int));
+  FUNCTION(wcstoul, unsigned long (*f)(const wchar_t*, wchar_t**, int));
+  FUNCTION(wcstoull, unsigned long long (*f)(const wchar_t*, wchar_t**, int));
+  FUNCTION(wcswidth, int (*f)(const wchar_t*, size_t));
+  FUNCTION(wcsxfrm, size_t (*f)(wchar_t*, const wchar_t*, size_t));
+  FUNCTION(wcsxfrm_l, size_t (*f)(wchar_t*, const wchar_t*, size_t, locale_t));
+  FUNCTION(wctob, int (*f)(wint_t));
+  FUNCTION(wcwidth, int (*f)(wchar_t));
+  FUNCTION(wmemchr, wchar_t* (*f)(const wchar_t*, wchar_t, size_t));
+  FUNCTION(wmemcmp, int (*f)(const wchar_t*, const wchar_t*, size_t));
+  FUNCTION(wmemcpy, wchar_t* (*f)(wchar_t*, const wchar_t*, size_t));
+  FUNCTION(wmemmove, wchar_t* (*f)(wchar_t*, const wchar_t*, size_t));
+  FUNCTION(wmemset, wchar_t* (*f)(wchar_t*, wchar_t, size_t));
+  FUNCTION(wprintf, int (*f)(const wchar_t*, ...));
+  FUNCTION(wscanf, int (*f)(const wchar_t*, ...));
+}
diff --git a/tests/headers/posix/wctype_h.c b/tests/headers/posix/wctype_h.c
new file mode 100644
index 0000000..c5839d5
--- /dev/null
+++ b/tests/headers/posix/wctype_h.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <wctype.h>
+
+#include "header_checks.h"
+
+static void wctype_h() {
+  TYPE(wint_t);
+  TYPE(wctrans_t);
+  TYPE(wctype_t);
+  TYPE(locale_t);
+
+  MACRO(WEOF);
+
+  FUNCTION(iswalnum, int (*f)(wint_t));
+  FUNCTION(iswalnum_l, int (*f)(wint_t, locale_t));
+  FUNCTION(iswalpha, int (*f)(wint_t));
+  FUNCTION(iswalpha_l, int (*f)(wint_t, locale_t));
+  FUNCTION(iswblank, int (*f)(wint_t));
+  FUNCTION(iswblank_l, int (*f)(wint_t, locale_t));
+  FUNCTION(iswcntrl, int (*f)(wint_t));
+  FUNCTION(iswcntrl_l, int (*f)(wint_t, locale_t));
+  FUNCTION(iswctype, int (*f)(wint_t, wctype_t));
+  FUNCTION(iswctype_l, int (*f)(wint_t, wctype_t, locale_t));
+  FUNCTION(iswdigit, int (*f)(wint_t));
+  FUNCTION(iswdigit_l, int (*f)(wint_t, locale_t));
+  FUNCTION(iswgraph, int (*f)(wint_t));
+  FUNCTION(iswgraph_l, int (*f)(wint_t, locale_t));
+  FUNCTION(iswlower, int (*f)(wint_t));
+  FUNCTION(iswlower_l, int (*f)(wint_t, locale_t));
+  FUNCTION(iswprint, int (*f)(wint_t));
+  FUNCTION(iswprint_l, int (*f)(wint_t, locale_t));
+  FUNCTION(iswpunct, int (*f)(wint_t));
+  FUNCTION(iswpunct_l, int (*f)(wint_t, locale_t));
+  FUNCTION(iswspace, int (*f)(wint_t));
+  FUNCTION(iswspace_l, int (*f)(wint_t, locale_t));
+  FUNCTION(iswupper, int (*f)(wint_t));
+  FUNCTION(iswupper_l, int (*f)(wint_t, locale_t));
+  FUNCTION(iswxdigit, int (*f)(wint_t));
+  FUNCTION(iswxdigit_l, int (*f)(wint_t, locale_t));
+  FUNCTION(towctrans, wint_t (*f)(wint_t, wctrans_t));
+  FUNCTION(towctrans_l, wint_t (*f)(wint_t, wctrans_t, locale_t));
+  FUNCTION(towlower, wint_t (*f)(wint_t));
+  FUNCTION(towlower_l, wint_t (*f)(wint_t, locale_t));
+  FUNCTION(towupper, wint_t (*f)(wint_t));
+  FUNCTION(towupper_l, wint_t (*f)(wint_t, locale_t));
+  FUNCTION(wctrans, wctrans_t (*f)(const char*));
+  FUNCTION(wctrans_l, wctrans_t (*f)(const char*, locale_t));
+  FUNCTION(wctype, wctype_t (*f)(const char*));
+  FUNCTION(wctype_l, wctype_t (*f)(const char*, locale_t));
+}
diff --git a/tests/netinet_in_test.cpp b/tests/netinet_in_test.cpp
index c0d3bc8..2606082 100644
--- a/tests/netinet_in_test.cpp
+++ b/tests/netinet_in_test.cpp
@@ -76,3 +76,11 @@
   UNUSED(le64);
 #endif
 }
+
+TEST(netinet_in, ip_mreq_source_fields) {
+  // https://issuetracker.google.com/36987220
+  ip_mreq_source mreq;
+  mreq.imr_interface.s_addr = htonl(INADDR_ANY);
+  mreq.imr_multiaddr.s_addr = htonl(INADDR_ANY);
+  mreq.imr_sourceaddr.s_addr = htonl(INADDR_ANY);
+}
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index f0e0ab6..d0d9130 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -1016,6 +1016,95 @@
   CheckScanf(swscanf, L"+,-/.", L"%[+--/]", 1, "+,-/");
 }
 
+// https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=202240
+TEST(STDIO_TEST, scanf_wscanf_EOF) {
+  EXPECT_EQ(0, sscanf("b", "ab"));
+  EXPECT_EQ(EOF, sscanf("", "a"));
+  EXPECT_EQ(0, swscanf(L"b", L"ab"));
+  EXPECT_EQ(EOF, swscanf(L"", L"a"));
+}
+
+TEST(STDIO_TEST, scanf_invalid_UTF8) {
+#if 0 // TODO: more tests invented during code review; no regressions, so fix later.
+  char buf[BUFSIZ];
+  wchar_t wbuf[BUFSIZ];
+
+  memset(buf, 0, sizeof(buf));
+  memset(wbuf, 0, sizeof(wbuf));
+  EXPECT_EQ(0, sscanf("\xc0" " foo", "%ls %s", wbuf, buf));
+#endif
+}
+
+TEST(STDIO_TEST, scanf_no_match_no_termination) {
+  char buf[4] = "x";
+  EXPECT_EQ(0, sscanf("d", "%[abc]", buf));
+  EXPECT_EQ('x', buf[0]);
+  EXPECT_EQ(0, swscanf(L"d", L"%[abc]", buf));
+  EXPECT_EQ('x', buf[0]);
+
+  wchar_t wbuf[4] = L"x";
+  EXPECT_EQ(0, swscanf(L"d", L"%l[abc]", wbuf));
+  EXPECT_EQ(L'x', wbuf[0]);
+
+  EXPECT_EQ(EOF, sscanf("", "%s", buf));
+  EXPECT_EQ('x', buf[0]);
+
+  EXPECT_EQ(EOF, swscanf(L"", L"%ls", wbuf));
+  EXPECT_EQ(L'x', wbuf[0]);
+}
+
+TEST(STDIO_TEST, scanf_wscanf_wide_character_class) {
+#if 0 // TODO: more tests invented during code review; no regressions, so fix later.
+  wchar_t buf[BUFSIZ];
+
+  // A wide character shouldn't match an ASCII-only class for scanf or wscanf.
+  memset(buf, 0, sizeof(buf));
+  EXPECT_EQ(1, sscanf("xĀyz", "%l[xy]", buf));
+  EXPECT_EQ(L"x"s, std::wstring(buf));
+  memset(buf, 0, sizeof(buf));
+  EXPECT_EQ(1, swscanf(L"xĀyz", L"%l[xy]", buf));
+  EXPECT_EQ(L"x"s, std::wstring(buf));
+
+  // Even if scanf has wide characters in a class, they won't match...
+  // TODO: is that a bug?
+  memset(buf, 0, sizeof(buf));
+  EXPECT_EQ(1, sscanf("xĀyz", "%l[xĀy]", buf));
+  EXPECT_EQ(L"x"s, std::wstring(buf));
+  // ...unless you use wscanf.
+  memset(buf, 0, sizeof(buf));
+  EXPECT_EQ(1, swscanf(L"xĀyz", L"%l[xĀy]", buf));
+  EXPECT_EQ(L"xĀy"s, std::wstring(buf));
+
+  // Negation only covers ASCII for scanf...
+  memset(buf, 0, sizeof(buf));
+  EXPECT_EQ(1, sscanf("xĀyz", "%l[^ab]", buf));
+  EXPECT_EQ(L"x"s, std::wstring(buf));
+  // ...but covers wide characters for wscanf.
+  memset(buf, 0, sizeof(buf));
+  EXPECT_EQ(1, swscanf(L"xĀyz", L"%l[^ab]", buf));
+  EXPECT_EQ(L"xĀyz"s, std::wstring(buf));
+
+  // We already determined that non-ASCII characters are ignored in scanf classes.
+  memset(buf, 0, sizeof(buf));
+  EXPECT_EQ(1, sscanf("x"
+                      "\xc4\x80" // Matches a byte from each wide char in the class.
+                      "\xc6\x82" // Neither byte is in the class.
+                      "yz",
+                      "%l[xy" "\xc5\x80" "\xc4\x81" "]", buf));
+  EXPECT_EQ(L"x", std::wstring(buf));
+  // bionic and glibc both behave badly for wscanf, so let's call it right for now...
+  memset(buf, 0, sizeof(buf));
+  EXPECT_EQ(1, swscanf(L"x"
+                       L"\xc4\x80"
+                       L"\xc6\x82"
+                       L"yz",
+                       L"%l[xy" L"\xc5\x80" L"\xc4\x81" L"]", buf));
+  // Note that this isn't L"xĀ" --- although the *bytes* matched, they're
+  // not put back together as a wide character.
+  EXPECT_EQ(L"x" L"\xc4" L"\x80", std::wstring(buf));
+#endif
+}
+
 TEST(STDIO_TEST, cantwrite_EBADF) {
   // If we open a file read-only...
   FILE* fp = fopen("/proc/version", "r");
@@ -1630,17 +1719,13 @@
   ASSERT_TRUE(fd != -1);
 
   // This fd doesn't have O_CLOEXEC...
-  int flags = fcntl(fd, F_GETFD);
-  ASSERT_TRUE(flags != -1);
-  ASSERT_EQ(0, flags & FD_CLOEXEC);
+  AssertCloseOnExec(fd, false);
 
   FILE* fp = fdopen(fd, "re");
   ASSERT_TRUE(fp != NULL);
 
   // ...but the new one does.
-  flags = fcntl(fileno(fp), F_GETFD);
-  ASSERT_TRUE(flags != -1);
-  ASSERT_EQ(FD_CLOEXEC, flags & FD_CLOEXEC);
+  AssertCloseOnExec(fileno(fp), true);
 
   fclose(fp);
   close(fd);
@@ -1651,16 +1736,12 @@
   ASSERT_TRUE(fp != NULL);
 
   // This FILE* doesn't have O_CLOEXEC...
-  int flags = fcntl(fileno(fp), F_GETFD);
-  ASSERT_TRUE(flags != -1);
-  ASSERT_EQ(0, flags & FD_CLOEXEC);
+  AssertCloseOnExec(fileno(fp), false);
 
   fp = freopen("/proc/version", "re", fp);
 
   // ...but the new one does.
-  flags = fcntl(fileno(fp), F_GETFD);
-  ASSERT_TRUE(flags != -1);
-  ASSERT_EQ(FD_CLOEXEC, flags & FD_CLOEXEC);
+  AssertCloseOnExec(fileno(fp), true);
 
   fclose(fp);
 }
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index ed5767c..1a3fc03 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -325,16 +325,12 @@
 
 TEST(stdlib, mkostemp64) {
   TemporaryFile tf([](char* path) { return mkostemp64(path, O_CLOEXEC); });
-  int flags = fcntl(tf.fd, F_GETFD);
-  ASSERT_TRUE(flags != -1);
-  ASSERT_EQ(FD_CLOEXEC, flags & FD_CLOEXEC);
+  AssertCloseOnExec(tf.fd, true);
 }
 
 TEST(stdlib, mkostemp) {
   TemporaryFile tf([](char* path) { return mkostemp(path, O_CLOEXEC); });
-  int flags = fcntl(tf.fd, F_GETFD);
-  ASSERT_TRUE(flags != -1);
-  ASSERT_EQ(FD_CLOEXEC, flags & FD_CLOEXEC);
+  AssertCloseOnExec(tf.fd, true);
 }
 
 TEST(stdlib, mkstemp64) {
diff --git a/tests/sys_epoll_test.cpp b/tests/sys_epoll_test.cpp
index f6be4af..d1b411a 100644
--- a/tests/sys_epoll_test.cpp
+++ b/tests/sys_epoll_test.cpp
@@ -22,6 +22,8 @@
 #include <sys/epoll.h>
 #include <unistd.h>
 
+#include "utils.h"
+
 TEST(sys_epoll, smoke) {
   int epoll_fd = epoll_create(1);
   ASSERT_NE(-1, epoll_fd) << strerror(errno);
@@ -72,3 +74,18 @@
   close(fds[0]);
   close(fds[1]);
 }
+
+TEST(sys_epoll, epoll_create1) {
+  int fd;
+  fd = epoll_create(1);
+  AssertCloseOnExec(fd, false);
+  close(fd);
+
+  fd = epoll_create1(0);
+  AssertCloseOnExec(fd, false);
+  close(fd);
+
+  fd = epoll_create1(EPOLL_CLOEXEC);
+  AssertCloseOnExec(fd, true);
+  close(fd);
+}
diff --git a/tests/sys_socket_test.cpp b/tests/sys_socket_test.cpp
index 8f5afac..506e01f 100644
--- a/tests/sys_socket_test.cpp
+++ b/tests/sys_socket_test.cpp
@@ -22,6 +22,8 @@
 #include <sys/un.h>
 #include <fcntl.h>
 
+#include "utils.h"
+
 struct ConnectData {
   bool (*callback_fn)(int);
   const char* sock_path;
@@ -106,8 +108,8 @@
   int fd_acc = accept4(fd, reinterpret_cast<struct sockaddr*>(addr), &len, SOCK_CLOEXEC);
   ASSERT_NE(fd_acc, -1) << strerror(errno);
 
-  // Check that the flag was set properly.
-  ASSERT_EQ(FD_CLOEXEC, fcntl(fd_acc, F_GETFD) & FD_CLOEXEC);
+  // Check that SOCK_CLOEXEC was set properly.
+  AssertCloseOnExec(fd_acc, true);
 
   close(fd_acc);
 }
diff --git a/tests/termios_test.cpp b/tests/termios_test.cpp
new file mode 100644
index 0000000..6290771
--- /dev/null
+++ b/tests/termios_test.cpp
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <termios.h>
+
+#include <errno.h>
+
+#include <gtest/gtest.h>
+
+// TODO:
+// tcdrain
+// tcflow
+// tcflush
+// tcgetattr
+// tcgetsid
+// tcsendbreak
+// tcsetattr
+
+TEST(termios, cfgetispeed_cfsetispeed) {
+  termios t = {};
+  ASSERT_EQ(0, cfsetispeed(&t, B1200));
+  ASSERT_EQ(static_cast<speed_t>(B1200), cfgetispeed(&t));
+}
+
+TEST(termios, cfsetispeed_EINVAL) {
+  termios t = {};
+  errno = 0;
+  ASSERT_EQ(-1, cfsetispeed(&t, 1200));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(termios, cfgetospeed_cfsetospeed) {
+  termios t = {};
+  ASSERT_EQ(0, cfsetospeed(&t, B1200));
+  ASSERT_EQ(static_cast<speed_t>(B1200), cfgetospeed(&t));
+}
+
+TEST(termios, cfsetospeed_EINVAL) {
+  termios t = {};
+  errno = 0;
+  ASSERT_EQ(-1, cfsetospeed(&t, 1200));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(termios, cfsetspeed) {
+  termios t = {};
+  ASSERT_EQ(0, cfsetspeed(&t, B1200));
+  ASSERT_EQ(static_cast<speed_t>(B1200), cfgetispeed(&t));
+  ASSERT_EQ(static_cast<speed_t>(B1200), cfgetospeed(&t));
+}
+
+TEST(termios, cfsetspeed_EINVAL) {
+  termios t = {};
+  errno = 0;
+  // glibc seems to allow 1200 as well as B1200 here, presumably for
+  // BSD compatibility (where Bxxx == xxx, unlike Linux).
+  ASSERT_EQ(-1, cfsetspeed(&t, 123));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(termios, cfmakeraw) {
+  termios t;
+  memset(&t, 0xff, sizeof(t));
+  cfmakeraw(&t);
+
+  EXPECT_EQ(0U, (t.c_iflag & (IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON)));
+  EXPECT_EQ(0U, (t.c_oflag & OPOST));
+  EXPECT_EQ(0U, (t.c_lflag & (ECHO|ECHONL|ICANON|ISIG|IEXTEN)));
+  EXPECT_EQ(0U, (t.c_cflag & PARENB));
+  EXPECT_EQ(CS8, static_cast<int>(t.c_cflag & CSIZE));
+  EXPECT_EQ(1, t.c_cc[VMIN]);
+  EXPECT_EQ(0, t.c_cc[VTIME]);
+}
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 022da4d..912ea0c 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -1043,6 +1043,17 @@
   ASSERT_EQ(EBADF, errno);
 }
 
+TEST(UNISTD_TEST, dup3) {
+  int fd = open("/proc/version", O_RDONLY);
+  ASSERT_EQ(666, dup3(fd, 666, 0));
+  AssertCloseOnExec(666, false);
+  close(666);
+  ASSERT_EQ(667, dup3(fd, 667, O_CLOEXEC));
+  AssertCloseOnExec(667, true);
+  close(667);
+  close(fd);
+}
+
 TEST(UNISTD_TEST, lockf_smoke) {
   constexpr off64_t file_size = 32*1024LL;
 
diff --git a/tests/utils.h b/tests/utils.h
index 410b427..a5783af 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -18,6 +18,7 @@
 #define __TEST_UTILS_H
 
 #include <dlfcn.h>
+#include <fcntl.h>
 #include <inttypes.h>
 #include <sys/mman.h>
 #include <sys/types.h>
@@ -151,6 +152,12 @@
   }
 }
 
+static inline void AssertCloseOnExec(int fd, bool close_on_exec) {
+  int flags = fcntl(fd, F_GETFD);
+  ASSERT_NE(flags, -1);
+  ASSERT_EQ(close_on_exec ? FD_CLOEXEC : 0, flags & FD_CLOEXEC);
+}
+
 // The absolute path to the executable
 const std::string& get_executable_path();
 
diff --git a/tools/versioner/platforms b/tools/versioner/platforms
deleted file mode 120000
index bcb7da8..0000000
--- a/tools/versioner/platforms
+++ /dev/null
@@ -1 +0,0 @@
-../../../development/ndk/platforms
\ No newline at end of file
diff --git a/tools/versioner/src/SymbolDatabase.cpp b/tools/versioner/src/SymbolDatabase.cpp
index 8521f4d..5b8ed5a 100644
--- a/tools/versioner/src/SymbolDatabase.cpp
+++ b/tools/versioner/src/SymbolDatabase.cpp
@@ -61,91 +61,3 @@
 
   return result;
 }
-
-// The NDK platforms are built by copying the platform directories on top of
-// each other to build each successive API version. Thus, we need to walk
-// backwards to find each desired file.
-static std::string readPlatformFile(const CompilationType& type, llvm::StringRef platform_dir,
-                                    const std::string& filename, bool required) {
-  int api_level = type.api_level;
-  std::ifstream stream;
-  while (api_level >= arch_min_api[type.arch]) {
-    std::string path = std::string(platform_dir) + "/android-" + std::to_string(api_level) +
-                       "/arch-" + to_string(type.arch) + "/symbols/" + filename;
-
-    stream = std::ifstream(path);
-    if (stream) {
-      return std::string(std::istreambuf_iterator<char>(stream), std::istreambuf_iterator<char>());
-    }
-
-    --api_level;
-  }
-
-  if (required) {
-    errx(1, "failed to find platform file '%s' for %s", filename.c_str(), to_string(type).c_str());
-  }
-
-  return std::string();
-}
-
-static std::map<std::string, NdkSymbolType> parsePlatform(const CompilationType& type,
-                                                          const std::string& platform_dir) {
-  std::map<std::string, NdkSymbolType> result;
-  std::map<std::string, bool /*required*/> wanted_files = {
-    { "libc.so.functions.txt", true },
-    { "libc.so.variables.txt", false },
-    { "libdl.so.functions.txt", false },
-    { "libm.so.functions.txt", false },
-    { "libm.so.variables.txt", false },
-  };
-
-  for (const auto& pair : wanted_files) {
-    llvm::StringRef file = pair.first;
-    bool required = pair.second;
-    NdkSymbolType symbol_type;
-    if (file.endswith(".functions.txt")) {
-      symbol_type = NdkSymbolType::function;
-    } else if (file.endswith(".variables.txt")) {
-      symbol_type = NdkSymbolType::variable;
-    } else {
-      errx(1, "internal error: unexpected platform filename '%s'\n", file.str().c_str());
-    }
-
-    std::string platform_file = readPlatformFile(type, platform_dir, file, required);
-    if (platform_file.empty()) {
-      continue;
-    }
-
-    llvm::SmallVector<llvm::StringRef, 0> symbols;
-    llvm::StringRef(platform_file).split(symbols, "\n");
-
-    for (llvm::StringRef symbol_name : symbols) {
-      if (symbol_name.empty()) {
-        continue;
-      }
-
-      if (result.count(symbol_name) != 0) {
-        if (strict) {
-          printf("duplicated symbol '%s' in '%s'\n", symbol_name.str().c_str(), file.str().c_str());
-        }
-      }
-
-      result[symbol_name] = symbol_type;
-    }
-  }
-
-  return result;
-}
-
-NdkSymbolDatabase parsePlatforms(const std::set<CompilationType>& types,
-                                 const std::string& platform_dir) {
-  std::map<std::string, std::map<CompilationType, NdkSymbolType>> result;
-  for (const CompilationType& type : types) {
-    std::map<std::string, NdkSymbolType> symbols = parsePlatform(type, platform_dir);
-    for (const auto& it : symbols) {
-      result[it.first][type] = it.second;
-    }
-  }
-
-  return result;
-}
diff --git a/tools/versioner/src/SymbolDatabase.h b/tools/versioner/src/SymbolDatabase.h
index 09948f5..c5b89d7 100644
--- a/tools/versioner/src/SymbolDatabase.h
+++ b/tools/versioner/src/SymbolDatabase.h
@@ -32,5 +32,3 @@
 };
 
 using NdkSymbolDatabase = std::map<std::string, std::map<CompilationType, NdkSymbolType>>;
-NdkSymbolDatabase parsePlatforms(const std::set<CompilationType>& types,
-                                 const std::string& platform_dir);
diff --git a/tools/versioner/src/versioner.cpp b/tools/versioner/src/versioner.cpp
index a082f07..efb39bd 100644
--- a/tools/versioner/src/versioner.cpp
+++ b/tools/versioner/src/versioner.cpp
@@ -33,6 +33,7 @@
 #include <iostream>
 #include <map>
 #include <memory>
+#include <optional>
 #include <set>
 #include <sstream>
 #include <string>
@@ -614,9 +615,6 @@
     std::string versioner_dir = to_string(top) + "/bionic/tools/versioner";
     location.header_path = versioner_dir + "/current";
     location.dependency_dir = versioner_dir + "/dependencies";
-    if (platform_dir.empty()) {
-      platform_dir = versioner_dir + "/platforms";
-    }
   } else {
     if (!android::base::Realpath(argv[optind], &location.header_path)) {
       err(1, "failed to get realpath for path '%s'", argv[optind]);
@@ -653,16 +651,10 @@
   }
 
   std::set<CompilationType> compilation_types;
-  NdkSymbolDatabase symbol_database;
+  std::optional<NdkSymbolDatabase> symbol_database;
 
   compilation_types = generateCompilationTypes(selected_architectures, selected_levels);
 
-  // Do this before compiling so that we can early exit if the platforms don't match what we
-  // expect.
-  if (!platform_dir.empty()) {
-    symbol_database = parsePlatforms(compilation_types, platform_dir);
-  }
-
   auto start = std::chrono::high_resolution_clock::now();
   std::unique_ptr<HeaderDatabase> declaration_database =
       compileHeaders(compilation_types, location);
@@ -682,8 +674,8 @@
       failed = true;
     }
 
-    if (!platform_dir.empty()) {
-      if (!checkVersions(compilation_types, declaration_database.get(), symbol_database)) {
+    if (symbol_database) {
+      if (!checkVersions(compilation_types, declaration_database.get(), *symbol_database)) {
         printf("versioner: version check failed\n");
         failed = true;
       }