This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH][BZ #10246] glob() with GLOB_NOCHECK is returning a modified pattern sometimes.


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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]