summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHartmut Holzgraefe <hholzgra@php.net>2005-06-12 07:53:24 +0000
committerHartmut Holzgraefe <hholzgra@php.net>2005-06-12 07:53:24 +0000
commit55b5376d1981270b36c63d4e7da631616a5aaee4 (patch)
tree5b9ab72df796dcba3932dacd839af6147bd970ab
parent88141e3ed01e8d4b1d1c4746197f3567549e5f24 (diff)
downloadphp-git-55b5376d1981270b36c63d4e7da631616a5aaee4.tar.gz
Support for GLOB_ERR so that glob() reports permission problems (Bug #28355)
-rw-r--r--ext/standard/dir.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/ext/standard/dir.c b/ext/standard/dir.c
index 70d17c672a..b1d756ce2d 100644
--- a/ext/standard/dir.c
+++ b/ext/standard/dir.c
@@ -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