2022-03-23 Paul Eggert <eggert@cs.ucla.edu>
+ glob: test for glibc bug 25659
+ https://sourceware.org/bugzilla/show_bug.cgi?id=25659
+ * m4/glob.m4 (gl_GLOB): Replace glob if it has bug 25659.
+ * tests/test-glob.c (main): Test for glibc bug 25659.
+
glob: fix symlink and // issues; improve speed
* lib/glob.c: Include fcntl.h.
(dirfd) [_LIBC]: New macro.
-# glob.m4 serial 24
+# glob.m4 serial 25
dnl Copyright (C) 2005-2007, 2009-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
esac
fi
+ if test $REPLACE_GLOB = 0; then
+ AC_CACHE_CHECK([whether glob NOTDIR*/ omits symlink to nondir],
+ [gl_cv_glob_omit_nondir_symlinks],
+ [if test $cross_compiling != yes; then
+ if ln -s conf-file conf$$-globtest 2>/dev/null && touch conf-file
+ then
+ gl_cv_glob_omit_nondir_symlinks=maybe
+ else
+ # If we can't make a symlink, then we cannot test this issue. Be
+ # pessimistic about this.
+ gl_cv_glob_omit_nondir_symlinks=no
+ fi
+ if test $gl_cv_glob_omit_nondir_symlinks = maybe; then
+ AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stddef.h>
+ #include <glob.h>]],
+ [[glob_t found;
+ if (glob ("conf*-globtest/", 0, NULL, &found) != GLOB_NOMATCH)
+ return 1;
+ globfree (&found);
+ ]])],
+ [gl_cv_glob_omit_nondir_symlinks=yes],
+ [gl_cv_glob_omit_nondir_symlinks=no],
+ [dnl We don't get here.
+ :
+ ])
+ fi
+ rm -f conf$$-globtest
+ else
+ gl_cv_glob_omit_nondir_symlinks="$gl_cross_guess_normal"
+ fi
+ ])
+ case "$gl_cv_glob_omit_nondir_symlinks" in
+ *yes) ;;
+ *) REPLACE_GLOB=1 ;;
+ esac
+ fi
+
fi
if test $ac_cv_func_glob_pattern_p = no; then
globfree (&g);
if ((symlink (GL_NO_SUCH_FILE, BASE "globlink1") == 0 || errno == EEXIST)
- && (symlink (".", BASE "globlink2") == 0 || errno == EEXIST))
+ && (symlink (".", BASE "globlink2") == 0 || errno == EEXIST)
+ && (symlink (BASE "globfile", BASE "globlink3") == 0 || errno == EEXIST)
+ && close (creat (BASE "globfile", 0666)) == 0)
{
res = glob (BASE "globlink[12]", 0, NULL, &g);
ASSERT (res == 0 && g.gl_pathc == 2);
ASSERT (strcmp (g.gl_pathv[1], BASE "globlink2") == 0);
globfree (&g);
+ res = glob (BASE "globlink[123]/", 0, NULL, &g);
+ ASSERT (res == 0 && g.gl_pathc == 1);
+ ASSERT (strcmp (g.gl_pathv[0], BASE "globlink2/") == 0);
+ globfree (&g);
+
res = glob (BASE "globlink[12]", GLOB_MARK, NULL, &g);
ASSERT (res == 0 && g.gl_pathc == 2);
ASSERT (strcmp (g.gl_pathv[0], BASE "globlink1") == 0);