From cb1ab5b5fc8237705e82a56350e4ef25349576ae Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sat, 29 Apr 2017 13:45:33 -0400 Subject: [PATCH] roken: refactor rk_getauxval Refactor rk_getauxval() to remove duplicate code and to ensure that a value is always returned. Change-Id: I3b452dbc11802169e2c96e7ad16e714e7a880450 --- lib/roken/getauxval.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/lib/roken/getauxval.c b/lib/roken/getauxval.c index 31f52fa6e..2fab37638 100644 --- a/lib/roken/getauxval.c +++ b/lib/roken/getauxval.c @@ -157,12 +157,12 @@ rk_getprocauxval(unsigned long type) ROKEN_LIB_FUNCTION unsigned long ROKEN_LIB_CALL rk_getauxval(unsigned long type) { -#ifdef HAVE_GETAUXVAL -#ifdef GETAUXVAL_SETS_ERRNO +#if defined(HAVE_GETAUXVAL) && defined(GETAUXVAL_SETS_ERRNO) if (rk_injected_auxv) return rk_getprocauxval(type); return getauxval(type); #else + const auxv_t *a; unsigned long ret; unsigned long ret2; static int getauxval_sets_errno = -1; @@ -181,17 +181,8 @@ rk_getauxval(unsigned long type) return ret; } - if (getauxval_sets_errno == 0) { - const auxv_t *a; - - errno = save_errno; - a = rk_getauxv(type); - if (a == NULL) { - errno = ENOENT; - return 0; - } - return a->a_un.a_val; - } + if (getauxval_sets_errno == 0) + goto out; /* * We've called getauxval() and it returned 0, but we don't know if @@ -200,7 +191,6 @@ rk_getauxval(unsigned long type) * Attempt to detect whether getauxval() sets errno = ENOENT by * calling it with what should be a bogus type. */ - errno = 0; ret2 = getauxval(~type); if (ret2 == 0 && errno == ENOENT) { @@ -208,16 +198,14 @@ rk_getauxval(unsigned long type) errno = save_errno; return ret; } - getauxval_sets_errno = 0; - errno = save_errno; -#endif -#else - const auxv_t *a; - if ((a = rk_getauxv(type)) == NULL) { - errno = ENOENT; - return 0; + out: + errno = save_errno; + a = rk_getauxv(type); + if (a == NULL) { + errno = ENOENT; + return 0; } return a->a_un.a_val; #endif