summaryrefslogtreecommitdiff
path: root/lib/fts.c
AgeCommit message (Collapse)Author
2006-07-11Sync from gnulib.Paul Eggert
2006-07-09Update from gnulib.Paul Eggert
2006-05-20(fts_open): Fail with EINVAL if a caller violates this rule:Jim Meyering
Either FTS_LOGICAL or FTS_PHYSICAL must be provided to the fts_open() function.
2006-05-15Avoid the expense of an fstat, when possible.Jim Meyering
(O_NOFOLLOW, STREQ): Define. (diropen_fd): Remove function. Merge it into sole caller... (diropen): ...here. Use O_NOFOLLOW when appropriate. (fts_safe_changedir): Call fstat for dev/inode check, only if the previous open/openat call may have opened the wrong directory.
2006-05-15Restore the parts of fts that were removed on 2006-01-17, so thatJim Meyering
it's easier for legacy applications designed for the version of fts in glibc or BSD to convert to this more robust version. Add a new mode, FTS_CWDFD, by which to enable the improved (openat- based -- aka no-chdir) semantics. * fts_.h (FTS_CWDFD): Define. Callers must use this fts_open option to enable the more robust behavior. (FTS_OPTIONMASK): Widen accordingly. * fts.c: Restore removed code, reverting the default behavior.
2006-04-14remove SPACEs before TABJim Meyering
2006-04-14(fts_open): Don't allocate parent if *argv==NULL. Patch from glibc.Jim Meyering
2006-04-14(fts_build): Free `head' before returning NULL, in two places,Jim Meyering
to avoid leaks. Patch from glibc.
2006-04-14(fts_build): Remove just-#if-0'd code and the code thatJim Meyering
declares and sets cderrno.
2006-04-14(fts_build): #if-0-out a block of unused code. Patch via glibc.Jim Meyering
2006-01-17Rewrite fts.c not to change the current working directory,Jim Meyering
by using openat, fstatat, fdopendir, etc.. [! _LIBC]: Include "openat.h" and "unistd--.h". (HAVE_OPENAT_SUPPORT): Define. [_LIBC] (fchdir): Don't undef or define; no longer used. (FCHDIR): Define in terms of cwd_advance_fd rather than fchdir. Now, this `function' always succeeds, and consumes its file descriptor parameter -- so callers must not close such FDs. Update callers. (diropen_fd, opendirat, cwd_advance_fd): New functions. (diropen): Add parameter, SP. Adjust all callers. Implement using diropen_fd, rather than open. (fts_open): Initialize new member, fts_cwd_fd. Remove fts_rft-setting code. (fts_close): Close fts_cwd_fd, if necessary. (__opendir2): Define in terms of opendir or opendirat, depending on whether the FST_NOCHDIR flag is set. (fts_build): Since fts_safe_changedir consumes its FD, and since this code must do `closedir(dirp)', dup the dirfd(dirp) argument, and close the dup'd file descriptor upon failure. (fts_stat): Use fstatat(...AT_SYMLINK_NOFOLLOW) in place of lstat. (fts_safe_changedir): Tweak semantics to reflect that this function now calls cwd_advance_fd and hence consumes its FD argument.
2006-01-11(fts_stat): When following a symlink-to-directory,Jim Meyering
don't interpret all stat-fails+lstat-succeeds as indicating a dangling symlink. That can also happen at least for ELOOP. The fix: return FTS_SLNONE only when the stat errno is ENOENT.
2006-01-11(fts_open): Put new (2006-01-04) maxarglen declaration and uses in theirJim Meyering
own block, so pre-c99 compilers don't object.
2006-01-11[!_LIBC]: Include "fcntl--.h", to map open to open_safer.Jim Meyering
2006-01-10Avoid the double-free (first in fts_read, second in fts_close) thatJim Meyering
would occur when an `active' directory is made inaccessible (e.g., via chmod a-x) during a traversal. (fts_read): After a failed fchdir, update sp->fts_cur before returning. Reproduce this failure by mkdir -p a/b; cd a; chmod a-x . b Reported by Stavros Passas.
2006-01-04Merge from glibc.Jim Meyering
(fts_open): Avoid function call in MAX macro use.
2005-12-27(diropen): Don't bother trying to open directory for write access:Paul Eggert
POSIX says that must fail.
2005-08-12(fts_cross_check) [FTS_DEBUG]: s/active_dir_ht/fts_cycle.ht/.Jim Meyering
2005-07-03[! _LIBC]: Include "lstat.h" rather than rolling our own.Paul Eggert
2005-07-03(fd_safer): Remove decl.Paul Eggert
Include fcntl--.h rather than unistd-safer.h (fts_safe_changedir): Don't call fd_safer; no longer needed now that we include fcntl--.h.
2005-06-02Don't use "path" or "filename" to mean "file name"Paul Eggert
in comments or local variable names.
2005-05-28Don't worry about debugging on pre-C99-comopatible hosts;Paul Eggert
the configuration hassle isn't worth it. Include inttypes.h and stdint.h unconditionally if FTS_DEBUG. (LONGEST_MODIFIER, PRIuMAX): Remove.
2005-05-22(fd_safer) [_LGPL_PACKAGE]: New static function,Paul Eggert
so that unistd-safer.h (GPL'ed code) need not be included.
2005-05-20Don't include "cycle-check.h" or "hash.h".Paul Eggert
(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.
2005-05-20(fts_open): Remove useless but otherwise harmless malloc call.Jim Meyering
Spotted by Paul Eggert.
2005-05-18Include fts_.h first, to check interface.Paul Eggert
Do not include intprops.h; no longer needed. Include cycle-check.h and hash.h, since fts_.h no longer does. Remove unnecessary casts of closedir to void. (fts_build): Use a simpler method (not involving TYPE_SIGNED) to decide whether to decrement nlinks.
2005-05-14tweak cpp indentation on one lineJim Meyering
2005-05-14Update FSF postal mail address.Jim Meyering
2005-05-09(fts_sort): Optimize the common case where all pointers smell the same.Paul Eggert
2005-05-09(__P): Remove. All uses rewritten to assume C89 or better.Paul Eggert
(fts_open): Don't cast a function value in a possibly-unsafe way. (fts_compar): New function. (fts_sort): Use it.
2005-04-11Include unistd-safer.h.Paul Eggert
(fts_safe_changedir): Use fd_safer.
2005-04-09(__attribute__, ATTRIBUTE_UNUSED): Define.Jim Meyering
Mark parameter `sp' with ATTRIBUTE_UNUSED.
2005-03-09* lib/fts.c: Include intprops.h.Paul Eggert
(TYPE_SIGNED): Remove.
2004-10-13(fts_read): When about to fail (by returning NULL) dueJim Meyering
to a failed fchdir or failed fts_safe_changedir call, set `sp->fts_cur = p'. Do this by removing the explicit `return NULL;' statements and setting p->fts_errno so execution falls through to the common-case code below. Otherwise, after such a failure, calling fts_close would attempt to free an already-freed buffer. Reported by Luis Lopez Lopez in http://bugs.debian.org/276352.
2004-09-02(fts_stat, fts_open, fts_read): Use "unsigned short int"Paul Eggert
rather than the unportable "u_short", and similarly for u_int.
2004-08-11(O_DIRECTORY): Define to 0 if the system doesn't define.Paul Eggert
2004-08-09(diropen): New function.Paul Eggert
(fts_open, fts_read, fts_children, fts_safe_changedir): Use it, so that the code works even if the directory is writeable but not readable.
2004-08-04(LONGEST_MODIFIER): New macro.Paul Eggert
(PRIuMAX) [!PRI_MACROS_BROKEN && !defined PRIuMAX]: New macro. (find_matching_ancestor): Use it for dev_t and ino_t.
2004-08-02Add an FSF copyright notice, since our changes are becoming nontrivial.Paul Eggert
Include stdint.h if available, as Autoconf suggests. (ALIGNBYTES, ALIGN): Remove; no longer needed now that fts_statp is an array. (fts_alloc, fts_palloc, fts_sort, fts_load, fts_build): Use size_t for sizes. (fts_stat, fts_safe_changedir, fts_debug, fts_read, fts_build, fts_palloc): Use bool when appropriate. (SIZE_MAX, TYPE_SIGNED): New macros. (fts_read): Use u_short for instructions. (fts_build): Use ptrdiff_t for levels. Don't assume file name lengths fit into int. Don't assume nlink_t is signed. (find_matching_ancestor): Don't assume dev, ino fit in int. (fts_stat): Use function prototype; required for bool arg. (fts_sort): Detect integer overflow in size calculations. (fts_alloc): Simplify allocation code, now that fts_statp is an array and not a pointer.
2004-06-08(fts_stat, fts_alloc): Always allocate and use a structJim Meyering
stat, even if the user isn't interested in the results. This prevents a core dump in cycle_check when FTS_NOSTAT is set.
2004-03-29Include dirfd.h, for dirfd.Jim Meyering
2003-12-20[!_LIBC]: Undefine, then define-away __P.Jim Meyering
2003-12-20[!_LIBC]: Define __P.Jim Meyering
2003-12-19Don't include <search.h>.Jim Meyering
[HAVE_INTTYPES_H]: Include <inttypes.h>. (tdestroy, tfind, tsearch): Remove definitions. (struct Active_dir): Rename from `known_object'. (AD_compare, AD_hash): New functions. (enter_dir, leave_dir): Rewrite to manipulate a hash table rather than a tree. (fts_open): Initialize hash table or cycle_state buffer. (free_node): Remove function. (find_matching_ancestor): Renamed/rewritten from look_up_active_dir. (fts_cross_check): Adapt to use new data structure.
2003-12-18Rewrite cycle detection code to work properly.Jim Meyering
Add some framework (compiled out by default) to test it. (Dprintf, ENTER_DIR, LEAVE_DIR): Define. (add_object): Remove function. Rewritten as... (enter_dir): New function. (leave_dir, free_node): New functions. (fts_read): Ensure that we call ENTER_DIR or LEAVE_DIR, as appropriate, before returning. (look_up_active_dir, fts_cross_check) [FTS_DEBUG]: New functions. (fts_stat): Don't perform the cycle check here. Now it's done via enter_dir.
2003-10-02Don't require that the maximum length of a file nameJim Meyering
encountered in a traversal fit in an `unsigned short', and fix some portability bugs (don't depend on gcc). Include "fts_.h", not <fts.h>. (ALIGNBYTES) [!(__GNUC__ >= 2)]: Add a definition that works with compilers that don't have __alignof__. (MAX): Use a definition that doesn't depend on gcc. (fts_build): Make `len' and `maxlen' be of type size_t, not int. Test for overflow in a less type-dependent manner. Test HAVE_STRUCT_DIRENT_D_TYPE, rather than defined DT_DIR && defined _DIRENT_HAVE_D_TYPE. (fts_palloc): Test for overflow in a less type-dependent manner. (fts_safe_changedir): Use stat, not stat64. Use fstat, not __fxstat64(_STAT_VER.
2003-04-15Remove (or replace-with-TAB(s) to retain alignment)Jim Meyering
each sequence of spaces before a TAB character.
2003-02-28(fts_children): If opening `.' fails, set the fts_childJim Meyering
member to NULL before returning. From NetBSD.
2003-02-28(fts_children): If fchdir fails, close file descriptorJim Meyering
before returning. From NetBSD.
2003-02-24Include <search.h>.Jim Meyering
(struct known_object): Define. (object_compare, add_object, find_object): New functions, like those in ftw.c. (fts_open): Initialize new member. (fts_close): Free memory allocated for new member. (fts_stat): Detect a cycle in O(logN) time per directory processed.