hholzgra                Fri Jul  4 10:40:22 2003 EDT

  Added files:                 (Branch: PHP_4_3)
    /php-src/ext/standard/tests/file    bug24482.phpt 

  Modified files:              
    /php-src/ext/standard       dir.c 
  Log:
  MFH
  
  
Index: php-src/ext/standard/dir.c
diff -u php-src/ext/standard/dir.c:1.109.2.7 php-src/ext/standard/dir.c:1.109.2.8
--- php-src/ext/standard/dir.c:1.109.2.7        Wed Jun  4 01:46:18 2003
+++ php-src/ext/standard/dir.c  Fri Jul  4 10:40:22 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dir.c,v 1.109.2.7 2003/06/04 05:46:18 sniper Exp $ */
+/* $Id: dir.c,v 1.109.2.8 2003/07/04 14:40:22 hholzgra Exp $ */
 
 /* {{{ includes/startup/misc */
 
@@ -139,9 +139,6 @@
 #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
@@ -154,6 +151,17 @@
 #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;
@@ -384,7 +392,7 @@
 #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
@@ -419,6 +427,19 @@
 
        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 != VCWD_STAT(globbuf.gl_pathv[n], &s)) {
+                               continue;
+                       }
+
+                       if (S_IFDIR != (s.st_mode & S_IFMT)) {
+                               continue;
+                       }
+               }
+#endif
                add_next_index_string(return_value, globbuf.gl_pathv[n]+cwd_skip, 1);
        }
 

Index: php-src/ext/standard/tests/file/bug24482.phpt
+++ php-src/ext/standard/tests/file/bug24482.phpt
--TEST--
Bug #24482: GLOB_ONLYDIR not working
--FILE--
<?php
$globdirs = glob("*", GLOB_ONLYDIR);

$dirs = array();
$dh = opendir(".");
while (is_string($file = readdir($dh))) {
        if ($file{0} === ".") continue;
        if (!is_dir($file)) continue;
        $dirs[] = $file;
}
closedir($dh);

if (count($dirs) != count($globdirs)) {
        echo "Directory count mismatch\n";
        
        echo "glob found:\n";
        sort($globdirs);        
        var_dump($globdirs);
        
        echo "opendir/readdir/isdir found:\n";
        sort($dirs);    
        var_dump($dirs);
} else {
        echo "OK\n";
}
?>
--EXPECT--
OK



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to