From ee7649c5ac5f1e56cc8193cd4cee73004c04893d Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sun, 15 Mar 2015 21:39:25 -0400 Subject: [PATCH] set errno to ENOENT in getauxval per glibc 2.19 Bionic's getauxval(...) implementation returns zero when entries are missing. Zero can be a valid value, so there is no unambiguous way of detecting an error. Since glibc 2.19, errno is set to ENOENT when an entry is missing to make it possible to detect this. Bionic should match this behavior as code in the Linux ecosystem will start relying on it to check for the presence of newly added entries. Change-Id: Ic1efe29bc45fc87489274c96c4d2193f3a7b8854 Signed-off-by: Daniel Micay --- libc/bionic/getauxval.cpp | 2 ++ tests/getauxval_test.cpp | 3 +++ 2 files changed, 5 insertions(+) diff --git a/libc/bionic/getauxval.cpp b/libc/bionic/getauxval.cpp index bc4182496..22922b942 100644 --- a/libc/bionic/getauxval.cpp +++ b/libc/bionic/getauxval.cpp @@ -31,6 +31,7 @@ #include #include #include +#include __LIBC_HIDDEN__ ElfW(auxv_t)* __libc_auxv = NULL; @@ -40,5 +41,6 @@ extern "C" unsigned long int getauxval(unsigned long int type) { return v->a_un.a_val; } } + errno = ENOENT; return 0; } diff --git a/tests/getauxval_test.cpp b/tests/getauxval_test.cpp index b33115007..6ce00f14a 100644 --- a/tests/getauxval_test.cpp +++ b/tests/getauxval_test.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include @@ -53,7 +54,9 @@ TEST(getauxval, expected_values) { TEST(getauxval, unexpected_values) { #if defined(GETAUXVAL_CAN_COMPILE) + errno = 0; ASSERT_EQ((unsigned long int) 0, getauxval(0xdeadbeef)); + ASSERT_EQ(ENOENT, errno); #else GTEST_LOG_(INFO) << "This test does nothing.\n"; #endif