This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][BZ #10246] glob() with GLOB_NOCHECK is returning a modified pattern sometimes.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Mon, 21 Oct 2013 15:07:54 +0200
- Subject: Re: [PATCH][BZ #10246] glob() with GLOB_NOCHECK is returning a modified pattern sometimes.
- Authentication-results: sourceware.org; auth=none
- References: <20131020185938 dot GA18659 at domone dot podge> <Pine dot LNX dot 4 dot 64 dot 1310211149180 dot 23978 at digraph dot polyomino dot org dot uk>
On Mon, Oct 21, 2013 at 11:49:33AM +0000, Joseph S. Myers wrote:
> This sounds like something for which it should be easy to add a testcase
> to the testsuite.
>
> --
Here.
[BZ #10246]
* posix/glob.c (glob): Return correct value when GLOB_NOCHECK
is specified.
* posix/tst-gnuglob.c (main): Add testcase.
diff --git a/posix/glob.c b/posix/glob.c
index ece71c1..8be2352 100644
--- a/posix/glob.c
+++ b/posix/glob.c
@@ -953,8 +953,7 @@ glob (pattern, flags, errfunc, pglob)
struct_stat64 st64;
/* Return the directory if we don't check for error or if it exists. */
- if ((flags & GLOB_NOCHECK)
- || (((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0))
+ if ((((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0))
? ((*pglob->gl_stat) (dirname, &st) == 0
&& S_ISDIR (st.st_mode))
: (__stat64 (dirname, &st64) == 0 && S_ISDIR (st64.st_mode)))))
@@ -1001,6 +1000,8 @@ glob (pattern, flags, errfunc, pglob)
return 0;
}
+ else if (flags & GLOB_NOCHECK)
+ goto no_matches;
/* Not found. */
return GLOB_NOMATCH;
diff --git a/posix/tst-gnuglob.c b/posix/tst-gnuglob.c
index 0c967d0..d4923ca 100644
--- a/posix/tst-gnuglob.c
+++ b/posix/tst-gnuglob.c
@@ -392,6 +392,14 @@ main (void)
memset (&gl, '\0', sizeof (gl));
+ glob ("//foo", GLOB_NOCHECK, NULL, &gl);
+ printf ("results for glob (\"//foo\", 0)\n %s\n", gl.gl_pathv[0]);
+ if (strcmp(gl.gl_pathv[0],"//foo"))
+ {
+ printf ("failed\n");
+ result = 1;
+ }
+
gl.gl_closedir = my_closedir;
gl.gl_readdir = my_readdir;
gl.gl_opendir = my_opendir;