summaryrefslogtreecommitdiff
path: root/lib/glob.c
Commit message (Collapse)AuthorAgeFilesLines
* glob: port to NetBSD 9.2Paul Eggert2022-04-261-1/+2
| | | | | | | | | | Problem reported by Benno Schulenberg in: https://lists.gnu.org/r/bug-gnulib/2022-04/msg00052.html * doc/posix-functions/dirfd.texi: Document NetBSD 9.2 portability bugs. Remove an old common about errno that is no longer true of POSIX 2018. * lib/glob.c (glob_in_dir): Convert dirfd arg from void * to DIR * before passing it to dirfd.
* glob: sync better with glibcPaul Eggert2022-03-301-3/+2
| | | | | * lib/glob.c (dirfd) [_LIBC]: Use #undef instead of #ifdef. Problem reported by DJ Delorie.
* glob: fix symlink and // issues; improve speedPaul Eggert2022-03-231-36/+40
| | | | | | | | | | | | | | | | * lib/glob.c: Include fcntl.h. (dirfd) [_LIBC]: New macro. (GLOB_STAT64, GLOB_LSTAT64): Remove. Replace all uses with ... (GLOB_FSTATAT64): ... this new macro. (glob_in_dir): Treat DT_LNK like DT_UNKNOWN. Use directory-relative fstatat unless GLOB_ALTDIRFUNC, or dirfd fails. Avoid duplicate strlen (directory). Work even if directory is "/", without turning it into "//". Use a scratch buffer instead of by-hand alloca stuff. Use mempcpy and memcpy instead of stpcpy and strcpy. * modules/glob (Depends-on): Add dirfd, fstatat. Remove stat. (License): Change from LGPLv2+ to GPL, since it depends on fstatat.
* glob: resolve DT_UNKNOWN via is_dirDJ Delorie2022-03-231-1/+27
| | | | | | | | | | | | | | | | | | | | | The DT_* values returned by getdents (readdir) are only hints and not required. In fact, some Linux filesystems return DT_UNKNOWN for most entries, regardless of actual type. This causes make to mis-match patterns with a trailing slash (via GLOB_ONLYDIR) (see make's functions/wildcard test case). Thus, this patch detects that case and uses is_dir() to make the type known enough for proper operation. Performance in non-DT_UNKNOWN cases is not affected. The lack of DT_* is a well known issue on older XFS installations (for example, RHEL 7 and 8, Fedora 28) but can be recreated by creating an XFS filesystem with flags that mimic older behavior: $ fallocate -l 10G /xfs.fs $ mkfs.xfs -n ftype=0 -m crc=0 -f /xfs.fs $ mkdir /xfs $ mount -o loop /xfs.fs /xfs
* maint: run 'make update-copyright'Paul Eggert2022-01-011-1/+1
|
* glob: merge from glibcPaul Eggert2021-08-061-21/+25
| | | | | | * lib/glob-libc.h, lib/glob.c: Merge changes from glibc 2.34. The result should be copyable directly into glibc. * modules/glob-h (glob-libc.gl.h): Also omit __THROWNL.
* glob: Reject ~user syntax, when flag GLOB_TILDE_CHECK is given.Bruno Haible2021-04-021-1/+18
| | | | | | | | Reported and patch suggested by Eli Zaretskii <eliz@gnu.org> in <https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00136.html>. * lib/glob.c (__glob) [WINDOWS32]: If flag GLOB_TILDE_CHECK is given, do error handling like when ~user is allowed by the user is unknown.
* glob: include libc-config.h in a more-standard wayPaul Eggert2021-02-241-1/+1
| | | | | | Inspired by Tom Tromey’s report for RHEL 6 in: https://lists.gnu.org/r/bug-gnulib/2021-02/msg00088.html * lib/glob.c [!_LIBC]: Include libc-config.h, not just config.h
* maint: run 'make update-copyright'Paul Eggert2020-12-311-1/+1
|
* glob: merge proposed glibc changesPaul Eggert2020-12-311-6/+0
| | | | | | This merges the change proposed by Adhemerval Zanella in: https://sourceware.org/pipermail/libc-alpha/2020-December/121211.html * lib/glob.c (__lstat64, __stat64) [_LIBC]: Remove.
* intprops: Avoid potentially buggy __builtin_add_overflow in GCC 5, 6.Bruno Haible2020-12-181-1/+1
| | | | | | | | | | Reported by Stefan Liebler <stli@linux.ibm.com> in <https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00152.html>. * lib/intprops.h (_GL_HAS_BUILTIN_ADD_OVERFLOW): Don't define for GCC 5.x and 6.x. * lib/glob.c (size_add_wrapv): Don't use __builtin_add_overflow for GCC 5.x and 6.x.
* Fix "warning: '__stat64' macro redefined".Bruno Haible2020-08-161-2/+2
| | | | * lib/glob.c (__stat64): Undefine also on MSVC/clang.
* glob: Fix use-after-free bug.Bruno Haible2020-01-171-2/+6
| | | | | | | | Reported by Tim Rühsen <tim.ruehsen@gmx.de> in <https://lists.gnu.org/archive/html/bug-gnulib/2020-01/msg00102.html>. * lib/glob.c (__glob): Delay freeing dirname until after the use of end_name.
* maint: Run 'make update-copyright'Paul Eggert2019-12-311-1/+1
|
* glob: Avoid warning on mingw.Bruno Haible2019-12-171-0/+4
| | | | | | | Reported by Christian Biesinger <cbiesinger@google.com> in <https://lists.gnu.org/archive/html/bug-gnulib/2019-12/msg00122.html>. * lib/glob.c (__stat64): Undefine first.
* glob: get closer to glibc glob.cPaul Eggert2019-11-181-25/+43
| | | | | | | | | | Omit differences from glibc when the differences don’t matter. * lib/glob.c [_LIBC]: Include shlib-compat.h. (__glob) [!_LIBC]: New macro. All uses of glob changed to __glob. (glob_lstat): New function. (glob_in_dir): Use it. (GLOB_ATTRIBUTE): Define to empty if not already defined. Use changed.
* maint: Run 'make update-copyright'Paul Eggert2019-01-011-1/+1
|
* glob: Fix over-optimization due to attribute __nonnull__.Bruno Haible2018-08-191-0/+6
| | | | * lib/glob.c (_GL_ARG_NONNULL): Define to empty.
* glob-h: New module.Bruno Haible2018-08-071-0/+4
| | | | | | | | | | | | | | | | | | | | | * lib/glob.in.h: Use nearly the usual gnulib idioms for header file replacements. * lib/glob.c: Include <config.h>. * m4/glob_h.m4: New file. * m4/glob.m4 (gl_GLOB): Require gl_GLOB_H. Remove code that is moved to glob_h.m4. Set HAVE_GLOB, REPLACE_GLOB, HAVE_GLOB_PATTERN_P, REPLACE_GLOB_PATTERN_P as appropriate. (gl_PREREQ_GLOB): Don't require AC_C_RESTRICT and AC_USE_SYSTEM_EXTENSIONS, now done through module 'glob-h'. * modules/glob-h: New file. * modules/glob (Files): Remove lib/glob.in.h, lib/glob-libc.h. (Dependencies): Add glob-h. Remove extensions, snippet/*, libc-config, lstat, sys_stat. Change conditions. (configure.ac): Test HAVE_GLOB, REPLACE_GLOB, HAVE_GLOB_PATTERN_P, REPLACE_GLOB_PATTERN_P. Set module indicator. (Makefile.am): Remove code that is moved to glob-h. * doc/posix-headers/glob.texi: Mention the 'glob-h' module. * modules/posixcheck (Depends-on): Add glob-h.
* glob: Choose 'dirent_type' in a way that works better on mingw.Bruno Haible2018-05-121-1/+3
| | | | | | Reported and suggested by Eli Zaretskii <eliz@gnu.org>. * lib/glob.c (dirent_type): Define as uint_fast32_t.
* Simplify code. Drop support for Borland C++ on Windows.Bruno Haible2018-05-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reported by Gisle Vanem <gisle.vanem@gmail.com>. * lib/accept4.c: Simplify 'defined _WIN32 || defined __WIN32__' to just 'defined _WIN32'. * lib/canonicalize-lgpl.c: Likewise. * lib/classpath.c: Likewise. * lib/clean-temp.c: Likewise. * lib/csharpexec.c: Likewise. * lib/ctime.c: Likewise. * lib/dosname.h: Likewise. * lib/dup2.c: Likewise. * lib/errno.in.h: Likewise. * lib/error.c: Likewise. * lib/euidaccess.c: Likewise. * lib/execute.c: Likewise. * lib/fcntl.in.h: Likewise. * lib/fcntl.c: Likewise. * lib/filename.h: Likewise. * lib/findprog.c: Likewise. * lib/flock.c: Likewise. * lib/fopen.c: Likewise. * lib/freopen.c: Likewise. * lib/fstat.c: Likewise. * lib/fsync.c: Likewise. * lib/gc-gnulib.c: Likewise. * lib/get-rusage-data.c: Likewise. * lib/getaddrinfo.c: Likewise. * lib/getdelim.c: Likewise. * lib/getdtablesize.c: Likewise. * lib/gethostname.c: Likewise. * lib/getlogin.c: Likewise. * lib/getlogin_r.c: Likewise. * lib/getopt.c: Likewise. * lib/getpagesize.c: Likewise. * lib/getpass.c: Likewise. * lib/getrusage.c: Likewise. * lib/gettimeofday.c: Likewise. * lib/glob.c: Likewise. * lib/inttypes.in.h: Likewise. * lib/isapipe.c: Likewise. * lib/javaexec.c: Likewise. * lib/link.c: Likewise. * lib/localcharset.c: Likewise. * lib/localename.h: Likewise. * lib/localename.c: Likewise. * lib/localtime.c: Likewise. * lib/lseek.c: Likewise. * lib/mbsinit.c: Likewise. * lib/mkdir.c: Likewise. * lib/msvc-nothrow.h: Likewise. * lib/nanosleep.c: Likewise. * lib/nl_langinfo.c: Likewise. * lib/nonblocking.c: Likewise. * lib/nproc.c: Likewise. * lib/open.c: Likewise. * lib/openpty.c: Likewise. * lib/pathmax.h: Likewise. * lib/pipe-filter-aux.c: Likewise. * lib/pipe-filter-gi.c: Likewise. * lib/pipe-filter-ii.c: Likewise. * lib/pipe.c: Likewise. * lib/pipe2.c: Likewise. * lib/poll.c: Likewise. * lib/popen.c: Likewise. * lib/posix_openpt.c: Likewise. * lib/printf-parse.c: Likewise. * lib/progreloc.c: Likewise. * lib/putenv.c: Likewise. * lib/read.c: Likewise. * lib/relocatable.c: Likewise. * lib/rename.c: Likewise. * lib/same-inode.h: Likewise. * lib/secure_getenv.c: Likewise. * lib/select.c: Likewise. * lib/sethostname.c: Likewise. * lib/setlocale.c: Likewise. * lib/sigaction.c: Likewise. * lib/sigprocmask.c: Likewise. * lib/sleep.c: Likewise. * lib/spawn-pipe.h: Likewise. * lib/spawn-pipe.c: Likewise. * lib/spawni.c: Likewise. * lib/stat-time.h: Likewise. * lib/stat-w32.c: Likewise. * lib/stat.c: Likewise. * lib/stdio.in.h: Likewise. * lib/stdio-impl.h: Likewise. * lib/stdio-read.c: Likewise. * lib/stdio-write.c: Likewise. * lib/stdlib.in.h: Likewise. * lib/strerror_r.c: Likewise. * lib/strftime-fixes.c: Likewise. * lib/sys_stat.in.h: Likewise. * lib/sys_types.in.h: Likewise. * lib/sys_wait.in.h : Likewise. * lib/system-quote.h: Likewise. * lib/system-quote.c: Likewise. * lib/tmpdir.c: Likewise. * lib/tzset.c: Likewise. * lib/uname.c: Likewise. * lib/unistd.in.h: Likewise. * lib/utime.in.h: Likewise. * lib/utime.c: Likewise. * lib/utimecmp.c: Likewise. * lib/utimens.c: Likewise. * lib/vasnprintf.c: Likewise. * lib/vma-iter.h: Likewise. * lib/vma-iter.c: Likewise. * lib/wait-process.c: Likewise. * lib/wcsftime.c: Likewise. * lib/wctype.in.h: Likewise. * lib/write.c: Likewise. * tests/nap.h: Likewise. * tests/test-cloexec.c: Likewise. * tests/test-dup-safer.c: Likewise. * tests/test-dup2.c: Likewise. * tests/test-dup3.c: Likewise. * tests/test-fcntl.c: Likewise. * tests/test-get-rusage-data.c: Likewise. * tests/test-getaddrinfo.c: Likewise. * tests/test-getlogin.h: Likewise. * tests/test-isatty.c: Likewise. * tests/test-localename.c: Likewise. * tests/test-mbrtowc-w32.c: Likewise. * tests/test-nonblocking.c: Likewise. * tests/test-nonblocking-pipe-main.c: Likewise. * tests/test-nonblocking-socket-main.c: Likewise. * tests/test-nonblocking-socket.h: Likewise. * tests/test-pipe.c: Likewise. * tests/test-pipe2.c: Likewise. * tests/test-poll.c: Likewise. * tests/test-pthread_sigmask1.c: Likewise. * tests/test-select.h: Likewise. * tests/test-sethostname2.c: Likewise. * tests/test-sigprocmask.c: Likewise. * tests/test-spawn-pipe-child.c: Likewise. * tests/test-stat-time.c: Likewise. * tests/test-system-quote-main.c: Likewise. * tests/test-utimens-common.h: Likewise. * tests/test-wcrtomb-w32.c: Likewise. * m4/csharpexec.m4 (gt_CSHARPEXEC): Likewise. * m4/getcwd.m4 (gl_FUNC_GETCWD_NULL): Likewise. * m4/javacomp.m4 (gt_JAVACOMP): Likewise. * m4/javaexec.m4 (gt_JAVAEXEC): Likewise. * m4/locale-ar.m4 (gt_LOCALE_AR): Likewise. * m4/locale-fr.m4 (gt_LOCALE_FR, gt_LOCALE_FR_UTF8): Likewise. * m4/locale-ja.m4 (gt_LOCALE_JA): Likewise. * m4/locale-tr.m4 (gt_LOCALE_TR_UTF8): Likewise. * m4/locale-zh.m4 (gt_LOCALE_ZH_CN): Likewise. * m4/malloc.m4 (gl_CHECK_MALLOC_POSIX): Likewise. * m4/nocrash.m4 (GL_NOCRASH): Likewise. * m4/pathmax.m4 (gl_PATHMAX_SNIPPET): Likewise. * m4/ptsname_r.m4 (gl_PREREQ_PTSNAME_R): Likewise. * m4/stdio_h.m4 (gl_STDIO_H): Likewise. * m4/tmpfile.m4 (gl_FUNC_TMPFILE): Likewise. * m4/unistd_h.m4 (gl_UNISTD_H): Likewise.
* maint: Run 'make update-copyright'Paul Eggert2018-01-011-1/+1
|
* glob.c: Silence warning about void pointer arithmeticTim Rühsen2017-12-151-1/+2
|
* glob: fix another heap buffer overflowPaul Eggert2017-10-211-2/+2
| | | | | | Problem reported by Tim Rühsen in: https://sourceware.org/bugzilla/show_bug.cgi?id=22332 * lib/glob.c (glob): Avoid buffer overrun when unescaping.
* glob: fix heap buffer overflowPaul Eggert2017-10-191-1/+1
| | | | | | | | * lib/glob.c (glob): Fix off-by-one error introduced into glibc in commit dd7d45e838a42b0ed470c44b55901ea98d0c2bab dated 1997-10-29 20:33:40. Problem reported by Tim Rühsen in: https://sourceware.org/bugzilla/show_bug.cgi?id=22320 Fix suggested by Bruno Haible.
* glob: pacify fuzzer for mempcpyPaul Eggert2017-10-181-2/+5
| | | | | | Problem reported by Tim Rühsen in: https://lists.gnu.org/archive/html/bug-gnulib/2017-10/msg00054.html * lib/glob.c (glob): Do not pass NULL to mempcpy.
* glob: remove bogus extern declPaul Eggert2017-09-261-3/+0
| | | | | | * lib/glob.c (__glob_pattern_type): Remove now-spurious extern declaration. Problem reported by Adhemerval Zanella in: https://sourceware.org/ml/libc-alpha/2017-09/msg00972.html
* all: prefer https: URLsPaul Eggert2017-09-131-1/+1
|
* glob: Use enum for __glob_pattern_type resultPaul Eggert2017-09-051-4/+4
| | | | | | | | | | | From a patch proposed by Adhemerval Zanella in: https://sourceware.org/ml/libc-alpha/2017-09/msg00212.html * lib/glob_internal.h (GLOBPAT_NONE, GLOBPAT_SPECIAL) (GLOBPAT_BACKSLASH, GLOBPAT_BRACKET): New constants. * lib/glob_internal.h (__glob_pattern_type): * lib/glob.c (glob): * lib/glob_pattern_p.c (__glob_pattern_p): Use them.
* glob: fix for use in glibcPaul Eggert2017-09-051-1/+1
| | | | | | | Problem reported by Adhemerval Zanella in: https://sourceware.org/ml/libc-alpha/2017-09/msg00213.html * lib/glob.c (DT_UNKNOWN, DT_DIR, DT_LINK): Do not redefine if _LIBC.
* glob: fix bugs with long login namesPaul Eggert2017-09-021-58/+30
| | | | | | | | | | Problem reported by Adhemerval Zanella in: https://sourceware.org/ml/libc-alpha/2017-08/msg00455.html * lib/glob.c (GET_LOGIN_NAME_MAX): Remove. (glob): Use the same scratch buffer for both getlogin_r and getpwnam_r. Don’t require preallocation of the login name. This simplifies storage allocation, and corrects the handling of long login names.
* glob: fix getpwnam_r errno typoPaul Eggert2017-09-021-12/+3
| | | | | | * lib/glob.c (glob): Fix longstanding misuse of errno after getpwnam_r, which returns an error number rather than setting errno.
* glob: fix typo in recent changePaul Eggert2017-09-021-1/+1
| | | | | * lib/glob.c (glob) [!HAVE_GETPWNAM_R && !_LIBC]: Fix recently-introduced typo.
* glob: don't save and restore errno unnecessarilyPaul Eggert2017-09-021-4/+0
| | | | | * lib/glob.c (glob): Don't save and restore errno merely because we have getpwnam_r.
* glob: don't assume getpwnam_rPaul Eggert2017-09-021-2/+2
| | | | | * lib/glob.c (glob): Port recent patches to platforms lacking getpwnam_r.
* glob: use scratch_buffer instead of extend_allocaPaul Eggert2017-09-011-129/+26
| | | | | | | | | | | | | | | | | | | | | Much of the lib/glob.c part of this patch comes from a glibc patch proposed by Adhemerval Zanella in: https://sourceware.org/ml/libc-alpha/2017-08/msg00456.html * lib/glob.c: Do not include <config.h>, since <libc-config.h>, included via glob.h, does this for us now. (__set_errno): Remove, as libc-config does this for us now. Include <scratch_buffer.h>. (GETPW_R_SIZE_MAX): Remove. (glob): Use struct scratch_buffer instead of extend_alloca. * lib/glob.in.h: Include libc-config.h rather than including <sys/cdefs.h> conditionally. (__BEGIN_DECLS, __END_DECLS, __THROW, __THROWNL, attribute_hidden) (__glibc_unlikely, __restrict, weak_alias): Remove, as libc-config does this for us now. * m4/glob.m4 (gl_PREREQ_GLOB): Remove sys/cdefs.h tests; no longer needed. * modules/glob (Depends-on): Add libc-config, scratch_buffer. (glob.h): Do not replace HAVE_SYS_CDEFS_H.
* glob: match dangling symlinksPaul Eggert2017-08-311-147/+80
| | | | | | | | | | | | | | | | | | | This fixes a bug I inadvertently introduced to Gnulib when I merged glibc glob back into gnulib on 2007-10-16. This fix is inspired by a patch proposed for glibc by Adhemerval Zanella in: https://sourceware.org/ml/libc-alpha/2017-08/msg00446.html * doc/posix-functions/glob.texi: Update list of affected platforms. * lib/glob.c (__lstat64): New macro. (is_dir): New function. (glob, glob_in_dir): Match symlinks even if they are dangling. (link_stat, link_exists_p): Remove. All uses removed. * lib/glob.in.h (__attribute_noinline__): Remove; no longer used. * m4/glob.m4 (gl_PREREQ_GLOB): Do not check for fstatat. * modules/glob (Depends-on): Remove dirfd. * modules/glob-tests (Depends-on): Add symlink. * tests/test-glob.c: Include errno.h, unistd.h. (BASE): New macro. (main): Test dangling symlinks, if symlinks are supported.
* glob, backupfile: inode 0 is a valid inode numberPaul Eggert2017-08-311-21/+0
| | | | | | | | | | | | | * doc/posix-functions/readdir.texi (readdir): * doc/posix-headers/dirent.texi (dirent.h): Document more readdir portability issues. * lib/backupfile.c (REAL_DIR_ENTRY): Remove. (numbered_backup): Don’t treat inode 0 any differently from other inode values. * lib/glob.c (struct readdir_result): Remove skip_entry member. (readdir_result_skip_entry, D_INO_TO_RESULT): Remove. All uses removed. * modules/glob (Depends-on): Remove d-ino.
* glob: simplify symlink detectionPaul Eggert2017-08-311-36/+39
| | | | | | | | | | | | | | | * lib/glob.c (dirent_type): New type. Use uint_fast8_t not uint8_t, as C99 does not require uint8_t. (DT_UNKNOWN, DT_DIR, DT_LNK) [!HAVE_STRUCT_DIRENT_D_TYPE]: New macros. (struct readdir_result): Use dirent_type. Do not define skip_entry unless it is needed; this saves a byte on platforms lacking d_ino. (readdir_result_type, readdir_result_skip_entry): New functions, replacing ... (readdir_result_might_be_symlink, readdir_result_might_be_dir): ... these functions, which were removed. This makes the callers easier to read. All callers changed. (D_INO_TO_RESULT): Now empty if there is no d_ino.
* glob: try to port recent changes to MS-WindowsPaul Eggert2017-08-241-1/+0
| | | | | | | Problem reported by Bruno Haible in: http://lists.gnu.org/archive/html/bug-gnulib/2017-08/msg00170.html * lib/glob.c (__glob_pattern_p) [!_LIBC]: Move from here ... * lib/glob.in.h (__glob_pattern_p): ... to here.
* glob: fix typo that broke platforms lacking d_inoPaul Eggert2017-08-241-3/+3
| | | | | | This typo also hurt performance on GNU/Linux and similar hosts. * lib/glob.c (D_INO_TO_RESULT): Fix typo (reversed ifdef) in previous change.
* glob: merge from glibc with Zanella glob changesPaul Eggert2017-08-231-238/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Merge glob from glibc, with changes for glob proposed by Adhemerval Zanella in the thread starting here: https://sourceware.org/ml/libc-alpha/2017-08/msg01079.html plus some fixes for this merge. * lib/flexmember.h: Change license wording to something that works unchanged in Glibc, since this code might be used in Glibc and this will minimize 'diff' output. * lib/glob_internal.h, lib/glob_pattern_p.c, lib/globfree.c: New files, ported from glibc. * lib/glob_pattern_p.c, lib/globfree.c, lib/glob.c [!_LIBC]: Include <config.h> first. * lib/glob-libc.h (_Restrict_): Remove. All uses replaced with __restrict. (__size_t): Remove. All uses replaced by size_t. (size_t): Define by defining __need_size_t and including <stddef.h>. This should work even in non-glibc platforms, where any name pollution is OK. Use __USE_MISC instead of __USE_BSD || __USE_GNU. (struct stat64): Don’t worry about __GLOB_GNULIB. (glob, globfree, glob_pattern_p): Remove macros for __USE_FILE_OFFSET64 && __GNUC__ < 2 && !defined __GLOB_GNULIB case. Remove _GL_ARG_NONNULL as GNU behavior is to accept NULL but set errno. * lib/glob.c (_GL_ARG_NONNULL) [!_LIBC]: Remove. All uses removed since the glibc behavior works on null pointers. Do not include stdio.h; old SunOS is irrelevant now. Do not worry about GLOB_ONLY_P as we now mimic glibc here. Include glob_internal.h. (D_INO_TO_RESULT): Depend on (_LIBC || D_INO_IN_DIRENT), not ((POSIX || WINDOWS32) && !__GNU_LIBRARY__). The latter probably worked only coincidentally. (attribute_hidden, __attribute_noinline__, __glibc_unlikely): Remove macros; now done in glob.in.h. (size_add_wrapv): Do not use __builtin_add_overflow if __ICC. (glob): Properly initialize glob structure with GLOB_BRACE|GLOB_DOOFFS (bug 20707). Remove old code using SHELL since Bash no longer uses this. (glob, prefix_array): Separate MS code better. (glob, glob_in_dir): Use C99 decls before statements when glibc does. (glob_in_dir): Remove old Amiga and VMS code. (globfree, __glob_pattern_type, __glob_pattern_p): Move to separate files. * lib/glob.in.h (attribute_hidden, __attribute_noinline__) (__glibc_unlikely): Move here from glob.c. (__restrict): New macro here, replacing the _Restrict_ in glob.c. (weak_alias): New macro. (__size_t): Remove. All uses replaced by size_t. * modules/d-ino (License): Now LGPLv2+, for compatibility with glob. * modules/flexmember (License): Now LGPLv2+, which it should have been anyway since flexmember.h is not unlimited-license. * modules/glob (Files): Add +lib/glob_internal.h, lib/glob_pattern_p.c, lib/globfree.c. (Depends-on): Remove snippet/arg-nonnull.
* glob: port to clang's Undefined SanitizerPaul Eggert2017-08-221-14/+15
| | | | | | | | | Problem reported by Tim Rühsen in: http://lists.gnu.org/archive/html/bug-gnulib/2017-08/msg00144.html * lib/glob.c (FLEXIBLE_ARRAY_MEMBER) [_LIBC]: Define to empty. (glob_in_dir): Do not rely on undefined behavior in accessing struct members beyond their bounds. Use a flexible array member instead.
* Don't interpret EOVERFLOW to mean nonexistencePaul Eggert2017-07-301-12/+16
| | | | | | | | | | | | | * 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.
* glob: Fix more memory leaks.Tim Rühsen2017-07-101-17/+32
| | | | | | * lib/glob.c (glob): Use 'goto out' in order to free dirname before returning. Reported by Tim Rühsen.
* glob: Fix more memory leaks.Bruno Haible2017-07-061-0/+2
| | | | | * lib/glob.c (glob): Free dirname before returning. Reported by Coverity and Tim Rühsen.
* glob: Declare variables at the very start of their scope.Benno Schulenberg2017-07-021-4/+10
| | | | | * lib/glob.c (convert_dirent, convert_dirent64): Give each fragment its separate scope, so the functions will compile on Haiku.
* glob: Fix more memory leaks.Bruno Haible2017-04-231-5/+14
| | | | | * lib/glob.c (glob): Free allocated memory before returning. Reported by Coverity via Tim Rühsen.
* glob: Fix invalid free() call.Bruno Haible2017-03-311-1/+4
| | | | | | * lib/glob.c (glob): Reset malloc_home_dir when assigning a pointer to static storage to home_dir. Reported by Coverity via Tim Rühsen.
* glob: Fix memory leaks.Bruno Haible2017-03-311-2/+11
| | | | | * lib/glob.c (glob): Free allocated memory before returning. Reported by Coverity via Tim Rühsen.