]> granicus.if.org Git - php/commitdiff
Support for GLOB_ERR so that glob() reports permission problems (Bug #28355)
authorHartmut Holzgraefe <hholzgra@php.net>
Sun, 12 Jun 2005 07:53:24 +0000 (07:53 +0000)
committerHartmut Holzgraefe <hholzgra@php.net>
Sun, 12 Jun 2005 07:53:24 +0000 (07:53 +0000)
ext/standard/dir.c

index 70d17c672a1e8a1c0b56288fe1eff29d318a7319..b1d756ce2d72cce6e66e71348a8c5734eb5e1e74 100644 (file)
@@ -155,6 +155,9 @@ PHP_MINIT_FUNCTION(dir)
 #ifdef GLOB_NOESCAPE
        REGISTER_LONG_CONSTANT("GLOB_NOESCAPE", GLOB_NOESCAPE, CONST_CS | CONST_PERSISTENT);
 #endif
+#ifdef GLOB_ERR
+       REGISTER_LONG_CONSTANT("GLOB_ERR", GLOB_ERR, CONST_CS | CONST_PERSISTENT);
+#endif
 
 #ifndef GLOB_ONLYDIR
 #define GLOB_ONLYDIR (1<<30)
@@ -395,10 +398,14 @@ PHP_FUNCTION(glob)
        if (0 != (ret = glob(pattern, flags & GLOB_FLAGMASK, NULL, &globbuf))) {
 #ifdef GLOB_NOMATCH
                if (GLOB_NOMATCH == ret) {
-                       /* Linux handles no matches as an error condition, but FreeBSD
-                        * doesn't. This ensure that if no match is found, an empty array
-                        * is always returned so it can be used without worrying in e.g.
-                        * foreach() */
+                       /* Some glob implementation simply return no data if no matches
+                          were found, others return the GLOB_NOMATCH error code.
+                          We don't want to treat GLOB_NOMATCH as an error condition
+                          so that PHP glob() behaves the same on both types of 
+                          implementations and so that 'foreach (glob() as ...'
+                          can be used for simple glob() calls without further error
+                          checking.
+                       */
                        array_init(return_value);
                        return;
                }
@@ -424,7 +431,7 @@ PHP_FUNCTION(glob)
 
        array_init(return_value);
        for (n = 0; n < globbuf.gl_pathc; n++) {
-               /* we need to this everytime since GLOB_ONLYDIR does not guarantee that
+               /* we need to do this everytime since GLOB_ONLYDIR does not guarantee that
                 * all directories will be filtered. GNU libc documentation states the
                 * following: 
                 * If the information about the type of the file is easily available