diff lib/fts_.h @ 5872:fab6701e5cb2

New fts module. * MODULES.html.sh (File system functions): Add fts, fts-lgpl. * lib/fts.c: Don't include "cycle-check.h" or "hash.h". (setup_dir, free_dir): New functions. (enter_dir, leave_dir): Define trivial alternatives of _LGPL_PACKAGE. Move to fts-cycle.c if !_LGPL_PACKAGE. (HT_INITIAL_SIZE, ENTER_DIR): Remove. All uses removed. (LEAVE_DIR): Fix typo: pass Fts and Ent to leave_dir. (struct Active_dir, AD_compare, AD_hash, enter_dir, leave_dir): Move to fts-cycle.c. (fts_open): Use setup_dir. (fts_close): Use free_dir. (fts_read): Have just one copy of the ENTER_DIR code rather than three. This adds a label and some gotos, but the alternatives were messier. Check for memory allocation failure when entering a dir. (fts_stat) [_LGPL_PACKAGE]: Bring back glibc cycle detection code. * lib/fts_.h (_LGPL_PACKAGE) [defined _LIBC]: New macro. (FTS): New member fts_cycle, that is a union that contains the old active_dir_ht and cycle_state. All uses changed to mention fts_cycle.ht and fts_cycle.state. * lib/fts-cycle.c: New file, containing GPL'ed code migrated out of fts.c, with the following changes: (setup_dir, free_dir): New functions. (enter_dir): Now returns bool. Return true if successful, false if memory exhausted. All callers changed. Do not bother partly cleaning up on memory allocation failure; that is free_dir's job. However, free ad if hash_insert fails, to avoid memory leak. (enter_dir, leave_dir): Accommodate change to FTS by inspecting fts->fts_options to see which union member to use. * m4/fts.m4 (gl_FUNC_FTS_CORE): Renamed from gl_FUNC_FTS. (gl_FUNC_FTS, gl_FUNC_FTS_LGPL): New macros. * lib/unlinkdir.h (cannot_unlink_dir) [UNLINK_CANNOT_UNLINK_DIR]: Now a macro, to pacify GCC.
author Paul Eggert <eggert@cs.ucla.edu>
date Fri, 20 May 2005 23:07:53 +0000 (2005-05-20)
parents 67b499052f7f
children c47674a83a78
line wrap: on
line diff
--- a/lib/fts_.h
+++ b/lib/fts_.h
@@ -52,6 +52,7 @@
 
 # ifdef _LIBC
 #  include <features.h>
+#  define _LGPL_PACKAGE 1
 # else
 #  undef __THROW
 #  define __THROW
@@ -104,19 +105,28 @@
 # define FTS_STOP	0x2000		/* (private) unrecoverable error */
 	int fts_options;		/* fts_open options, global flags */
 
-	/* This data structure records the directories between a starting
-	   point and the current directory.  I.e., a directory is recorded
-	   here IFF we have visited it once, but we have not yet completed
-	   processing of all its entries.  Every time we visit a new directory,
-	   we add that directory to this set.  When we finish with a directory
-	   (usually by visiting it a second time), we remove it from this
-	   set.  Each entry in this data structure is a device/inode pair.
-	   This data structure is used to detect directory cycles efficiently
-	   and promptly even when the depth of a hierarchy is in the tens
-	   of thousands.  Lazy checking, as done by GNU rm via cycle-check.c,
-	   wouldn't be appropriate for du.  */
-	struct hash_table *active_dir_ht;
-	struct cycle_check_state *cycle_state;
+# if !_LGPL_PACKAGE
+	union {
+		/* This data structure is used if FTS_TIGHT_CYCLE_CHECK is
+		   specified.  It records the directories between a starting
+		   point and the current directory.  I.e., a directory is
+		   recorded here IFF we have visited it once, but we have not
+		   yet completed processing of all its entries.  Every time we
+		   visit a new directory, we add that directory to this set.
+		   When we finish with a directory (usually by visiting it a
+		   second time), we remove it from this set.  Each entry in
+		   this data structure is a device/inode pair.  This data
+		   structure is used to detect directory cycles efficiently and
+		   promptly even when the depth of a hierarchy is in the tens
+		   of thousands.  */
+		struct hash_table *ht;
+
+		/* This data structure uses lazy checking, as done by rm via
+	           cycle-check.c.  It's the default, but it's not appropriate
+	           for programs like du.  */
+		struct cycle_check_state *state;
+	} fts_cycle;
+# endif
 } FTS;
 
 typedef struct _ftsent {