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
This commit is contained in:
@@ -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 @@ extern "C" __LIBC_HIDDEN__ const char* __strsignal_lookup(int signal_number) {
|
||||
}
|
||||
|
||||
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 @@ int strerror_r(int error_number, char* buf, size_t buf_len) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user