mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-09 23:00:07 +00:00
misc: Add internal __getauxval2 function
The explicit error return value (without in-band signaling) avoids complicated steps to detect errors based on whether errno has been updated. Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
This commit is contained in:
parent
0ce51bef34
commit
562ef5e69e
@ -5,4 +5,9 @@
|
|||||||
extern __typeof (getauxval) __getauxval;
|
extern __typeof (getauxval) __getauxval;
|
||||||
libc_hidden_proto (__getauxval)
|
libc_hidden_proto (__getauxval)
|
||||||
|
|
||||||
|
/* Like getauxval, but writes the value to *RESULT and returns true if
|
||||||
|
found, or returns false. Does not set errno. */
|
||||||
|
_Bool __getauxval2 (unsigned long int type, unsigned long int *result);
|
||||||
|
libc_hidden_proto (__getauxval2)
|
||||||
|
|
||||||
#endif /* !_ISOMAC */
|
#endif /* !_ISOMAC */
|
||||||
|
@ -18,26 +18,47 @@
|
|||||||
#include <sys/auxv.h>
|
#include <sys/auxv.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ldsodefs.h>
|
#include <ldsodefs.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
bool
|
||||||
unsigned long int
|
__getauxval2 (unsigned long int type, unsigned long int *result)
|
||||||
__getauxval (unsigned long int type)
|
|
||||||
{
|
{
|
||||||
#ifdef HAVE_AUX_VECTOR
|
#ifdef HAVE_AUX_VECTOR
|
||||||
ElfW(auxv_t) *p;
|
ElfW(auxv_t) *p;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (type == AT_HWCAP)
|
if (type == AT_HWCAP)
|
||||||
return GLRO(dl_hwcap);
|
{
|
||||||
|
*result = GLRO(dl_hwcap);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else if (type == AT_HWCAP2)
|
else if (type == AT_HWCAP2)
|
||||||
return GLRO(dl_hwcap2);
|
{
|
||||||
|
*result = GLRO(dl_hwcap2);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_AUX_VECTOR
|
#ifdef HAVE_AUX_VECTOR
|
||||||
for (p = GLRO(dl_auxv); p->a_type != AT_NULL; p++)
|
for (p = GLRO(dl_auxv); p->a_type != AT_NULL; p++)
|
||||||
if (p->a_type == type)
|
if (p->a_type == type)
|
||||||
return p->a_un.a_val;
|
{
|
||||||
|
*result = p->a_un.a_val;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
libc_hidden_def (__getauxval2)
|
||||||
|
|
||||||
|
unsigned long int
|
||||||
|
__getauxval (unsigned long int type)
|
||||||
|
{
|
||||||
|
unsigned long int result;
|
||||||
|
|
||||||
|
if (__getauxval2 (type, &result))
|
||||||
|
return result;
|
||||||
|
|
||||||
__set_errno (ENOENT);
|
__set_errno (ENOENT);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user