helly Sat Mar 3 21:38:25 2007 UTC
Modified files:
/php-src/main/streams glob_wrapper.c php_stream_glob_wrapper.h
Log:
- Provide access to pattern used in glob
http://cvs.php.net/viewvc.cgi/php-src/main/streams/glob_wrapper.c?r1=1.2&r2=1.3&diff_format=u
Index: php-src/main/streams/glob_wrapper.c
diff -u php-src/main/streams/glob_wrapper.c:1.2
php-src/main/streams/glob_wrapper.c:1.3
--- php-src/main/streams/glob_wrapper.c:1.2 Sat Mar 3 20:56:45 2007
+++ php-src/main/streams/glob_wrapper.c Sat Mar 3 21:38:25 2007
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: glob_wrapper.c,v 1.2 2007/03/03 20:56:45 helly Exp $ */
+/* $Id: glob_wrapper.c,v 1.3 2007/03/03 21:38:25 helly Exp $ */
#include "php.h"
#include "php_streams_int.h"
@@ -42,6 +42,8 @@
int flags;
char *path;
size_t path_len;
+ char *pattern;
+ size_t pattern_len;
} glob_s_t;
PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, int *plen
STREAMS_DC TSRMLS_DC) /* {{{ */
@@ -66,6 +68,28 @@
}
/* }}} */
+PHPAPI char* _php_glob_stream_get_pattern(php_stream *stream, int copy, int
*plen STREAMS_DC TSRMLS_DC) /* {{{ */
+{
+ glob_s_t *pglob = (glob_s_t *)stream->abstract;
+
+ if (pglob && pglob->pattern) {
+ if (plen) {
+ *plen = pglob->pattern_len;
+ }
+ if (copy) {
+ return estrndup(pglob->pattern, pglob->pattern_len);
+ } else {
+ return pglob->pattern;
+ }
+ } else {
+ if (plen) {
+ *plen = 0;
+ }
+ return NULL;
+ }
+}
+/* }}} */
+
static void php_glob_stream_path_split(glob_s_t *pglob, char *path, int
get_path, char **p_file TSRMLS_DC) /* {{{ */
{
char *pos, *gpath = path;
@@ -75,7 +99,6 @@
}
#if defined(PHP_WIN32) || defined(NETWARE)
if ((pos = strrchr(path, '\\')) != NULL) {
- if (pos != NULL) {
path = pos+1;
}
#endif
@@ -86,6 +109,9 @@
if (pglob->path) {
efree(pglob->path);
}
+ if (path != gpath) {
+ path--;
+ }
pglob->path_len = path - gpath;
pglob->path = estrndup(gpath, pglob->path_len);
}
@@ -126,6 +152,9 @@
if (pglob->path) {
efree(pglob->path);
}
+ if (pglob->pattern) {
+ efree(pglob->pattern);
+ }
}
efree(stream->abstract);
return 0;
@@ -163,7 +192,7 @@
{
glob_s_t *pglob;
int ret;
- char *tmp;
+ char *tmp, *pos;
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) &&
php_check_open_basedir(path TSRMLS_CC)) {
return NULL;
@@ -199,6 +228,19 @@
}
}
+ pos = path;
+ if ((tmp = strrchr(pos, '/')) != NULL) {
+ pos = tmp+1;
+ }
+#if defined(PHP_WIN32) || defined(NETWARE)
+ if ((tmp = strrchr(pos, '\\')) != NULL) {
+ pos = tmp+1;
+ }
+#endif
+
+ pglob->pattern_len = strlen(pos);
+ pglob->pattern = estrndup(pos, pglob->pattern_len);
+
return php_stream_alloc(&php_glob_stream_ops, pglob, 0, mode);
}
/* }}} */
http://cvs.php.net/viewvc.cgi/php-src/main/streams/php_stream_glob_wrapper.h?r1=1.2&r2=1.3&diff_format=u
Index: php-src/main/streams/php_stream_glob_wrapper.h
diff -u php-src/main/streams/php_stream_glob_wrapper.h:1.2
php-src/main/streams/php_stream_glob_wrapper.h:1.3
--- php-src/main/streams/php_stream_glob_wrapper.h:1.2 Sat Mar 3 20:56:45 2007
+++ php-src/main/streams/php_stream_glob_wrapper.h Sat Mar 3 21:38:25 2007
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_stream_glob_wrapper.h,v 1.2 2007/03/03 20:56:45 helly Exp $ */
+/* $Id: php_stream_glob_wrapper.h,v 1.3 2007/03/03 21:38:25 helly Exp $ */
PHPAPI extern php_stream_wrapper php_glob_stream_wrapper;
PHPAPI extern php_stream_ops php_glob_stream_ops;
@@ -26,6 +26,9 @@
PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, int *plen
STREAMS_DC TSRMLS_DC);
#define php_glob_stream_get_path(stream, copy, plen)
_php_glob_stream_get_path((stream), (copy), (plen) STREAMS_CC TSRMLS_CC)
+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)
+
END_EXTERN_C()
/*
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php