[vlc-devel] [PATCH] compat: add lfind

Victorien Le Couviour--Tuffet victorien.lecouviour.tuffet at gmail.com
Mon Oct 8 12:30:42 CEST 2018


Fixes android build with NDK 17 as lfind is not always available.
---
 compat/lfind.c       | 19 +++++++++++++++++++
 configure.ac         |  2 +-
 include/vlc_fixups.h |  2 ++
 3 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 compat/lfind.c

diff --git a/compat/lfind.c b/compat/lfind.c
new file mode 100644
index 0000000000..d62b2cfd9b
--- /dev/null
+++ b/compat/lfind.c
@@ -0,0 +1,19 @@
+/*****************************************************************************
+ * lfind.c : implement lfind
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+void *lfind(const void *key, const void *base, size_t *nmemb,
+            size_t size, int(*cmp)(const void *, const void *))
+{
+    for (int i = 0; i < *nmemb; ++i)
+    {
+        const void *elem = base + i * size;
+        if (!cmp(key, elem))
+            return elem;
+    }
+    return NULL;
+}
diff --git a/configure.ac b/configure.ac
index f352de1138..686fb55e5c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -581,7 +581,7 @@ need_libc=false
 
 dnl Check for usual libc functions
 AC_CHECK_FUNCS([accept4 daemon fcntl flock fstatvfs fork getenv getpwuid_r isatty memalign mkostemp mmap open_memstream newlocale openat pipe2 pread posix_fadvise posix_madvise posix_memalign setlocale stricmp strnicmp strptime uselocale])
-AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir flockfile fsync getdelim getpid lldiv memrchr nrand48 poll recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy tfind timegm timespec_get twalk strverscmp pathconf])
+AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir flockfile fsync getdelim getpid lfind lldiv memrchr nrand48 poll recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy tfind timegm timespec_get twalk strverscmp pathconf])
 AC_REPLACE_FUNCS([gettimeofday])
 AC_CHECK_FUNC(fdatasync,,
   [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index 87394fccad..caf1768f63 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -486,6 +486,8 @@ void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void
 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
+void *lfind( const void *key, const void *base, size_t *nmemb,
+             size_t size, int(*cmp)(const void *, const void *) );
 #endif /* HAVE_SEARCH_H */
 #ifndef HAVE_TDESTROY
 void tdestroy( void *root, void (*free_node)(void *nodep) );
-- 
2.19.1



More information about the vlc-devel mailing list