浏览代码

add getauxval function

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.
Rich Felker 11 年之前
父节点
当前提交
21ada94c4b
共有 2 个文件被更改,包括 28 次插入0 次删除
  1. 16 0
      include/sys/auxv.h
  2. 12 0
      src/misc/getauxval.c

+ 16 - 0
include/sys/auxv.h

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

+ 12 - 0
src/misc/getauxval.c

@@ -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;
+}