More pthreads cleanup.

POSIX says pthread_create returns EAGAIN, not ENOMEM.

Also pull pthread_attr_t functions into their own file.

Also pull pthread_setname_np into its own file.

Also remove unnecessary #includes from pthread_key.cpp.

Also account for those pthread keys used internally by bionic,
so they don't count against the number of keys available to user
code. (They do with glibc, but glibc's limit is the much more
generous 1024.)

Also factor out the common errno-restoring idiom to reduce gotos.

Bug: 6702535
Change-Id: I555e66efffcf2c1b5a2873569e91489156efca42
diff --git a/libc/bionic/tmpfile.cpp b/libc/bionic/tmpfile.cpp
index b97cc6c..8419ff5 100644
--- a/libc/bionic/tmpfile.cpp
+++ b/libc/bionic/tmpfile.cpp
@@ -38,6 +38,8 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include "private/ErrnoRestorer.h"
+
 class ScopedSignalBlocker {
  public:
   ScopedSignalBlocker() {
@@ -77,9 +79,8 @@
     struct stat sb;
     int rc = fstat(fd, &sb);
     if (rc == -1) {
-      int old_errno = errno;
+      ErrnoRestorer errno_restorer;
       close(fd);
-      errno = old_errno;
       return NULL;
     }
   }
@@ -91,9 +92,8 @@
   }
 
   // Failure. Clean up. We already unlinked, so we just need to close.
-  int old_errno = errno;
+  ErrnoRestorer errno_restorer;
   close(fd);
-  errno = old_errno;
   return NULL;
 }