]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
misc: Add internal __getauxval2 function
authorFlorian Weimer <fweimer@redhat.com>
Tue, 27 Oct 2020 09:42:10 +0000 (10:42 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Tue, 27 Oct 2020 15:34:37 +0000 (16:34 +0100)
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>
include/sys/auxv.h
misc/getauxval.c

index 3bab6d05d43016808ec7551e675042dae4ca3dce..dd0602b08d881cd3bb75ec7f0042a88af6a8fdf8 100644 (file)
@@ -5,4 +5,9 @@
 extern __typeof (getauxval) __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 */
index d7f9f957d09f6772cbf2854b2f4d96fc8660423e..e96d4dfa2066f1a23063bb36c5f8cd901e3ceb9d 100644 (file)
 #include <sys/auxv.h>
 #include <errno.h>
 #include <ldsodefs.h>
+#include <stdbool.h>
 
-
-unsigned long int
-__getauxval (unsigned long int type)
+bool
+__getauxval2 (unsigned long int type, unsigned long int *result)
 {
 #ifdef HAVE_AUX_VECTOR
   ElfW(auxv_t) *p;
 #endif
 
   if (type == AT_HWCAP)
-    return GLRO(dl_hwcap);
+    {
+      *result = GLRO(dl_hwcap);
+      return true;
+    }
   else if (type == AT_HWCAP2)
-    return GLRO(dl_hwcap2);
+    {
+      *result = GLRO(dl_hwcap2);
+      return true;
+    }
 
 #ifdef HAVE_AUX_VECTOR
   for (p = GLRO(dl_auxv); p->a_type != AT_NULL; p++)
     if (p->a_type == type)
-      return p->a_un.a_val;
+      {
+        *result = p->a_un.a_val;
+        return true;
+      }
 #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);
   return 0;
 }