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
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