]> granicus.if.org Git - php/commitdiff
- Allow to retrieve flags with php_glob_stream_get_count()
authorMarcus Boerger <helly@php.net>
Sat, 3 Mar 2007 23:41:10 +0000 (23:41 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 3 Mar 2007 23:41:10 +0000 (23:41 +0000)
- Detect meta chars in pathand switch to append mode so that path can
  actually changes for each entry

main/streams/glob_wrapper.c
main/streams/php_stream_glob_wrapper.h

index a9f1e3b5e46b467f004cafcc25ea74f6ba4534c3..301ce4e8bbdc62e84466b068260868348a710c49 100755 (executable)
@@ -90,11 +90,21 @@ PHPAPI char* _php_glob_stream_get_pattern(php_stream *stream, int copy, int *ple
 }
 /* }}} */
 
-PHPAPI int _php_glob_stream_get_count(php_stream *stream STREAMS_DC TSRMLS_DC) /* {{{ */
+PHPAPI int _php_glob_stream_get_count(php_stream *stream, int *pflags STREAMS_DC TSRMLS_DC) /* {{{ */
 {
        glob_s_t *pglob = (glob_s_t *)stream->abstract;
-       
-       return pglob ? pglob->glob.gl_pathc : 0;
+
+       if (pglob) {
+               if (pflags) {
+                       *pflags = pglob->flags;
+               }
+               return pglob->glob.gl_pathc;
+       } else {
+               if (pflags) {
+                       *pflags = 0;
+               }
+               return 0;
+       }
 }
 /* }}} */
 
@@ -199,7 +209,7 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, char *pat
                int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
 {
        glob_s_t *pglob;
-       int ret;
+       int ret, path_len;
        char *tmp, *pos;
 
        if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) {
@@ -208,9 +218,12 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, char *pat
 
        if (!strncmp(path, "glob://", sizeof("glob://")-1)) {
                path += sizeof("glob://")-1;
+               path_len = strlen(path);
                if (opened_path) {
-                       *opened_path = estrdup(path);
+                       *opened_path = estrndup(path, path_len);
                }
+       } else {
+               path_len = strlen(path);
        }
 
        pglob = ecalloc(sizeof(*pglob), 1);
@@ -225,17 +238,6 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, char *pat
                }
        }
 
-#ifdef GLOB_APPEND
-       if ((pglob->flags & GLOB_APPEND) == 0)
-#endif
-       {
-               if (pglob->glob.gl_pathc) {
-                       php_glob_stream_path_split(pglob, pglob->glob.gl_pathv[0], 1, &tmp TSRMLS_CC);
-               } else {
-                       php_glob_stream_path_split(pglob, path, 1, &tmp TSRMLS_CC);
-               }
-       }
-
        pos = path;
        if ((tmp = strrchr(pos, '/')) != NULL) {
                pos = tmp+1;
@@ -249,6 +251,16 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, char *pat
        pglob->pattern_len = strlen(pos);
        pglob->pattern = estrndup(pos, pglob->pattern_len);
 
+       if (strcspn(path, "*?") < (path_len - pglob->pattern_len)) {
+               pglob->flags |= GLOB_APPEND;
+       }
+
+       if (pglob->glob.gl_pathc) {
+               php_glob_stream_path_split(pglob, pglob->glob.gl_pathv[0], 1, &tmp TSRMLS_CC);
+       } else {
+               php_glob_stream_path_split(pglob, path, 1, &tmp TSRMLS_CC);
+       }
+
        return php_stream_alloc(&php_glob_stream_ops, pglob, 0, mode);
 }
 /* }}} */
index 0306fecb24e900e640cefb7c4e4eaa3b683669ff..003cbef6d1ec053fa07923e895b419feb9da7b22 100755 (executable)
@@ -29,8 +29,8 @@ PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, int *plen S
 PHPAPI char* _php_glob_stream_get_pattern(php_stream *stream, int copy, int *plen STREAMS_DC TSRMLS_DC);
 #define php_glob_stream_get_pattern(stream, copy, plen)        _php_glob_stream_get_pattern((stream), (copy), (plen) STREAMS_CC TSRMLS_CC)
 
-PHPAPI int   _php_glob_stream_get_count(php_stream *stream STREAMS_DC TSRMLS_DC);
-#define php_glob_stream_get_count(stream)      _php_glob_stream_get_count((stream) STREAMS_CC TSRMLS_CC)
+PHPAPI int   _php_glob_stream_get_count(php_stream *stream, int *pflags STREAMS_DC TSRMLS_DC);
+#define php_glob_stream_get_count(stream, pflags)      _php_glob_stream_get_count((stream), (pflags) STREAMS_CC TSRMLS_CC)
 
 END_EXTERN_C()