30#define GLOB_ONLYDIR (1<<30)
31#define GLOB_FLAGMASK (~GLOB_ONLYDIR)
33#define GLOB_FLAGMASK (~0)
44 size_t *open_basedir_indexmap;
45 size_t open_basedir_indexmap_size;
46 bool open_basedir_used;
51 glob_s_t *pglob = (glob_s_t *)stream->
abstract;
53 if (pglob && pglob->path) {
55 *plen = pglob->path_len;
69 glob_s_t *pglob = (glob_s_t *)stream->
abstract;
71 if (pglob && pglob->pattern) {
73 *plen = pglob->pattern_len;
75 return pglob->pattern;
85static inline int php_glob_stream_get_result_count(glob_s_t *pglob)
87 return pglob->open_basedir_used ? (int) pglob->open_basedir_indexmap_size : pglob->
glob.gl_pathc;
92 glob_s_t *pglob = (glob_s_t *)stream->
abstract;
96 *pflags = pglob->flags;
98 return php_glob_stream_get_result_count(pglob);
108static void php_glob_stream_path_split(glob_s_t *pglob,
const char *path,
int get_path,
const char **p_file)
110 const char *
pos, *gpath = path;
127 if ((path - gpath) > 1) {
130 pglob->path_len = path - gpath;
131 pglob->path =
estrndup(gpath, pglob->path_len);
138 glob_s_t *pglob = (glob_s_t *)stream->
abstract;
141 int glob_result_count;
146 glob_result_count = php_glob_stream_get_result_count(pglob);
147 if (pglob->index < (
size_t) glob_result_count) {
148 index = pglob->open_basedir_used && pglob->open_basedir_indexmap ?
149 pglob->open_basedir_indexmap[pglob->index] : pglob->index;
150 php_glob_stream_path_split(pglob, pglob->glob.gl_pathv[index], pglob->flags &
GLOB_APPEND, &path);
156 pglob->index = glob_result_count;
167static int php_glob_stream_close(
php_stream *stream,
int close_handle)
169 glob_s_t *pglob = (glob_s_t *)stream->
abstract;
177 if (pglob->pattern) {
178 efree(pglob->pattern);
180 if (pglob->open_basedir_indexmap) {
181 efree(pglob->open_basedir_indexmap);
184 efree(stream->abstract);
191 glob_s_t *pglob = (glob_s_t *)stream->
abstract;
205 NULL, php_glob_stream_read,
206 php_glob_stream_close,
NULL,
208 php_glob_stream_rewind,
220 const char *tmp, *
pos;
222 if (!
strncmp(path,
"glob://",
sizeof(
"glob://")-1)) {
223 path +=
sizeof(
"glob://")-1;
225 *opened_path = zend_string_init(path,
strlen(path), 0);
228 const char *pattern = path;
247 pattern = work_pattern;
251 pglob =
ecalloc(1,
sizeof(*pglob));
253 if (0 != (
ret =
glob(pattern, pglob->flags & GLOB_FLAGMASK,
NULL, &pglob->glob))) {
266 for (i = 0; i < pglob->glob.gl_pathc; i++) {
267 char *
p = pglob->glob.gl_pathv[i];
268 char *q =
p + cwd_skip;
269 char *e =
p +
strlen(pglob->glob.gl_pathv[i]) - 1;
280 pglob->open_basedir_used =
true;
281 for (i = 0; i < pglob->glob.gl_pathc; i++) {
283 if (!pglob->open_basedir_indexmap) {
285 pglob->glob.gl_pathc,
sizeof(
size_t), 0);
287 pglob->open_basedir_indexmap[pglob->open_basedir_indexmap_size++] = i;
303 pglob->pattern =
estrndup(
pos, pglob->pattern_len);
307 if (pglob->glob.gl_pathc) {
308 php_glob_stream_path_split(pglob, pglob->glob.gl_pathv[0], 1, &tmp);
310 php_glob_stream_path_split(pglob, path, 1, &tmp);
322 php_glob_stream_opener,
332 &php_glob_stream_wrapper_ops,
strrchr(string $haystack, string $needle, bool $before_needle=false)
count(Countable|array $value, int $mode=COUNT_NORMAL)
glob(string $pattern, int $flags=0)
zend_ffi_ctype_name_buf buf
PHPAPI int php_check_open_basedir_ex(const char *path, int warn)
PHPAPI void globfree(glob_t *pglob)
#define PHP_STRLCPY(dst, src, size, src_size)
unsigned const char * pos
PHP_JSON_API size_t int options
PHPAPI char * _php_glob_stream_get_pattern(php_stream *stream, size_t *plen STREAMS_DC)
PHPAPI int _php_glob_stream_get_count(php_stream *stream, int *pflags STREAMS_DC)
PHPAPI char * _php_glob_stream_get_path(php_stream *stream, size_t *plen STREAMS_DC)
PHPAPI const php_stream_wrapper php_glob_stream_wrapper
PHPAPI const php_stream_ops php_glob_stream_ops
struct _php_stream_wrapper_ops php_stream_wrapper_ops
struct _php_stream php_stream
struct _php_stream_context php_stream_context
struct _php_stream_dirent php_stream_dirent
#define STREAM_DISABLE_OPEN_BASEDIR
struct _php_stream_ops php_stream_ops
struct _php_stream_wrapper php_stream_wrapper
#define php_stream_alloc(ops, thisptr, persistent_id, mode)
#define estrndup(s, length)
#define ecalloc(nmemb, size)
#define safe_emalloc(nmemb, size, offset)
strncmp(string $string1, string $string2, int $length)
struct _zend_string zend_string
#define IS_ABSOLUTE_PATH(path, len)
#define VCWD_GETCWD(buff, size)