[vlc-devel] [PATCH] compat: split twalk from tfind.c

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


This fixes android build with NDK 17 since tfind is always available but
not twalk.
---
 compat/tfind.c | 49 +------------------------------------
 compat/twalk.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++
 configure.ac   |  2 +-
 3 files changed, 68 insertions(+), 49 deletions(-)
 create mode 100644 compat/twalk.c

diff --git a/compat/tfind.c b/compat/tfind.c
index 804ecb8e43..abef9f44a6 100644
--- a/compat/tfind.c
+++ b/compat/tfind.c
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * tfind.c : implement every t* fuctions
+ * tfind.c : implement every t* functions except twalk
  *****************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -205,51 +205,4 @@ tsearch(vkey, vrootp, compar)
 	return q;
 }
 
-
-/*	$NetBSD: twalk.c,v 1.2 1999/09/16 11:45:37 lukem Exp $	*/
-
-/*
- * Tree search generalized from Knuth (6.2.2) Algorithm T just like
- * the AT&T man page says.
- *
- * The node_t structure is for internal use only, lint doesn't grok it.
- *
- * Written by reading the System V Interface Definition, not the code.
- *
- * Totally public domain.
- */
-
-/* Walk the nodes of a tree */
-static void
-twalk_recurse(root, action, level)
-	const node_t *root;	/* Root of the tree to be walked */
-	void (*action) (const void *, VISIT, int);
-	int level;
-{
-	assert(root != NULL);
-	assert(action != NULL);
-
-	if (root->llink == NULL && root->rlink == NULL)
-		(*action)(root, leaf, level);
-	else {
-		(*action)(root, preorder, level);
-		if (root->llink != NULL)
-			twalk_recurse(root->llink, action, level + 1);
-		(*action)(root, postorder, level);
-		if (root->rlink != NULL)
-			twalk_recurse(root->rlink, action, level + 1);
-		(*action)(root, endorder, level);
-	}
-}
-
-/* Walk the nodes of a tree */
-void
-twalk(vroot, action)
-	const void *vroot;	/* Root of the tree to be walked */
-	void (*action) (const void *, VISIT, int);
-{
-	if (vroot != NULL && action != NULL)
-		twalk_recurse(vroot, action, 0);
-}
-
 #endif // HAVE_SEARCH_H
diff --git a/compat/twalk.c b/compat/twalk.c
new file mode 100644
index 0000000000..59486d7575
--- /dev/null
+++ b/compat/twalk.c
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * twalk.c : implement twalk
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/** search.h is not present so twalk has to be implemented */
+#ifndef HAVE_SEARCH_H
+
+#include <assert.h>
+#include <stdlib.h>
+
+typedef struct node {
+    char         *key;
+    struct node  *llink, *rlink;
+} node_t;
+
+/*	$NetBSD: twalk.c,v 1.2 1999/09/16 11:45:37 lukem Exp $	*/
+
+/*
+ * Tree search generalized from Knuth (6.2.2) Algorithm T just like
+ * the AT&T man page says.
+ *
+ * The node_t structure is for internal use only, lint doesn't grok it.
+ *
+ * Written by reading the System V Interface Definition, not the code.
+ *
+ * Totally public domain.
+ */
+
+/* Walk the nodes of a tree */
+static void
+twalk_recurse(root, action, level)
+	const node_t *root;	/* Root of the tree to be walked */
+	void (*action) (const void *, VISIT, int);
+	int level;
+{
+	assert(root != NULL);
+	assert(action != NULL);
+
+	if (root->llink == NULL && root->rlink == NULL)
+		(*action)(root, leaf, level);
+	else {
+		(*action)(root, preorder, level);
+		if (root->llink != NULL)
+			twalk_recurse(root->llink, action, level + 1);
+		(*action)(root, postorder, level);
+		if (root->rlink != NULL)
+			twalk_recurse(root->rlink, action, level + 1);
+		(*action)(root, endorder, level);
+	}
+}
+
+/* Walk the nodes of a tree */
+void
+twalk(vroot, action)
+	const void *vroot;	/* Root of the tree to be walked */
+	void (*action) (const void *, VISIT, int);
+{
+	if (vroot != NULL && action != NULL)
+		twalk_recurse(vroot, action, 0);
+}
+
+#endif /* HAVE_SEARCH_H */
diff --git a/configure.ac b/configure.ac
index 202f1fa624..f352de1138 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 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.])
-- 
2.19.1



More information about the vlc-devel mailing list