summaryrefslogtreecommitdiff
path: root/lib/fts.c
Commit message (Collapse)AuthorAgeFilesLines
* gnulib-common.m4: Use C2x [[maybe_unused]] when possible.Bruno Haible2021-08-221-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * m4/gnulib-common.m4 (gl_COMMON_BODY): Define _GL_UNUSED as an alias of _GL_ATTRIBUTE_MAYBE_UNUSED, not of _GL_ATTRIBUTE_UNUSED. * lib/binary-io.h (__gl_setmode): Put _GL_UNUSED before, not after, the declaration. * lib/c-stack.c (null_action, segv_handler, overflow_handler, c_stack_action): Likewise. * lib/chown.c (chown): Likewise. * lib/clean-temp-simple.c (cleanup_action): Likewise. * lib/fts.c (dirent_inode_sort_may_be_useful, leaf_optimization, fts_set): Likewise. * lib/getgroups.c (getgroups): Likewise. * lib/getopt.c (_getopt_initialize): Likewise. * lib/getugroups.c (getugroups): Likewise. * lib/localename.c (gl_locale_name_thread_unsafe, gl_locale_name_thread, gl_locale_name_posix, gl_locale_name_environ): Likewise. * lib/mkdir.c (rpl_mkdir): Likewise. * lib/mkfifo.c (mkfifo): Likewise. * lib/mkfifoat.c (mkfifoat): Likewise. * lib/mknod.c (mknod): Likewise. * lib/mknodat.c (mknodat): Likewise. * lib/mountlist.c (me_remote): Likewise. * lib/openpty.c (openpty): Likewise. * lib/parse-datetime.y (yyerror): Likewise. * lib/passfd.c (sendfd, recvfd): Likewise. * lib/pthread-cond.c (pthread_condattr_destroy, pthread_cond_init, pthread_cond_wait, pthread_cond_timedwait, pthread_cond_signal, pthread_cond_broadcast, pthread_cond_destroy): Likewise. * lib/pthread-mutex.c (pthread_mutexattr_destroy, pthread_mutex_init, pthread_mutex_lock, pthread_mutex_trylock, pthread_mutex_timedlock, pthread_mutex_unlock, pthread_mutex_destroy): Likewise. * lib/pthread-rwlock.c (pthread_rwlockattr_destroy, pthread_rwlock_init, pthread_rwlock_timedrdlock, pthread_rwlock_timedwrlock): Likewise. * lib/pthread-spin.c (pthread_spin_init, pthread_spin_lock, pthread_spin_trylock, pthread_spin_unlock, pthread_spin_destroy): Likewise. * lib/pthread-thread.c (pthread_attr_destroy): Likewise. * lib/readlink.c (readlink): Likewise. * lib/rename.c (rpl_rename): Likewise. * lib/set-permissions.c (set_permissions): Likewise. * lib/sockets.c (gl_sockets_startup): Likewise. * lib/stat-time.h (get_stat_birthtime_ns, get_stat_birthtime, stat_time_normalize): Likewise. * lib/strptime.c (__strptime_internal): Likewise. * lib/strtod.c (LDEXP): Likewise. * lib/symlink.c (symlink): Likewise. * lib/symlinkat.c (symlinkat): Likewise. * lib/tempname.c (try_dir, try_nocreate): Likewise. * lib/textstyle.in.h (styled_ostream_begin_use_class, styled_ostream_end_use_class, styled_ostream_get_hyperlink_ref, styled_ostream_get_hyperlink_id, styled_ostream_set_hyperlink, styled_ostream_flush_to_current_style, fd_ostream_create, term_ostream_get_color, term_ostream_set_color, term_ostream_get_bgcolor, term_ostream_set_bgcolor, term_ostream_get_weight, term_ostream_set_weight, term_ostream_get_posture, term_ostream_set_posture, term_ostream_get_underline, term_ostream_set_underline, term_ostream_get_hyperlink_ref, term_ostream_get_hyperlink_id, term_ostream_set_hyperlink, term_ostream_create, term_styled_ostream_create, html_styled_ostream_create, handle_color_option, handle_style_option, style_file_prepare, styled_ostream_create, libtextstyle_set_failure_exit_code): Likewise. * lib/unicodeio.c (exit_failure_callback, fallback_failure_callback): Likewise. * lib/wait-process.c (cleanup_slaves_action): Likewise. * tests/signature.h (SIGNATURE_CHECK2): Likewise. * tests/test-areadlink.c (do_areadlink): Likewise. * tests/test-areadlinkat.c (do_areadlinkat): Likewise. * tests/test-ceilf-ieee.c (main): Likewise. * tests/test-ceilf1.c (main): Likewise. * tests/test-dirent.c (dir): Likewise. * tests/test-fchownat.c (main): Likewise. * tests/test-fdopendir.c (main): Likewise. * tests/test-filenamecat.c (main): Likewise. * tests/test-floor1.c (main): Likewise. * tests/test-floorf-ieee.c (main): Likewise. * tests/test-floorf1.c (main): Likewise. * tests/test-fseeko.c (main): Likewise. * tests/test-fstatat.c (main): Likewise. * tests/test-ftello.c (main): Likewise. * tests/test-getdomainname.c (main): Likewise. * tests/test-getgroups.c (main): Likewise. * tests/test-gethostname.c (main): Likewise. * tests/test-math-c++.cc (OVERLOADED_CHECK): Likewise. * tests/test-mkdirat.c (main): Likewise. * tests/test-openat.c (main): Likewise. * tests/test-parse-datetime.c (main): Likewise. * tests/test-quotearg-simple.c (main): Likewise. * tests/test-quotearg.c (main): Likewise. * tests/test-sethostname2.c (main): Likewise. * tests/test-unlinkat.c (main): Likewise. * tests/test-version-etc.c (main): Likewise. * tests/test-xalloc-die.c (main): Likewise. * tests/test-xfprintf-posix.c (main): Likewise. * tests/test-xprintf-posix.c (main): Likewise. * tests/test-xvasprintf.c (main): Likewise.
* fnmatch, regex, fts: FALLTHROUGH consistencyPaul Eggert2021-01-191-2/+2
| | | | | | | | | | | | | | Be more consistent about how FALLTHROUGH is defined. For Gnulib, use attribute.h. For glibc, use __GNUC__ >= 7. Problem for glibc reported by Vaseeharan Vinayagamoorthy in: https://sourceware.org/pipermail/libc-alpha/2021-January/121778.html * lib/fnmatch.c (FALLTHROUGH) [_LIBC]: * lib/regex_internal.h (FALLTHROUGH) [_LIBC]: Don’t worry about Clang, as it’s not needed and provokes GCC. * lib/fts.c (FALLTHROUGH) [!_LIBC]: * lib/regex_internal.h (FALLTHROUGH) [!_LIBC]: Rely on attribute.h for FALLTHROUGH * modules/regex: Depend on attribute module.
* maint: run 'make update-copyright'Paul Eggert2020-12-311-1/+1
|
* Silence warnings from clang 10 with -Wimplicit-fallthrough.Bruno Haible2020-08-091-3/+3
| | | | | | | | | | * lib/dfa.c (FALLTHROUGH): Use __attribute__ __fallthrough__ also on clang >= 10. * lib/fnmatch.c (FALLTHROUGH): Likewise. * lib/fts.c (FALLTHROUGH): Likewise. * tests/macros.h (FALLTHROUGH): Likewise. * lib/regex_internal.h (FALLTHROUGH): Likewise. * config/srclist.txt: Mark it as needing sync with glibc.
* Optimize three-valued comparison between integers.Bruno Haible2020-07-241-2/+1
| | | | | | | | | | | | | | | | | | | (a > b ? 1 : a < b ? -1 : 0) is the same as (a > b) - (a < b). * m4/gnulib-common.m4 (gl_COMMON): Define _GL_CMP. * lib/c-strcasecmp.c (c_strcasecmp): Use _GL_CMP. * lib/c-strncasecmp.c (c_strncasecmp): Likewise. * lib/dfa.c (compare): Likewise. * lib/fts.c (fts_compare_ino): Likewise. * lib/mbmemcasecmp.c (mbmemcasecmp): Likewise. * lib/mbscasecmp.c (mbscasecmp): Likewise. * lib/mbsncasecmp.c (mbsncasecmp): Likewise. * lib/memcasecmp.c (memcasecmp): Likewise. * lib/memcmp2.c (memcmp2): Likewise. * lib/savedir.c (direntry_cmp_inode): Likewise. * lib/strcasecmp.c (strcasecmp): Likewise. * lib/strncasecmp.c (strncasecmp): Likewise. * lib/unistr/u-cmp2.h (FUNC): Likewise.
* fts: Make more robust in multithreaded applications.Bruno Haible2020-05-281-1/+1
| | | | | * lib/fts.c (fts_open): Pass an O_CLOEXEC flag to open(). * modules/fts (Depends-on): Add 'open'.
* attribute: new modulePaul Eggert2020-05-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This simplifies use of GCC and C2X attributes like ‘deprecated’. * MODULES.html.sh: Add attribute. * doc/attribute.texi, lib/attribute.h, modules/attribute: New files. * doc/gnulib.texi (Particular Modules): Add Attributes. * lib/backupfile.c, lib/fnmatch.c, lib/freopen-safer.c: * lib/mbrtoc32.c, lib/mbrtowc.c, lib/nstrftime.c, lib/quotearg.c: * lib/savewd.c, lib/unistr/u8-uctomb-aux.c, lib/unistr/u8-uctomb.c: * lib/vasnprintf.c: Include attribute.h, and let it define FALLTHROUGH. * lib/bitset/base.h, lib/c-stack.c (__attribute__): Remove macro. * lib/bitset/base.h (ATTRIBUTE_UNUSED): Define in terms of _GL_ATTRIBUTE_MAYBE_UNUSED, for forwards compatibility to C2X. * lib/dfa.c (FALLTHROUGH): Define consistently with gl_COMMON_BODY. This is a copy since Gawk doesn’t use Gnulib. * lib/di-set.h (_GL_ATTRIBUTE_NONNULL): Remove definition that is incompatible with gl_COMMON_BODY’s. All uses changed. * lib/fts.c: Include attribte.h, for FALLTHROUGH. Keep the existing FALLTHROUGH definition since Glibc might use it, and it does no harm to Gnulib’s FALLTHROUGH. * lib/fts_.h, lib/inttostr.h: (__GNUC_PREREQ): Remove; no longer needed. (__attribute_warn_unused_result__): Remove. All uses replaced by _GL_ATTRIBUTE_NODISCARD. * lib/gl_list.h, lib/gl_map.h, lib/gl_omap.h, lib/gl_oset.h: * lib/gl_set.h: Prefer _GL_ATTRIBUTE_NODISCARD to an ifdeffed __attribute__ ((__warn_unused_result__)), for forward compatibility to C2X. * lib/hash.h (_GL_ATTRIBUTE_WUR): Remove. All uses replaced by _GL_ATTRIBUTE_NODISCARD. (_GL_ATTRIBUTE_DEPRECATED): Remove, since gl_COMMON_BODY defines it. * lib/ino-map.h (_GL_ATTRIBUTE_NONNULL): Remove. All uses replaced by gl_COMMON_BODY’s implementation, which has a slightly different signature. * lib/safe-alloc.h (_GL_ATTRIBUTE_RETURN_CHECK): Remove. All uses replaced by _GL_ATTRIBUTE_NODISCARD. * lib/unused-parameter.h (_GL_UNUSED_PARAMETER): Define in terms of _GL_ATTRIBUTE_MAYBE_UNUSED. No doubt all uses should be replaced, at some point. * m4/gnulib-common.m4 (_GL_GNUC_PREREQ): New macro. (_Noreturn): Use it. (_GL_HAS_ATTRIBUTE, _GL_ATTRIBUTE_ALLOC_SIZE) (_GL_ATTRIBUTE_ALWAYS_INLINE, _GL_ATTRIBUTE_ARTIFICIAL) (_GL_ATTRIBUTE_COLD) (_GL_ATTRIBUTE_DEPRECATED, _GL_ATTRIBUTE_ERROR) (_GL_ATTRIBUTE_WARNING, _GL_ATTRIBUTE_EXTERNALLY_VISIBLE) (_GL_ATTRIBUTE_FALLTHROUGH, _GL_ATTRIBUTE_FORMAT) (_GL_ATTRIBUTE_LEAF, _GL_ATTRIBUTE_MAY_ALIAS) (_GL_ATTRIBUTE_MAYBE_UNUSED) (_GL_ATTRIBUTE_NODISCARD, _GL_ATTRIBUTE_NOINLINE) (_GL_ATTRIBUTE_NONNULL, _GL_ATTRIBUTE_NONSTRING) (_GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PACKED, _GL_ATTRIBUTE_PURE) (_GL_ATTRIBUTE_SENTINEL): New macros. * modules/backup-rename, modules/backupfile, modules/c-vasnprintf: * modules/fnmatch, modules/freopen-safer, modules/fts: * modules/mbrtoc32, modules/mbrtowc, modules/nstrftime: * modules/quotearg, modules/savewd: * modules/unistdio/u16-u16-vasnprintf: * modules/unistdio/u16-vasnprintf: * modules/unistdio/u32-u32-vasnprintf: * modules/unistdio/u32-vasnprintf: * modules/unistdio/u8-u8-vasnprintf: * modules/unistdio/u8-vasnprintf: * modules/unistdio/ulc-vasnprintf: * modules/unistr/u8-uctomb, modules/vasnprintf: (Depends-on:): Add attribute module.
* Tune fts for FTS_LOGICAL+FTS_NOSTATPaul Eggert2020-04-251-3/+4
| | | | | | | | | From a suggestion by Askar Safin in: https://lists.gnu.org/r/bug-gnulib/2020-04/msg00074.html * lib/fts.c (fts_build): If file types are known, optimize FTS_LOGICAL+FTS_NOSTAT for non-symlinks and non-directories the same way that we already optimize FTS_PHYSICAL+FTS_NOSTAT for non-directories.
* fts: remove NOSTAT_LEAF_OPTIMIZATIONPaul Eggert2020-04-151-48/+8
| | | | | | | | | | | | | | | | It caused ‘find’ and ‘du’ to dump core, and it was useful only for obsolescent Linux filesystems anyway. Problem reported in: https://lists.gnu.org/r/bug-gnulib/2020-04/msg00068.html Quite possibly there is still a serious underlying fts bug with tight-loop-check and mutating file systems, but if so this patch should cause the bug to be triggered less often. * lib/fts.c (enum leaf_optimization): Remove NOSTAT_LEAF_OPTIMIZATION, as it’s problematic. (S_MAGIC_REISERFS, S_MAGIC_XFS): Remove; no longer needed. (leaf_optimization): Remove special cases for ReiserFS and XFS. (fts_read): Remove NOSTAT_LEAF_OPTIMIZATION code. * lib/fts_.h (struct _ftsent.fts_n_dirs_remaining): Remove. All uses removed.
* maint: Run 'make update-copyright'Paul Eggert2019-12-311-1/+1
|
* fts: tune via callocPaul Eggert2019-12-171-2/+2
| | | | * lib/fts.c (fts_open): Prefer calloc to malloc + memset.
* fts: minor simplificationPaul Eggert2019-03-171-1/+0
| | | | * lib/fts.c (fts_safe_changedir): Remove redundant assignment.
* fts: Optimize on Android.Bruno Haible2019-01-271-1/+1
| | | | * lib/fts.c: Treat Android like Linux.
* maint: Run 'make update-copyright'Paul Eggert2019-01-011-1/+1
|
* backupfile: new dir_fd argsPaul Eggert2018-10-231-25/+1
| | | | | | | | | | | | | | | | | | | | | | New module opendirat with code taken from fts. Use this module to let backupfile use a directory file descriptor. * NEWS: Document the incompatible change. * lib/backup-find.c (find_backup_file_name): * lib/backup-rename.c (backup_file_rename): New arg DIR_FD. * lib/backupfile.c: Include stdint.h, for SIZE_MAX. (SIZE_MAX): Remove. Include opendirat.h rather than dirent--.h. (check_extension): New args DIR_FD and BASE_MAX. All callers changed. (numbered_backup): New args DIR_FD and PNEW_FD. All callers changed. (backupfile_internal): New arg DIR_FD. All callers changed. * lib/fts.c: Include opendirat.h. (opendirat): Move to opendirat.c. * lib/opendirat.c, lib/opendirat.h, modules/opendirat: New files. * modules/backupfile (Depends-on): Remove dirfd, opendir. Add opendirat. * modules/fts (Depends-on): Remove fdopendir, openat-safer. Add opendirat.
* fts: remove FTS_NOATIMEBernhard Voelker2018-10-081-7/+4
| | | | | | | | | | | | | This reverts commit da4d6974013c822af1498941e32db774b2031765. We cannot guarantee that O_NOATIME works: e.g. openat fails with EPERM if the effective user ID of the caller does not match the owner of the file and the caller is not privileged. Downstream findutils has never picked up FTS_NOATIME. Discussed at <https://lists.gnu.org/r/bug-gnulib/2018-09/msg00122.html>. * lib/fts_.h (FTS_NOATIME): Remove bit flag. (FTS_OPTIONMASK): Adjust. * lib/fts.c (diropen, fts_open, fts_build): Likewise. (fd_ring_check): Likewise.
* fts: avoid a memory leak edge casePádraig Brady2018-05-201-0/+1
| | | | | | | | * lib/fts.c (fts_open): Set an appropriate fts_level so that an immediate fts_close() will free the allocation. * tests/test-fts.c (fts_dealloc): Add a test case which will trigger under valgrind or address sanitizer. Fixes https://bugs.gnu.org/31439
* fts: add commentPaul Eggert2018-04-111-1/+5
| | | | | | * lib/fts.c (fts_build): Explain why ==, not >. See remark by Bernhard Voelker in: https://lists.gnu.org/r/bug-gnulib/2018-04/msg00041.html
* fts: fix bug in find across filesystemsPaul Eggert2018-04-111-24/+31
| | | | | | | | | | | This fixes a bug I introduced last summer. Problem reported by Kamil Dudka in: https://lists.gnu.org/r/bug-gnulib/2018-04/msg00033.html * lib/fts.c (filesystem_type, dirent_inode_sort_may_be_useful) (leaf_optimization): New arg for file descriptor. All callers changed. (fts_build): Check for whether inodes should be sorted before closing the directory.
* fts: treat CIFS like NFSPaul Eggert2018-04-051-1/+7
| | | | | | | | Problem reported by Kamil Dudka in: https://lists.gnu.org/r/bug-gnulib/2018-04/msg00015.html * lib/fts.c (S_MAGIC_CIFS): New macro. (dirent_inode_sort_may_be_useful, leaf_optimization): Treat CIFS like NFS.
* maint: Run 'make update-copyright'Paul Eggert2018-01-011-1/+1
|
* all: Replace many more http URLs by https URLs. Update stale URLs.Bruno Haible2017-09-141-2/+2
| | | | | * users.txt: Remove mention of 'newts'. * lib/localename.c: Update comment about LANG_SOTHO.
* all: prefer https: URLsPaul Eggert2017-09-131-1/+1
|
* * lib/fts.c: Fix XFS comments.Paul Eggert2017-09-081-3/+3
|
* fts: fix cloexec racesPaul Eggert2017-08-121-19/+8
| | | | | | | | | | | * lib/fts.c [!_LIBC]: Do not include dirent--.h, unistd--.h, cloexec.h. (opendirat, diropen): Use O_CLOEXEC instead of set_cloexec_flag. (fts_build): Use F_DUPD_CLOEXEC rinstad of set_cloexec_flag. (fd_ring_check): Set cloexec flag on new file descriptors. (fts_build, fd_ring_check): While we’re at it, make sure the resulting file descriptor is not 0, 1, or 2, since that is easy. * modules/fts (Depends-on): Remove cloexec, dirent-safer, dup, fcntl-safer, unistd-safer. Add fcntl.
* fts: port recent changes to CentOS 6Paul Eggert2017-08-101-2/+8
| | | | | | | | | Problem reported by Tom G. Christensen in: http://lists.gnu.org/archive/html/bug-gnulib/2017-08/msg00064.html * lib/fts.c (fsword): New type. (struct dev_type, filesystem_type): Use it. * m4/fts.m4 (gl_FUNC_FTS_CORE): Check for __fsword_t. Also, check for f_type only if fstatfs and sys/vfs.h work.
* Don't interpret EOVERFLOW to mean nonexistencePaul Eggert2017-07-301-3/+1
| | | | | | | | | | | | | * lib/fts.c (fts_stat): If lstat fails, report its errno, which may be EOVERFLOW; this is likely more useful than reporting the stat errno. * lib/glob.c (link_stat): Rename from link_exists2_p and return -1/0 instead of 0/1. Caller changed. * lib/glob.c (link_exists_p): * lib/renameat2.c (rename_noreplace, renameat2): * lib/tempname.c (try_nocreate): If errno == EOVERFLOW then the directory entry exists, so do not act as if it does not exist.
* fts: simplify fts_buildPaul Eggert2017-07-251-25/+15
| | | | | * lib/fts.c (fts_build): Simplify, and be lazier about calling leaf_optimization.
* fts: three levels of leaf optimizationPaul Eggert2017-07-251-17/+37
| | | | | | | | | * lib/fts.c (enum leaf_optimization): New type with three values. (S_MAGIC_AFS): New macro. Sort them. (leaf_optimization): Rename from leaf_optimization_applies, and return enum leaf_optimization instead of bool. All uses changed. Add cases for unknown type and for AFS. (fts_build): Don’t rely on link counts if NO_LEAF_OPTIMIZATION.
* fts: cache dirent_inode_sort_may_be_useful tooPaul Eggert2017-07-251-106/+96
| | | | | | | | | | | * lib/fts.c (struct dev_type): New struct. (DEV_TYPE_HT_INITIAL_SIZE): New constant. (dev_type_hash, dev_type_compare, filesystem_type): New functions. (dirent_inode_sort_may_be_useful, leaf_optimization_applies): Now takes FTSENT const *, not int. All uses changed. Use filesystem_type to cache. (link_count_optimize_ok): Remove. Caller changed to use leaf_optimization_applies, which now uses shared cache.
* fts: introduce MIN_DIR_NLINKPaul Eggert2017-07-251-5/+14
| | | | | * lib/fts.c (MIN_DIR_NLINK): New constant. Use it instead of 2, whenever we are talking about link counts.
* fts: nlink_t signedness fixupsPaul Eggert2017-07-251-17/+9
| | | | | | | | | | * lib/fts.c (fts_open): Set rootparent n_dirs_remaining to -1 so that root need not be a special case later. (fts_read): Remove now-redundant test for fts_level. Do not assume that nlink_t is signed. (fts_build): Remove useless decrement of nlinks. (fts_stat): Avoid unlikely signed integer overflow later, if nlink_t is signed.
* fallthrough: update for GCC 7/8Jim Meyering2017-05-191-2/+10
| | | | | | | | | | | | | | | | * lib/quotearg.c (FALLTHROUGH): New macro. Use it whenever one switch case falls through into the next, replacing "/* Fall through */" comments. This exposed one instance of an unwarranted "fall through" comment: unwarranted because it preceded a "goto" label not a case statement. * lib/freopen-safer.c (freopen_safer): Likewise. * lib/fts.c (leaf_optimization_applies): Likewise. * lib/unistr/u8-uctomb-aux.c (u8_uctomb_aux): Likewise. * tests/test-getopt_long.h (getopt_long_loop): Likewise. * tests/test-tsearch.c (mangle_tree): Likewise. Also include tests/macros.h for the definition. * tests/test-argp.c (group1_parser): Likewise. * tests/test-getopt.h (getopt_loop): Likewise.
* version-etc: new yearPaul Eggert2017-01-011-1/+1
| | | | | | | | | | * build-aux/gendocs.sh (version): * doc/gendocs_template: * doc/gendocs_template_min: * doc/gnulib.texi: * lib/version-etc.c (COPYRIGHT_YEAR): Update copyright dates by hand in templates and the like. * all files: Run 'make update-copyright'.
* flexmember: port better to GCC + valgrindPaul Eggert2016-09-071-11/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With a char[] flexible array member in a struct with nontrivial alignment, GCC-generated code can access past the end of the array, because GCC assumes there are padding bytes to get the struct aligned. So the common idiom of malloc (offsetof (struct s, m), n) does not properly allocate an n-byte trailing member, as malloc’s argument should be the next multiple of alignof (struct s). See GCC Bug#66661: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66661 Although C11 apparently permits this GCC optimization (i.e., there was a bug in Gnulib not in GCC), possibly this is a defect in C11. See the thread containing: https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00317.html * lib/flexmember.h: New file. * lib/fnmatch.c, lib/fts.c, lib/glob.c, lib/idcache.c: * lib/localename.c, lib/time_rz.c: Include flexmember.h. * lib/fnmatch_loop.c (struct patternlist): * lib/localename.c (struct hash_node): Use FLEXIBLE_ARRAY_MEMBER. * lib/fnmatch_loop.c (EXT): * lib/fts.c (fts_alloc): * lib/glob.c (glob_in_dir): * lib/idcache.c (getuser, getuidbyname, getgroup, getgidbyname): * lib/localename.c (gl_lock_define_initialized): * lib/time_rz.c (tzalloc): Use FLEXSIZEOF instead of offsetof. * m4/flexmember.m4 (AC_C_FLEXIBLE_ARRAY_MEMBER): Check that the size of the struct can be taken. * modules/flexmember (Files): Add lib/flexmember.h. * modules/fnmatch, modules/glob, modules/localename (Depends-on): Add flexmember.
* fts: handle readdir() errorsPádraig Brady2016-06-261-2/+12
| | | | | | | | | | | | | * lib/fts.c (fts_build): readdir(3) returns NULL when finished, but also upon error when it will also set errno. Therefore flag the error case from readdir(). We treat the case where no items are read the same as if the dir can't be accessed, i.e. by setting fts_errno to FTS_DNR. The bug was initially reported by Peter Benie http://bugzilla.opensuse.org/show_bug.cgi?id=984910 where it was mentioned that readdir() may fail when an NFS server has a poor readdir cookie implementation.
* Use GCC_LINT, not lintPaul Eggert2016-05-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | FreeBSD and Cygwin #define _Noreturn to empty if 'lint' is defined. Problem reported by Ken Brown in: http://bugs.gnu.org/23640 * doc/posix-headers/stdnoreturn.texi (stdnoreturn.h): Document problem with lint and _Noreturn. * lib/diffseq.h (IF_LINT, IF_LINT2): * lib/fts.c (sccsid): * lib/getndelim2.c (IF_LINT): * lib/gl_anylinked_list2.h (gl_linked_iterator) (gl_linked_iterator_from_to): * lib/gl_anytree_list2.h (gl_tree_iterator) (gl_tree_iterator_from_to): * lib/gl_anytree_oset.h (gl_tree_iterator): * lib/gl_array_list.c (gl_array_iterator) (gl_array_iterator_from_to): * lib/gl_array_oset.c (gl_array_iterator): * lib/gl_carray_list.c (gl_carray_iterator) (gl_carray_iterator_from_to): * lib/idcache.c: * lib/inet_ntop.c (IF_LINT): * lib/regcomp.c (build_charclass_op, create_tree): * lib/regex_internal.c (re_acquire_state) (re_acquire_state_context): * lib/trigl.c (rcsid): * lib/trim.c (IF_LINT): * lib/vasnprintf.c (IF_LINT): * lib/verify.h (assume): Treat GCC_LINT like lint.
* fts: don't unconditionally use leaf optimization for NFSPádraig Brady2016-01-181-9/+10
| | | | | | | | NFS st_nlink are not accurate on all implementations, leading to aborts() if that assumption is made. See <https://bugzilla.redhat.com/1299169> * lib/fts.c (leaf_optimization_applies): Remove NFS from the white list, and document the issue.
* version-etc: new yearPaul Eggert2016-01-011-1/+1
| | | | | | | | | | * build-aux/gendocs.sh (version): * doc/gendocs_template: * doc/gendocs_template_min: * doc/gnulib.texi: * lib/version-etc.c (COPYRIGHT_YEAR): Update copyright dates by hand in templates and the like. * all files: Run 'make update-copyright'.
* fts: ensure leaf optimization is used for NFSKamil Dudka2015-12-201-0/+5
| | | | | | NFS provides usable dirent.d_type but not necessarily for all entries of large directories. See <https://bugzilla.redhat.com/1252549> * lib/fts.c (leaf_optimization_applies): Append NFS on the white list.
* fts: enable leaf optimization for XFSPádraig Brady2015-12-201-0/+2
| | | | | | | | | | | | | | | | | | | | | | XFS provides usable dirent.d_type only for DT_DIR, but the noleaf optimization still applies, as confirmed with: test $(($(find . -maxdepth 1 -type d | wc -l) + 1)) = $(stat -c %h .) Enabling this gives significant traversal speedup. Testing with find(1) gives: $ time find/find-before /usr/share >/dev/null real 0m0.410s user 0m0.145s sys 0m0.266s $ time find/find-after /usr/share >/dev/null real 0m0.278s user 0m0.147s sys 0m0.131s * lib/fts.c (leaf_optimization_applies): Add XFS to the white list.
* fts: port to C11 alignofPaul Eggert2015-10-181-3/+8
| | | | | | | | * doc/posix-headers/stdalign.texi (stdalign.h): Document the C11 restriction. * lib/fts.c: Include stddef.h, for max_align_t. (fts_alloc): Align using max_align_t, not FTSENT. * modules/fts (Depends-on): Add stddef.
* fts: avoid reading beyond the heap allocationPádraig Brady2015-06-251-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GCC 5.1.1 with -O2 and -fsanitize=address reports the following from `chmod a+rx ..` for example: ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61200000be48 READ of size 4 at 0x61200000be48 thread T0 #0 0x40f0a1 in fts_stat lib/fts.c:1821 #1 0x4141ec in fts_open lib/fts.c:514 #2 0x40ca6e in xfts_open lib/xfts.c:36 #3 0x402c35 in process_files src/chmod.c:336 #4 0x402c35 in main src/chmod.c:566 #5 0x7f8fdc38678f in __libc_start_main (/lib64/libc.so.6+0x2078f) #6 0x404608 in _start (/home/padraig/git/coreutils/src/chmod+0x404608) 0x61200000be4b is located 0 bytes to the right of 267-byte region [0x61200000bd40,0x61200000be4b) allocated by thread T0 here: #0 0x7f8fdd4cfa0a in malloc (/lib64/libasan.so.2+0x98a0a) #1 0x40f22c in fts_alloc lib/fts.c:1916 The read of size 4 from a heap object of size 3 is indeed invalid, though this may be due to incorrect padding assumptions by GCC, see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66661 The read is coming from the a[2] access in ISDOT() which GCC seems to assume can access according to the alignment of the main structure, since the flexible array members are being accessed directly. One could cast the parameter to ISDOT() to (char const*) to restrict to byte at a time access, however it seems more correct and maintainable to increase the buffer size to the appropriate alignment to avoid this issue. For reference some notes on alignment and flexible array members are at: https://sites.google.com/site/embeddedmonologue/home/c-programming/data-alignment-structure-padding-and-flexible-array-member * lib/fts.c (fts_alloc): Increase allocation to alignof(FTSENT). * modules/fts: Depend on stdalign.
* fts: port to GCC 5.1 with --enable-gcc-warningsPaul Eggert2015-04-271-1/+1
| | | | | | | | | | | Without this fix, GCC 5.1 (correctly) warns about a subscript error on the fts_name component of FTSENT. It's actually a flexible member, so define it that way on C99 or later hosts. * lib/fts.c (fts_alloc): Use offsetof, not sizeof, for a structure that now has a flexible array member. * lib/fts_.h (__FLEXIBLE_ARRAY_MEMBER): New macro. (FTSENT): fts_name is now flexible on C99-or-later platforms. * modules/fts (Depends-on): Add flexmember.
* fts: remove redundant close() (trivial)Jaroslav Skarvada2015-02-201-3/+0
| | | | | * lib/fts.c (fts_read): Remove redundant call to close(). Spotted by coverity.
* fts: avoid crash when a cycle is added while traversingKamil Dudka2015-02-171-3/+9
| | | | | | | | This could be triggered by auto-mounting a recursive bind mount. Reported by Michael Chapman in: https://bugzilla.redhat.com/1188498 * lib/fts.c (fts_read): Avoid removing the original hash table item when leaving a directory that caused a cycle, and preserve the FTS_DC flag.
* version-etc: new yearPaul Eggert2014-12-311-1/+1
| | | | | | * doc/gnulib.texi: * lib/version-etc.c (COPYRIGHT_YEAR): Update copyright date. * all files: Run 'make update-copyright'.
* assure: new modulePaul Eggert2014-12-201-1/+1
| | | | | | | | | | | | | | | This works better than 'assert' when compiling with -DNDEBUG, as it avoids some compiler diagnostics in that case. Reported by Norihiro Tanaka in: http://lists.gnu.org/archive/html/bug-gnulib/2014-12/msg00215.html * MODULES.html.sh (func_all_modules): Add 'assure'. * lib/assure.h, modules/assure: New files. * lib/chdir-long.c, lib/cycle-check.c, lib/fchdir.c, lib/fts.c: * lib/poll.c, lib/savewd.c, lib/utimens.c, lib/xstrtol.c: Prefer 'assure' to 'assert'. * modules/chdir-long, modules/cycle-check, modules/fchdir: * modules/poll, modules/savewd, modules/utimens, modules/xstrtol: Depend on 'assure'.
* fts: port to C89Paul Eggert2014-11-101-2/+2
| | | | | | Problem reported for MSVC 16 by Gisle Vanem in: http://lists.gnu.org/archive/html/bug-gnulib/2014-11/msg00027.html * lib/fts.c (fts_build): Avoid declaration before statement.
* fts: avoid unnecessary strlen callsEric Blake2014-04-091-0/+3
| | | | | | | | Not all platforms have _D_EXACT_NAMLEN. * lib/fts.c (_D_EXACT_NAMLEN): Restore definition when needed. Signed-off-by: Eric Blake <eblake@redhat.com>