Revert "More pthreads cleanup."

This reverts commit 2a1bb4e64677b9abbc17173c79768ed494565047

Change-Id: Ia443d0748015c8e9fc3121e40e68258616767b51
diff --git a/libc/bionic/stubs.cpp b/libc/bionic/stubs.cpp
index 8ddc326..3f24d1b 100644
--- a/libc/bionic/stubs.cpp
+++ b/libc/bionic/stubs.cpp
@@ -31,17 +31,15 @@
 #include <grp.h>
 #include <mntent.h>
 #include <netdb.h>
+#include <private/android_filesystem_config.h>
+#include <private/debug_format.h>
+#include <private/logd.h>
 #include <pthread.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 
-#include "private/android_filesystem_config.h"
-#include "private/debug_format.h"
-#include "private/ErrnoRestorer.h"
-#include "private/logd.h"
-
 // Thread-specific state for the non-reentrant functions.
 static pthread_once_t stubs_once = PTHREAD_ONCE_INIT;
 static pthread_key_t stubs_key;
@@ -60,7 +58,7 @@
                       passwd** result) {
   // getpwnam_r and getpwuid_r don't modify errno, but library calls we
   // make might.
-  ErrnoRestorer errno_restorer;
+  int old_errno = errno;
   *result = NULL;
 
   // Our implementation of getpwnam(3) and getpwuid(3) use thread-local
@@ -71,7 +69,9 @@
   // POSIX allows failure to find a match to be considered a non-error.
   // Reporting success (0) but with *result NULL is glibc's behavior.
   if (src == NULL) {
-    return (errno == ENOENT) ? 0 : errno;
+    int rc = (errno == ENOENT) ? 0 : errno;
+    errno = old_errno;
+    return rc;
   }
 
   // Work out where our strings will go in 'buf', and whether we've got
@@ -84,11 +84,13 @@
   dst->pw_shell = buf + required_byte_count;
   required_byte_count += strlen(src->pw_shell) + 1;
   if (byte_count < required_byte_count) {
+    errno = old_errno;
     return ERANGE;
   }
 
   // Copy the strings.
-  snprintf(buf, byte_count, "%s%c%s%c%s", src->pw_name, 0, src->pw_dir, 0, src->pw_shell);
+  snprintf(buf, byte_count, "%s%c%s%c%s",
+           src->pw_name, 0, src->pw_dir, 0, src->pw_shell);
 
   // pw_passwd is non-POSIX and unused (always NULL) in bionic.
   // pw_gecos is non-POSIX and missing in bionic.
@@ -99,6 +101,7 @@
   dst->pw_uid = src->pw_uid;
 
   *result = dst;
+  errno = old_errno;
   return 0;
 }