diff options
author | Hartmut Holzgraefe <hholzgra@php.net> | 2003-07-03 14:34:02 +0000 |
---|---|---|
committer | Hartmut Holzgraefe <hholzgra@php.net> | 2003-07-03 14:34:02 +0000 |
commit | a7edbe04ad7f81e2449f06af3791976c682212b5 (patch) | |
tree | 399d1b26ae2313164f794a52300c3725c7a27caf | |
parent | edf78b21415e078192ac304f8c784d77399045e9 (diff) | |
download | php-git-a7edbe04ad7f81e2449f06af3791976c682212b5.tar.gz |
PHP glob() will now emulate GLOB_ONLYDIR on non-GNU systems
-rw-r--r-- | ext/standard/dir.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/ext/standard/dir.c b/ext/standard/dir.c index b775ffa712..c22eb673ab 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -141,9 +141,6 @@ PHP_MINIT_FUNCTION(dir) #ifdef GLOB_BRACE REGISTER_LONG_CONSTANT("GLOB_BRACE", GLOB_BRACE, CONST_CS | CONST_PERSISTENT); #endif -#ifdef GLOB_ONLYDIR - REGISTER_LONG_CONSTANT("GLOB_ONLYDIR", GLOB_ONLYDIR, CONST_CS | CONST_PERSISTENT); -#endif #ifdef GLOB_MARK REGISTER_LONG_CONSTANT("GLOB_MARK", GLOB_MARK, CONST_CS | CONST_PERSISTENT); #endif @@ -156,6 +153,17 @@ PHP_MINIT_FUNCTION(dir) #ifdef GLOB_NOESCAPE REGISTER_LONG_CONSTANT("GLOB_NOESCAPE", GLOB_NOESCAPE, CONST_CS | CONST_PERSISTENT); #endif + +#ifndef GLOB_ONLYDIR +#define GLOB_ONLYDIR (1<<30) +#define GLOB_EMULATE_ONLYDIR +#define GLOB_FLAGMASK (~GLOB_ONLYDIR) +#else +#define GLOB_FLAGMASK (~0) +#endif + + REGISTER_LONG_CONSTANT("GLOB_ONLYDIR", GLOB_ONLYDIR, CONST_CS | CONST_PERSISTENT); + #endif return SUCCESS; @@ -386,7 +394,7 @@ PHP_FUNCTION(glob) #endif globbuf.gl_offs = 0; - if (0 != (ret = glob(pattern, flags, NULL, &globbuf))) { + 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 @@ -421,6 +429,19 @@ PHP_FUNCTION(glob) array_init(return_value); for (n = 0; n < globbuf.gl_pathc; n++) { +#ifdef GLOB_EMULATE_ONLYDIR + if (flags & GLOB_ONLYDIR) { + struct stat s; + + if (0 != stat(globbuf.gl_pathv[n], &s)) { + continue; + } + + if (!S_ISDIR(s.st_mode)) { + continue; + } + } +#endif add_next_index_string(return_value, globbuf.gl_pathv[n]+cwd_skip, 1); } |