Revert "Revert "More pthreads cleanup.""
This reverts commit 6f94de3ca49e4ea147b1c59e5818fa175846518f
(Doesn't try to increase the number of TLS slots; that leads to
an inability to boot. Adds more tests.)
Change-Id: Ia7d25ba3995219ed6e686463dbba80c95cc831ca
diff --git a/libc/bionic/strerror_r.cpp b/libc/bionic/strerror_r.cpp
index 646cc52..81120ec 100644
--- a/libc/bionic/strerror_r.cpp
+++ b/libc/bionic/strerror_r.cpp
@@ -7,6 +7,8 @@
#include <stdio.h>
#include <string.h>
+#include "private/ErrnoRestorer.h"
+
struct Pair {
int code;
const char* msg;
@@ -42,7 +44,7 @@
}
int strerror_r(int error_number, char* buf, size_t buf_len) {
- int saved_errno = errno;
+ ErrnoRestorer errno_restorer;
size_t length;
const char* error_name = __strerror_lookup(error_number);
@@ -52,11 +54,10 @@
length = snprintf(buf, buf_len, "Unknown error %d", error_number);
}
if (length >= buf_len) {
- errno = ERANGE;
+ errno_restorer.override(ERANGE);
return -1;
}
- errno = saved_errno;
return 0;
}