From ea93bcb8d3f6cde11502d5a18076b4406d59e413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sun, 20 Feb 2022 22:34:48 +0200 Subject: [PATCH] compat: Linux getauxval() replacement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was added over a decade ago, but 🤷... --- compat/getauxval.c | 43 +++++++++++++++++++++++++++++++++++++++++++ configure.ac | 1 + include/vlc_fixups.h | 5 +++++ 3 files changed, 49 insertions(+) create mode 100644 compat/getauxval.c diff --git a/compat/getauxval.c b/compat/getauxval.c new file mode 100644 index 0000000000..e0202f4f6f --- /dev/null +++ b/compat/getauxval.c @@ -0,0 +1,43 @@ +/***************************************************************************** + * getauxval.c: Linux getauxval() replacement + ***************************************************************************** + * Copyright © 2022 Rémi Denis-Courmont + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +extern char **environ; + +unsigned long getauxval(unsigned long type) +{ + const unsigned long *auxv; + size_t i = 0; + + while (environ[i++] != NULL); + + auxv = (const void *)&environ[i]; + + for (i = 0; auxv[i]; i += 2) + if (auxv[i] == type) + return auxv[i + 1]; + + return 0; +} diff --git a/configure.ac b/configure.ac index 4c48941c2e..0dda204bf1 100644 --- a/configure.ac +++ b/configure.ac @@ -734,6 +734,7 @@ dnl Check for non-standard system calls case "$SYS" in "linux") AC_CHECK_FUNCS([eventfd vmsplice sched_getaffinity recvmmsg memfd_create]) + AC_REPLACE_FUNCS([getauxval]) ;; "mingw32") AC_CHECK_FUNCS([_lock_file]) diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h index 1911057dbf..a8481e4b53 100644 --- a/include/vlc_fixups.h +++ b/include/vlc_fixups.h @@ -503,6 +503,11 @@ void *lfind( const void *key, const void *base, size_t *nmemb, void tdestroy( void *root, void (*free_node)(void *nodep) ); #endif +/* sys/auxv.h */ +#ifndef HAVE_GETAUXVAL +unsigned long getauxval(unsigned long); +#endif + /* Random numbers */ #ifndef HAVE_NRAND48 double erand48 (unsigned short subi[3]);