瀏覽代碼

Fix the bugs I stupidly added

Eric Andersen 22 年之前
父節點
當前提交
a1380a837e
共有 3 個文件被更改,包括 29 次插入2 次删除
  1. 1 1
      libc/misc/ftw/ftw.c
  2. 1 1
      libc/misc/search/Makefile
  3. 27 0
      libc/misc/search/tsearch.c

+ 1 - 1
libc/misc/ftw/ftw.c

@@ -486,7 +486,7 @@ ftw_startup (const char *dir, int is_nftw, void *func, int descriptors, int flag
     data.dirbuf = (char *) malloc (data.dirbufsize);
     if (data.dirbuf == NULL)
 	return -1;
-    cp = __stpcpy (data.dirbuf, dir);
+    cp = stpcpy (data.dirbuf, dir);
     /* Strip trailing slashes.  */
     while (cp > data.dirbuf + 1 && cp[-1] == '/')
 	--cp;

+ 1 - 1
libc/misc/search/Makefile

@@ -25,7 +25,7 @@ TOPDIR=../../../
 include $(TOPDIR)Rules.mak
 
 MSRC1=tsearch.c
-MOBJ1=tsearch.o tfind.o tdelete.o twalk.o
+MOBJ1=tsearch.o tfind.o tdelete.o twalk.o tdestroy.o
 
 MSRC2=lsearch.c
 MOBJ2=lfind.o lsearch.o

+ 27 - 0
libc/misc/search/tsearch.c

@@ -28,6 +28,7 @@ Cambridge, MA 02139, USA.  */
  */
 /*LINTLIBRARY*/
 
+#define _GNU_SOURCE
 #include <search.h>
 #include <stdlib.h>
 
@@ -187,4 +188,30 @@ void twalk(__const void *vroot, __action_fn_t action)
 }
 #endif
 
+#ifdef L_tdestroy
+/* The standardized functions miss an important functionality: the
+   tree cannot be removed easily.  We provide a function to do this.  */
+static void
+internal_function
+tdestroy_recurse (node *root, __free_fn_t freefct)
+{
+    if (root->left != NULL)
+	tdestroy_recurse (root->left, freefct);
+    if (root->right != NULL)
+	tdestroy_recurse (root->right, freefct);
+    (*freefct) ((void *) root->key);
+    /* Free the node itself.  */
+    free (root);
+}
+
+void tdestroy (void *vroot, __free_fn_t freefct)
+{
+    node *root = (node *) vroot;
+    if (root != NULL) {
+	tdestroy_recurse (root, freefct);
+    }
+}
+#endif
+
 /* tsearch.c ends here */
+