[vlc-commits] compat: add lfind

Victorien Le Couviour--Tuffet git at videolan.org
Tue Oct 23 14:53:59 CEST 2018


vlc | branch: master | Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet at gmail.com> | Tue Oct  2 15:42:02 2018 +0200| [cf9bd77c67b844cd188f266d6b2aaacdb45bf60c] | committer: Thomas Guillem

compat: add lfind

Fixes android build with NDK 17 as lfind is not always available.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cf9bd77c67b844cd188f266d6b2aaacdb45bf60c
---

 compat/lfind.c       | 19 +++++++++++++++++++
 configure.ac         |  2 +-
 include/vlc_fixups.h |  2 ++
 3 files changed, 22 insertions(+), 1 deletion(-)

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 9066dd7022..c1abf7dbd2 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 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 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) );



More information about the vlc-commits mailing list