mirror of
https://github.com/php/php-src.git
synced 2025-08-21 01:45:16 +02:00
PHP glob() will now emulate GLOB_ONLYDIR on non-GNU systems
This commit is contained in:
parent
edf78b2141
commit
a7edbe04ad
1 changed files with 25 additions and 4 deletions
|
@ -141,9 +141,6 @@ PHP_MINIT_FUNCTION(dir)
|
||||||
#ifdef GLOB_BRACE
|
#ifdef GLOB_BRACE
|
||||||
REGISTER_LONG_CONSTANT("GLOB_BRACE", GLOB_BRACE, CONST_CS | CONST_PERSISTENT);
|
REGISTER_LONG_CONSTANT("GLOB_BRACE", GLOB_BRACE, CONST_CS | CONST_PERSISTENT);
|
||||||
#endif
|
#endif
|
||||||
#ifdef GLOB_ONLYDIR
|
|
||||||
REGISTER_LONG_CONSTANT("GLOB_ONLYDIR", GLOB_ONLYDIR, CONST_CS | CONST_PERSISTENT);
|
|
||||||
#endif
|
|
||||||
#ifdef GLOB_MARK
|
#ifdef GLOB_MARK
|
||||||
REGISTER_LONG_CONSTANT("GLOB_MARK", GLOB_MARK, CONST_CS | CONST_PERSISTENT);
|
REGISTER_LONG_CONSTANT("GLOB_MARK", GLOB_MARK, CONST_CS | CONST_PERSISTENT);
|
||||||
#endif
|
#endif
|
||||||
|
@ -156,6 +153,17 @@ PHP_MINIT_FUNCTION(dir)
|
||||||
#ifdef GLOB_NOESCAPE
|
#ifdef GLOB_NOESCAPE
|
||||||
REGISTER_LONG_CONSTANT("GLOB_NOESCAPE", GLOB_NOESCAPE, CONST_CS | CONST_PERSISTENT);
|
REGISTER_LONG_CONSTANT("GLOB_NOESCAPE", GLOB_NOESCAPE, CONST_CS | CONST_PERSISTENT);
|
||||||
#endif
|
#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
|
#endif
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
@ -386,7 +394,7 @@ PHP_FUNCTION(glob)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
globbuf.gl_offs = 0;
|
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
|
#ifdef GLOB_NOMATCH
|
||||||
if (GLOB_NOMATCH == ret) {
|
if (GLOB_NOMATCH == ret) {
|
||||||
/* Linux handles no matches as an error condition, but FreeBSD
|
/* Linux handles no matches as an error condition, but FreeBSD
|
||||||
|
@ -421,6 +429,19 @@ PHP_FUNCTION(glob)
|
||||||
|
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
for (n = 0; n < globbuf.gl_pathc; n++) {
|
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);
|
add_next_index_string(return_value, globbuf.gl_pathv[n]+cwd_skip, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue