roken: refactor rk_getauxval

Refactor rk_getauxval() to remove duplicate code and to ensure
that a value is always returned.

Change-Id: I3b452dbc11802169e2c96e7ad16e714e7a880450
This commit is contained in:
Jeffrey Altman
2017-04-29 13:45:33 -04:00
parent 029d32580a
commit cb1ab5b5fc

View File

@@ -157,12 +157,12 @@ rk_getprocauxval(unsigned long type)
ROKEN_LIB_FUNCTION unsigned long ROKEN_LIB_CALL ROKEN_LIB_FUNCTION unsigned long ROKEN_LIB_CALL
rk_getauxval(unsigned long type) rk_getauxval(unsigned long type)
{ {
#ifdef HAVE_GETAUXVAL #if defined(HAVE_GETAUXVAL) && defined(GETAUXVAL_SETS_ERRNO)
#ifdef GETAUXVAL_SETS_ERRNO
if (rk_injected_auxv) if (rk_injected_auxv)
return rk_getprocauxval(type); return rk_getprocauxval(type);
return getauxval(type); return getauxval(type);
#else #else
const auxv_t *a;
unsigned long ret; unsigned long ret;
unsigned long ret2; unsigned long ret2;
static int getauxval_sets_errno = -1; static int getauxval_sets_errno = -1;
@@ -181,17 +181,8 @@ rk_getauxval(unsigned long type)
return ret; return ret;
} }
if (getauxval_sets_errno == 0) { if (getauxval_sets_errno == 0)
const auxv_t *a; goto out;
errno = save_errno;
a = rk_getauxv(type);
if (a == NULL) {
errno = ENOENT;
return 0;
}
return a->a_un.a_val;
}
/* /*
* We've called getauxval() and it returned 0, but we don't know if * 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 * Attempt to detect whether getauxval() sets errno = ENOENT by
* calling it with what should be a bogus type. * calling it with what should be a bogus type.
*/ */
errno = 0; errno = 0;
ret2 = getauxval(~type); ret2 = getauxval(~type);
if (ret2 == 0 && errno == ENOENT) { if (ret2 == 0 && errno == ENOENT) {
@@ -208,16 +198,14 @@ rk_getauxval(unsigned long type)
errno = save_errno; errno = save_errno;
return ret; return ret;
} }
getauxval_sets_errno = 0; getauxval_sets_errno = 0;
errno = save_errno;
#endif
#else
const auxv_t *a;
if ((a = rk_getauxv(type)) == NULL) { out:
errno = ENOENT; errno = save_errno;
return 0; a = rk_getauxv(type);
if (a == NULL) {
errno = ENOENT;
return 0;
} }
return a->a_un.a_val; return a->a_un.a_val;
#endif #endif