[vlc-commits] compat: add lfind

Victorien Le Couviour--Tuffet git at videolan.org
Tue Oct 23 17:25:19 CEST 2018


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

compat: add lfind

Fixes android build with NDK 17 as lfind is not always available.
(cherry picked from commit cf9bd77c67b844cd188f266d6b2aaacdb45bf60c)
Signed-off-by: Thomas Guillem <thomas at gllm.fr>

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

 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 007a2def19..826b6ba43e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -591,7 +591,7 @@ need_libc=false
 
 dnl Check for usual libc functions
 AC_CHECK_FUNCS([accept4 daemon fcntl flock fstatvfs fork getenv getpwuid_r isatty lstat memalign mkostemp mmap newlocale open_memstream openat pipe2 pread posix_fadvise posix_madvise posix_memalign setlocale stricmp strnicmp strptime uselocale])
-AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir ffsll 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 ffsll 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 286ff12ca6..6c0de2854b 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -488,6 +488,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