add getauxval function
authorRich Felker <dalias@aerifal.cx>
Mon, 7 Apr 2014 06:46:15 +0000 (02:46 -0400)
committerRich Felker <dalias@aerifal.cx>
Mon, 7 Apr 2014 06:46:15 +0000 (02:46 -0400)
in a sense this implementation is incomplete since it doesn't provide
the HWCAP_* macros for use with AT_HWCAP, which is perhaps the most
important intended usage case for getauxval. they will be added at a
later time.

include/sys/auxv.h [new file with mode: 0644]
src/misc/getauxval.c [new file with mode: 0644]

diff --git a/include/sys/auxv.h b/include/sys/auxv.h
new file mode 100644 (file)
index 0000000..6dcf9ad
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef _SYS_AUXV_H
+#define _SYS_AUXV_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <elf.h>
+
+unsigned long getauxval(unsigned long);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/misc/getauxval.c b/src/misc/getauxval.c
new file mode 100644 (file)
index 0000000..5ac8b3d
--- /dev/null
@@ -0,0 +1,12 @@
+#include <sys/auxv.h>
+#include <errno.h>
+#include "libc.h"
+
+unsigned long getauxval(unsigned long item)
+{
+       size_t *auxv = libc.auxv;
+       for (; *auxv; auxv+=2)
+               if (*auxv==item) return auxv[1];
+       errno = ENOENT;
+       return 0;
+}