diff options
author | Elliott Hughes <enh@google.com> | 2012-09-17 15:23:35 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2012-09-17 15:23:35 -0700 |
commit | 4198fa4c23fc8a1895808a597bb153530f6ea515 (patch) | |
tree | 79a050550930720fba3886064bd95acc10944f11 /libc/bionic/strerror_r.cpp | |
parent | 4e9d953a0e9334c0f3519f470b97973c31da5bb6 (diff) | |
download | bionic-4198fa4c23fc8a1895808a597bb153530f6ea515.zip bionic-4198fa4c23fc8a1895808a597bb153530f6ea515.tar.gz bionic-4198fa4c23fc8a1895808a597bb153530f6ea515.tar.bz2 |
Don't copy strerror(3) or strsignal(3) strings if we can share.
Change-Id: Ic405269f63b945c6fb347e7c4346cd6f104aff35
Diffstat (limited to 'libc/bionic/strerror_r.cpp')
-rw-r--r-- | libc/bionic/strerror_r.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/libc/bionic/strerror_r.cpp b/libc/bionic/strerror_r.cpp index 92235a5..a00ebe5 100644 --- a/libc/bionic/strerror_r.cpp +++ b/libc/bionic/strerror_r.cpp @@ -27,11 +27,25 @@ static const Pair _sys_error_strings[] = { { 0, NULL } }; +extern "C" const char* __strerror_lookup(int error_number) { + return __code_string_lookup(_sys_error_strings, error_number); +} + +static const Pair _sys_signal_strings[] = { +#define __BIONIC_SIGDEF(x,y,z) { y, z }, +#include <sys/_sigdefs.h> + { 0, NULL } +}; + +extern "C" const char* __strsignal_lookup(int signal_number) { + return __code_string_lookup(_sys_signal_strings, signal_number); +} + int strerror_r(int error_number, char* buf, size_t buf_len) { int saved_errno = errno; size_t length; - const char* error_name = __code_string_lookup(_sys_error_strings, error_number); + const char* error_name = __strerror_lookup(error_number); if (error_name != NULL) { length = snprintf(buf, buf_len, "%s", error_name); } else { @@ -46,14 +60,8 @@ int strerror_r(int error_number, char* buf, size_t buf_len) { return 0; } -static const Pair _sys_signal_strings[] = { -#define __BIONIC_SIGDEF(x,y,z) { y, z }, -#include <sys/_sigdefs.h> - { 0, NULL } -}; - extern "C" const char* __strsignal(int signal_number, char* buf, size_t buf_len) { - const char* signal_name = __code_string_lookup(_sys_signal_strings, signal_number); + const char* signal_name = __strsignal_lookup(signal_number); if (signal_name != NULL) { return signal_name; } |