2000-02-24 09:32:50 +00:00
|
|
|
/*
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2014-09-19 16:33:14 +00:00
|
|
|
| PHP Version 7 |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2014-01-03 03:08:10 +00:00
|
|
|
| Copyright (c) 1997-2014 The PHP Group |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 12:51:34 +00:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
1999-07-16 13:13:16 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 12:51:34 +00:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
1999-07-16 13:13:16 +00:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2002-02-28 08:29:35 +00:00
|
|
|
| Author: Thies C. Arntzen <thies@thieso.net> |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1999-10-05 14:36:00 +00:00
|
|
|
/* {{{ includes/startup/misc */
|
|
|
|
|
1999-04-17 00:37:12 +00:00
|
|
|
#include "php.h"
|
2001-02-23 22:07:16 +00:00
|
|
|
#include "fopen_wrappers.h"
|
2002-04-16 22:14:27 +00:00
|
|
|
#include "file.h"
|
1999-12-04 19:19:57 +00:00
|
|
|
#include "php_dir.h"
|
2007-06-12 12:53:08 +00:00
|
|
|
#include "php_string.h"
|
2003-02-19 09:27:29 +00:00
|
|
|
#include "php_scandir.h"
|
2008-08-11 22:38:31 +00:00
|
|
|
#include "basic_functions.h"
|
1999-04-17 00:37:12 +00:00
|
|
|
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-16 17:06:53 +00:00
|
|
|
#ifdef HAVE_DIRENT_H
|
2003-02-19 09:27:29 +00:00
|
|
|
#include <dirent.h>
|
1999-04-17 00:37:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
2000-02-11 15:59:30 +00:00
|
|
|
#ifdef PHP_WIN32
|
1999-04-17 00:37:12 +00:00
|
|
|
#include "win32/readdir.h"
|
|
|
|
#endif
|
|
|
|
|
2003-01-28 01:48:57 +00:00
|
|
|
|
2002-03-21 19:18:13 +00:00
|
|
|
#ifdef HAVE_GLOB
|
2002-05-19 14:32:24 +00:00
|
|
|
#ifndef PHP_WIN32
|
2002-03-21 19:18:13 +00:00
|
|
|
#include <glob.h>
|
2002-05-19 14:32:24 +00:00
|
|
|
#else
|
|
|
|
#include "win32/glob.h"
|
|
|
|
#endif
|
2002-03-21 19:18:13 +00:00
|
|
|
#endif
|
|
|
|
|
1999-10-05 14:36:00 +00:00
|
|
|
typedef struct {
|
2014-02-13 13:54:23 +00:00
|
|
|
zend_resource *default_dir;
|
1999-10-05 14:36:00 +00:00
|
|
|
} php_dir_globals;
|
|
|
|
|
|
|
|
#ifdef ZTS
|
2014-10-05 17:49:41 +00:00
|
|
|
#define DIRG(v) ZEND_TSRMG(dir_globals_id, php_dir_globals *, v)
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-25 16:48:27 +00:00
|
|
|
int dir_globals_id;
|
1999-10-05 14:36:00 +00:00
|
|
|
#else
|
2000-06-27 18:44:30 +00:00
|
|
|
#define DIRG(v) (dir_globals.v)
|
1999-10-05 14:36:00 +00:00
|
|
|
php_dir_globals dir_globals;
|
|
|
|
#endif
|
|
|
|
|
2002-04-16 22:14:27 +00:00
|
|
|
#if 0
|
1999-10-05 14:36:00 +00:00
|
|
|
typedef struct {
|
|
|
|
int id;
|
|
|
|
DIR *dir;
|
|
|
|
} php_dir;
|
|
|
|
|
1999-04-17 00:37:12 +00:00
|
|
|
static int le_dirp;
|
2002-04-16 22:14:27 +00:00
|
|
|
#endif
|
1999-10-05 14:36:00 +00:00
|
|
|
|
1999-05-28 11:09:39 +00:00
|
|
|
static zend_class_entry *dir_class_entry_ptr;
|
1999-04-17 00:37:12 +00:00
|
|
|
|
1999-10-05 14:36:00 +00:00
|
|
|
#define FETCH_DIRP() \
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &id) == FAILURE) { \
|
2008-07-24 12:49:11 +00:00
|
|
|
return; \
|
|
|
|
} \
|
2000-06-05 19:47:54 +00:00
|
|
|
if (ZEND_NUM_ARGS() == 0) { \
|
1999-10-05 14:36:00 +00:00
|
|
|
myself = getThis(); \
|
2014-03-27 22:11:22 +00:00
|
|
|
if (myself) { \
|
2014-02-13 13:54:23 +00:00
|
|
|
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(myself), "handle", sizeof("handle")-1)) == NULL) { \
|
2014-12-13 22:06:14 +00:00
|
|
|
php_error_docref(NULL, E_WARNING, "Unable to find my handle property"); \
|
1999-10-05 14:36:00 +00:00
|
|
|
RETURN_FALSE; \
|
|
|
|
} \
|
2002-04-16 22:14:27 +00:00
|
|
|
ZEND_FETCH_RESOURCE(dirp, php_stream *, tmp, -1, "Directory", php_file_le_stream()); \
|
1999-10-05 14:36:00 +00:00
|
|
|
} else { \
|
2014-10-22 17:46:51 +00:00
|
|
|
ZEND_FETCH_RESOURCE(dirp, php_stream *, 0, (int)DIRG(default_dir)->handle, "Directory", php_file_le_stream()); \
|
1999-10-05 14:36:00 +00:00
|
|
|
} \
|
|
|
|
} else { \
|
2014-12-13 22:06:14 +00:00
|
|
|
dirp = (php_stream *) zend_fetch_resource(id, -1, "Directory", NULL, 1, php_file_le_stream()); \
|
2003-07-14 16:23:14 +00:00
|
|
|
if (!dirp) \
|
2002-10-07 16:46:38 +00:00
|
|
|
RETURN_FALSE; \
|
1999-10-05 14:36:00 +00:00
|
|
|
}
|
2010-06-26 16:03:39 +00:00
|
|
|
|
|
|
|
/* {{{ arginfo */
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_dir, 0, 0, 0)
|
|
|
|
ZEND_ARG_INFO(0, dir_handle)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
1999-10-05 14:36:00 +00:00
|
|
|
|
2007-09-27 18:00:48 +00:00
|
|
|
static const zend_function_entry php_dir_class_functions[] = {
|
2010-06-26 16:03:39 +00:00
|
|
|
PHP_FALIAS(close, closedir, arginfo_dir)
|
|
|
|
PHP_FALIAS(rewind, rewinddir, arginfo_dir)
|
|
|
|
PHP_NAMED_FE(read, php_if_readdir, arginfo_dir)
|
1999-08-19 16:52:53 +00:00
|
|
|
{NULL, NULL, NULL}
|
1999-05-28 11:09:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
static void php_set_default_dir(zend_resource *res)
|
2000-06-27 18:44:30 +00:00
|
|
|
{
|
2014-02-13 13:54:23 +00:00
|
|
|
if (DIRG(default_dir)) {
|
2002-09-11 14:21:39 +00:00
|
|
|
zend_list_delete(DIRG(default_dir));
|
|
|
|
}
|
2000-11-04 14:58:50 +00:00
|
|
|
|
2014-02-13 13:54:23 +00:00
|
|
|
if (res) {
|
2014-04-02 10:34:44 +00:00
|
|
|
GC_REFCOUNT(res)++;
|
2000-11-04 14:58:50 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 13:54:23 +00:00
|
|
|
DIRG(default_dir) = res;
|
2000-06-27 18:44:30 +00:00
|
|
|
}
|
|
|
|
|
2000-06-29 21:51:40 +00:00
|
|
|
PHP_RINIT_FUNCTION(dir)
|
1999-10-05 14:36:00 +00:00
|
|
|
{
|
2014-02-13 13:54:23 +00:00
|
|
|
DIRG(default_dir) = NULL;
|
2000-06-29 21:51:40 +00:00
|
|
|
return SUCCESS;
|
1999-10-05 14:36:00 +00:00
|
|
|
}
|
1999-04-17 00:37:12 +00:00
|
|
|
|
1999-07-26 20:09:08 +00:00
|
|
|
PHP_MINIT_FUNCTION(dir)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2002-11-14 22:50:01 +00:00
|
|
|
static char dirsep_str[2], pathsep_str[2];
|
1999-05-28 11:09:39 +00:00
|
|
|
zend_class_entry dir_class_entry;
|
|
|
|
|
|
|
|
INIT_CLASS_ENTRY(dir_class_entry, "Directory", php_dir_class_functions);
|
2014-12-13 22:06:14 +00:00
|
|
|
dir_class_entry_ptr = zend_register_internal_class(&dir_class_entry);
|
1999-10-05 14:36:00 +00:00
|
|
|
|
|
|
|
#ifdef ZTS
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-25 16:48:27 +00:00
|
|
|
ts_allocate_id(&dir_globals_id, sizeof(php_dir_globals), NULL, NULL);
|
1999-10-05 14:36:00 +00:00
|
|
|
#endif
|
2003-07-14 16:23:14 +00:00
|
|
|
|
2002-11-14 22:50:01 +00:00
|
|
|
dirsep_str[0] = DEFAULT_SLASH;
|
|
|
|
dirsep_str[1] = '\0';
|
|
|
|
REGISTER_STRING_CONSTANT("DIRECTORY_SEPARATOR", dirsep_str, CONST_CS|CONST_PERSISTENT);
|
2003-07-14 16:23:14 +00:00
|
|
|
|
2002-11-15 07:21:33 +00:00
|
|
|
pathsep_str[0] = ZEND_PATHS_SEPARATOR;
|
|
|
|
pathsep_str[1] = '\0';
|
2002-11-14 22:50:01 +00:00
|
|
|
REGISTER_STRING_CONSTANT("PATH_SEPARATOR", pathsep_str, CONST_CS|CONST_PERSISTENT);
|
1999-10-05 14:36:00 +00:00
|
|
|
|
2014-08-25 17:24:55 +00:00
|
|
|
REGISTER_LONG_CONSTANT("SCANDIR_SORT_ASCENDING", PHP_SCANDIR_SORT_ASCENDING, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("SCANDIR_SORT_DESCENDING", PHP_SCANDIR_SORT_DESCENDING, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("SCANDIR_SORT_NONE", PHP_SCANDIR_SORT_NONE, CONST_CS | CONST_PERSISTENT);
|
2010-11-26 09:52:28 +00:00
|
|
|
|
2002-09-26 07:15:33 +00:00
|
|
|
#ifdef HAVE_GLOB
|
2007-08-22 14:59:45 +00:00
|
|
|
|
2002-11-13 13:31:33 +00:00
|
|
|
#ifdef GLOB_BRACE
|
2014-08-25 17:24:55 +00:00
|
|
|
REGISTER_LONG_CONSTANT("GLOB_BRACE", GLOB_BRACE, CONST_CS | CONST_PERSISTENT);
|
2007-08-22 14:59:45 +00:00
|
|
|
#else
|
|
|
|
# define GLOB_BRACE 0
|
2002-11-13 13:31:33 +00:00
|
|
|
#endif
|
2007-08-22 14:59:45 +00:00
|
|
|
|
2002-09-27 12:40:31 +00:00
|
|
|
#ifdef GLOB_MARK
|
2014-08-25 17:24:55 +00:00
|
|
|
REGISTER_LONG_CONSTANT("GLOB_MARK", GLOB_MARK, CONST_CS | CONST_PERSISTENT);
|
2007-08-22 14:59:45 +00:00
|
|
|
#else
|
|
|
|
# define GLOB_MARK 0
|
2002-09-27 12:40:31 +00:00
|
|
|
#endif
|
2007-08-22 14:59:45 +00:00
|
|
|
|
2002-09-27 12:40:31 +00:00
|
|
|
#ifdef GLOB_NOSORT
|
2014-08-25 17:24:55 +00:00
|
|
|
REGISTER_LONG_CONSTANT("GLOB_NOSORT", GLOB_NOSORT, CONST_CS | CONST_PERSISTENT);
|
2007-08-22 14:59:45 +00:00
|
|
|
#else
|
|
|
|
# define GLOB_NOSORT 0
|
2002-09-27 12:40:31 +00:00
|
|
|
#endif
|
2007-08-22 14:59:45 +00:00
|
|
|
|
2002-09-27 12:40:31 +00:00
|
|
|
#ifdef GLOB_NOCHECK
|
2014-08-25 17:24:55 +00:00
|
|
|
REGISTER_LONG_CONSTANT("GLOB_NOCHECK", GLOB_NOCHECK, CONST_CS | CONST_PERSISTENT);
|
2007-08-22 14:59:45 +00:00
|
|
|
#else
|
|
|
|
# define GLOB_NOCHECK 0
|
2002-09-27 12:40:31 +00:00
|
|
|
#endif
|
2007-08-22 14:59:45 +00:00
|
|
|
|
2002-09-27 12:40:31 +00:00
|
|
|
#ifdef GLOB_NOESCAPE
|
2014-08-25 17:24:55 +00:00
|
|
|
REGISTER_LONG_CONSTANT("GLOB_NOESCAPE", GLOB_NOESCAPE, CONST_CS | CONST_PERSISTENT);
|
2007-08-22 14:59:45 +00:00
|
|
|
#else
|
|
|
|
# define GLOB_NOESCAPE 0
|
2002-09-26 11:19:26 +00:00
|
|
|
#endif
|
2007-08-22 14:59:45 +00:00
|
|
|
|
2005-06-12 07:53:24 +00:00
|
|
|
#ifdef GLOB_ERR
|
2014-08-25 17:24:55 +00:00
|
|
|
REGISTER_LONG_CONSTANT("GLOB_ERR", GLOB_ERR, CONST_CS | CONST_PERSISTENT);
|
2007-08-22 14:59:45 +00:00
|
|
|
#else
|
|
|
|
# define GLOB_ERR 0
|
2005-06-12 07:53:24 +00:00
|
|
|
#endif
|
2003-07-03 14:34:02 +00:00
|
|
|
|
|
|
|
#ifndef GLOB_ONLYDIR
|
2007-08-22 14:59:45 +00:00
|
|
|
# define GLOB_ONLYDIR (1<<30)
|
|
|
|
# define GLOB_EMULATE_ONLYDIR
|
|
|
|
# define GLOB_FLAGMASK (~GLOB_ONLYDIR)
|
2003-07-03 14:34:02 +00:00
|
|
|
#else
|
2007-08-22 14:59:45 +00:00
|
|
|
# define GLOB_FLAGMASK (~0)
|
2003-07-03 14:34:02 +00:00
|
|
|
#endif
|
|
|
|
|
2007-08-22 14:59:45 +00:00
|
|
|
/* This is used for checking validity of passed flags (passing invalid flags causes segfault in glob()!! */
|
|
|
|
#define GLOB_AVAILABLE_FLAGS (0 | GLOB_BRACE | GLOB_MARK | GLOB_NOSORT | GLOB_NOCHECK | GLOB_NOESCAPE | GLOB_ERR | GLOB_ONLYDIR)
|
|
|
|
|
2014-08-25 17:24:55 +00:00
|
|
|
REGISTER_LONG_CONSTANT("GLOB_ONLYDIR", GLOB_ONLYDIR, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("GLOB_AVAILABLE_FLAGS", GLOB_AVAILABLE_FLAGS, CONST_CS | CONST_PERSISTENT);
|
2003-07-03 14:34:02 +00:00
|
|
|
|
2003-07-14 16:23:14 +00:00
|
|
|
#endif /* HAVE_GLOB */
|
2002-09-26 00:27:52 +00:00
|
|
|
|
1999-04-17 00:37:12 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
1999-10-05 14:36:00 +00:00
|
|
|
/* }}} */
|
|
|
|
|
2003-07-14 16:23:14 +00:00
|
|
|
/* {{{ internal functions */
|
1999-10-05 14:36:00 +00:00
|
|
|
static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2004-03-01 05:40:14 +00:00
|
|
|
char *dirname;
|
2014-08-27 13:31:48 +00:00
|
|
|
size_t dir_len;
|
2004-03-01 05:40:14 +00:00
|
|
|
zval *zcontext = NULL;
|
|
|
|
php_stream_context *context = NULL;
|
2002-04-16 22:14:27 +00:00
|
|
|
php_stream *dirp;
|
2004-03-01 05:40:14 +00:00
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|r", &dirname, &dir_len, &zcontext) == FAILURE) {
|
2004-03-01 05:40:14 +00:00
|
|
|
RETURN_NULL();
|
|
|
|
}
|
|
|
|
|
2008-12-09 09:03:38 +00:00
|
|
|
context = php_stream_context_from_zval(zcontext, 0);
|
1999-04-17 00:37:12 +00:00
|
|
|
|
2010-04-26 23:53:30 +00:00
|
|
|
dirp = php_stream_opendir(dirname, REPORT_ERRORS, context);
|
2001-04-29 17:57:23 +00:00
|
|
|
|
2002-04-16 22:14:27 +00:00
|
|
|
if (dirp == NULL) {
|
1999-04-17 00:37:12 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2008-07-23 11:25:14 +00:00
|
|
|
|
|
|
|
dirp->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
|
2002-04-16 22:14:27 +00:00
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
php_set_default_dir(dirp->res);
|
1999-10-05 14:36:00 +00:00
|
|
|
|
|
|
|
if (createobject) {
|
|
|
|
object_init_ex(return_value, dir_class_entry_ptr);
|
2014-04-15 11:40:40 +00:00
|
|
|
add_property_stringl(return_value, "path", dirname, dir_len);
|
2014-02-13 13:54:23 +00:00
|
|
|
add_property_resource(return_value, "handle", dirp->res);
|
2002-04-16 22:14:27 +00:00
|
|
|
php_stream_auto_cleanup(dirp); /* so we don't get warnings under debug */
|
1999-10-05 14:36:00 +00:00
|
|
|
} else {
|
2002-04-16 22:14:27 +00:00
|
|
|
php_stream_to_zval(dirp, return_value);
|
1999-10-05 14:36:00 +00:00
|
|
|
}
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2003-07-14 16:23:14 +00:00
|
|
|
|
2004-03-01 05:40:14 +00:00
|
|
|
/* {{{ proto mixed opendir(string path[, resource context])
|
1999-10-05 14:36:00 +00:00
|
|
|
Open a directory and return a dir_handle */
|
|
|
|
PHP_FUNCTION(opendir)
|
|
|
|
{
|
2001-08-11 17:03:37 +00:00
|
|
|
_php_do_opendir(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
|
1999-10-05 14:36:00 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2003-07-14 16:23:14 +00:00
|
|
|
|
2004-03-01 05:40:14 +00:00
|
|
|
/* {{{ proto object dir(string directory[, resource context])
|
2000-02-24 07:49:43 +00:00
|
|
|
Directory class with properties, handle and class and methods read, rewind and close */
|
1999-10-05 14:36:00 +00:00
|
|
|
PHP_FUNCTION(getdir)
|
|
|
|
{
|
2001-08-11 17:03:37 +00:00
|
|
|
_php_do_opendir(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
|
1999-10-05 14:36:00 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2003-07-14 16:23:14 +00:00
|
|
|
|
2002-01-03 06:57:22 +00:00
|
|
|
/* {{{ proto void closedir([resource dir_handle])
|
2000-02-24 07:49:43 +00:00
|
|
|
Close directory connection identified by the dir_handle */
|
1999-05-16 11:19:26 +00:00
|
|
|
PHP_FUNCTION(closedir)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2014-02-13 13:54:23 +00:00
|
|
|
zval *id = NULL, *tmp, *myself;
|
2002-04-16 22:14:27 +00:00
|
|
|
php_stream *dirp;
|
2014-02-13 13:54:23 +00:00
|
|
|
zend_resource *res;
|
1999-10-05 14:36:00 +00:00
|
|
|
|
|
|
|
FETCH_DIRP();
|
|
|
|
|
2008-06-11 09:01:56 +00:00
|
|
|
if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
|
2014-12-13 22:06:14 +00:00
|
|
|
php_error_docref(NULL, E_WARNING, "%pd is not a valid Directory resource", dirp->res->handle);
|
2008-06-11 09:01:56 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-13 13:54:23 +00:00
|
|
|
res = dirp->res;
|
2014-03-09 12:08:06 +00:00
|
|
|
zend_list_close(dirp->res);
|
2008-03-05 12:10:02 +00:00
|
|
|
|
2014-02-13 13:54:23 +00:00
|
|
|
if (res == DIRG(default_dir)) {
|
2014-12-13 22:06:14 +00:00
|
|
|
php_set_default_dir(NULL);
|
2000-11-04 14:58:50 +00:00
|
|
|
}
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
2001-02-14 10:48:48 +00:00
|
|
|
/* }}} */
|
2001-02-15 00:43:44 +00:00
|
|
|
|
2001-09-12 02:07:46 +00:00
|
|
|
#if defined(HAVE_CHROOT) && !defined(ZTS) && ENABLE_CHROOT_FUNC
|
2001-12-30 09:50:41 +00:00
|
|
|
/* {{{ proto bool chroot(string directory)
|
2001-02-14 10:48:48 +00:00
|
|
|
Change root directory */
|
|
|
|
PHP_FUNCTION(chroot)
|
|
|
|
{
|
2001-12-30 09:50:41 +00:00
|
|
|
char *str;
|
2014-08-27 13:31:48 +00:00
|
|
|
int ret;
|
|
|
|
size_t str_len;
|
2001-02-14 10:48:48 +00:00
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &str_len) == FAILURE) {
|
2001-12-30 09:50:41 +00:00
|
|
|
RETURN_FALSE;
|
2001-02-14 10:48:48 +00:00
|
|
|
}
|
2002-09-11 14:21:39 +00:00
|
|
|
|
|
|
|
ret = chroot(str);
|
2001-02-14 10:48:48 +00:00
|
|
|
if (ret != 0) {
|
2014-12-13 22:06:14 +00:00
|
|
|
php_error_docref(NULL, E_WARNING, "%s (errno %d)", strerror(errno), errno);
|
2001-02-14 10:48:48 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
php_clear_stat_cache(1, NULL, 0);
|
2007-01-22 09:31:46 +00:00
|
|
|
|
2001-02-14 11:02:54 +00:00
|
|
|
ret = chdir("/");
|
|
|
|
|
|
|
|
if (ret != 0) {
|
2014-12-13 22:06:14 +00:00
|
|
|
php_error_docref(NULL, E_WARNING, "%s (errno %d)", strerror(errno), errno);
|
2001-02-14 11:02:54 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-02-14 10:48:48 +00:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
1999-04-17 00:37:12 +00:00
|
|
|
/* }}} */
|
2001-02-15 00:43:44 +00:00
|
|
|
#endif
|
|
|
|
|
2001-12-30 10:13:08 +00:00
|
|
|
/* {{{ proto bool chdir(string directory)
|
1999-10-20 16:17:30 +00:00
|
|
|
Change the current directory */
|
1999-05-16 11:19:26 +00:00
|
|
|
PHP_FUNCTION(chdir)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2001-12-30 10:13:08 +00:00
|
|
|
char *str;
|
2014-08-27 13:31:48 +00:00
|
|
|
int ret;
|
|
|
|
size_t str_len;
|
1999-04-17 00:37:12 +00:00
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &str, &str_len) == FAILURE) {
|
2001-12-30 10:13:08 +00:00
|
|
|
RETURN_FALSE;
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
if (php_check_open_basedir(str)) {
|
2001-06-20 14:47:26 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2001-12-30 10:13:08 +00:00
|
|
|
ret = VCWD_CHDIR(str);
|
1999-10-05 14:36:00 +00:00
|
|
|
|
2000-06-04 07:57:40 +00:00
|
|
|
if (ret != 0) {
|
2014-12-13 22:06:14 +00:00
|
|
|
php_error_docref(NULL, E_WARNING, "%s (errno %d)", strerror(errno), errno);
|
1999-04-17 00:37:12 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-05 14:36:00 +00:00
|
|
|
|
2008-08-11 22:38:31 +00:00
|
|
|
if (BG(CurrentStatFile) && !IS_ABSOLUTE_PATH(BG(CurrentStatFile), strlen(BG(CurrentStatFile)))) {
|
|
|
|
efree(BG(CurrentStatFile));
|
|
|
|
BG(CurrentStatFile) = NULL;
|
|
|
|
}
|
|
|
|
if (BG(CurrentLStatFile) && !IS_ABSOLUTE_PATH(BG(CurrentLStatFile), strlen(BG(CurrentLStatFile)))) {
|
|
|
|
efree(BG(CurrentLStatFile));
|
|
|
|
BG(CurrentLStatFile) = NULL;
|
|
|
|
}
|
|
|
|
|
1999-04-17 00:37:12 +00:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
1999-10-20 16:17:30 +00:00
|
|
|
/* }}} */
|
2003-07-14 16:23:14 +00:00
|
|
|
|
2002-01-03 06:57:22 +00:00
|
|
|
/* {{{ proto mixed getcwd(void)
|
1999-10-20 16:17:30 +00:00
|
|
|
Gets the current directory */
|
|
|
|
PHP_FUNCTION(getcwd)
|
|
|
|
{
|
|
|
|
char path[MAXPATHLEN];
|
1999-10-20 18:09:44 +00:00
|
|
|
char *ret=NULL;
|
1999-10-20 16:17:30 +00:00
|
|
|
|
2008-03-10 22:15:36 +00:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
1999-10-20 16:17:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_GETCWD
|
2001-04-30 12:45:02 +00:00
|
|
|
ret = VCWD_GETCWD(path, MAXPATHLEN);
|
1999-10-20 16:17:30 +00:00
|
|
|
#elif HAVE_GETWD
|
2001-04-30 12:45:02 +00:00
|
|
|
ret = VCWD_GETWD(path);
|
1999-10-20 16:17:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ret) {
|
2014-02-13 13:54:23 +00:00
|
|
|
RETURN_STRING(path);
|
1999-10-20 16:17:30 +00:00
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
1999-04-17 00:37:12 +00:00
|
|
|
/* }}} */
|
2003-07-14 16:23:14 +00:00
|
|
|
|
2002-01-03 06:57:22 +00:00
|
|
|
/* {{{ proto void rewinddir([resource dir_handle])
|
2000-02-24 07:49:43 +00:00
|
|
|
Rewind dir_handle back to the start */
|
1999-05-16 11:19:26 +00:00
|
|
|
PHP_FUNCTION(rewinddir)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2014-02-13 13:54:23 +00:00
|
|
|
zval *id = NULL, *tmp, *myself;
|
2002-04-16 22:14:27 +00:00
|
|
|
php_stream *dirp;
|
1999-04-17 00:37:12 +00:00
|
|
|
|
1999-10-05 14:36:00 +00:00
|
|
|
FETCH_DIRP();
|
|
|
|
|
2008-06-11 09:01:56 +00:00
|
|
|
if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
|
2014-12-13 22:06:14 +00:00
|
|
|
php_error_docref(NULL, E_WARNING, "%pd is not a valid Directory resource", dirp->res->handle);
|
2008-06-11 09:01:56 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-04-16 22:14:27 +00:00
|
|
|
php_stream_rewinddir(dirp);
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2002-03-21 19:18:13 +00:00
|
|
|
|
2002-01-03 06:57:22 +00:00
|
|
|
/* {{{ proto string readdir([resource dir_handle])
|
2000-02-24 07:49:43 +00:00
|
|
|
Read directory entry from dir_handle */
|
2000-12-07 12:09:38 +00:00
|
|
|
PHP_NAMED_FUNCTION(php_if_readdir)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2014-02-13 13:54:23 +00:00
|
|
|
zval *id = NULL, *tmp, *myself;
|
2002-04-16 22:14:27 +00:00
|
|
|
php_stream *dirp;
|
|
|
|
php_stream_dirent entry;
|
1999-10-05 14:36:00 +00:00
|
|
|
|
|
|
|
FETCH_DIRP();
|
2000-05-23 15:13:16 +00:00
|
|
|
|
2008-06-11 09:01:56 +00:00
|
|
|
if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
|
2014-12-13 22:06:14 +00:00
|
|
|
php_error_docref(NULL, E_WARNING, "%pd is not a valid Directory resource", dirp->res->handle);
|
2008-06-11 09:01:56 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-04-16 22:14:27 +00:00
|
|
|
if (php_stream_readdir(dirp, &entry)) {
|
2014-02-13 13:54:23 +00:00
|
|
|
RETURN_STRINGL(entry.d_name, strlen(entry.d_name));
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-03-21 19:18:13 +00:00
|
|
|
#ifdef HAVE_GLOB
|
|
|
|
/* {{{ proto array glob(string pattern [, int flags])
|
2002-09-11 14:21:39 +00:00
|
|
|
Find pathnames matching a pattern */
|
2002-03-21 19:18:13 +00:00
|
|
|
PHP_FUNCTION(glob)
|
|
|
|
{
|
2002-09-26 00:27:52 +00:00
|
|
|
int cwd_skip = 0;
|
2002-10-04 18:03:29 +00:00
|
|
|
#ifdef ZTS
|
2007-06-12 13:42:32 +00:00
|
|
|
char cwd[MAXPATHLEN];
|
2002-09-26 00:27:52 +00:00
|
|
|
char work_pattern[MAXPATHLEN];
|
|
|
|
char *result;
|
2002-10-04 18:03:29 +00:00
|
|
|
#endif
|
2002-03-21 19:18:13 +00:00
|
|
|
char *pattern = NULL;
|
2014-08-27 13:31:48 +00:00
|
|
|
size_t pattern_len;
|
2014-08-25 17:24:55 +00:00
|
|
|
zend_long flags = 0;
|
2002-03-21 19:18:13 +00:00
|
|
|
glob_t globbuf;
|
2006-02-26 10:57:00 +00:00
|
|
|
int n;
|
2003-09-26 08:09:56 +00:00
|
|
|
int ret;
|
2007-09-19 22:37:58 +00:00
|
|
|
zend_bool basedir_limit = 0;
|
2002-03-21 19:18:13 +00:00
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|l", &pattern, &pattern_len, &flags) == FAILURE) {
|
2002-03-21 19:18:13 +00:00
|
|
|
return;
|
2007-08-22 14:59:45 +00:00
|
|
|
}
|
|
|
|
|
2007-09-04 12:51:49 +00:00
|
|
|
if (pattern_len >= MAXPATHLEN) {
|
2014-12-13 22:06:14 +00:00
|
|
|
php_error_docref(NULL, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN);
|
2007-09-04 12:51:49 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-08-22 14:59:45 +00:00
|
|
|
if ((GLOB_AVAILABLE_FLAGS & flags) != flags) {
|
2014-12-13 22:06:14 +00:00
|
|
|
php_error_docref(NULL, E_WARNING, "At least one of the passed flags is invalid or not supported on this platform");
|
2007-08-22 14:59:45 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2002-03-21 19:18:13 +00:00
|
|
|
|
2002-09-26 00:27:52 +00:00
|
|
|
#ifdef ZTS
|
2003-07-14 16:23:14 +00:00
|
|
|
if (!IS_ABSOLUTE_PATH(pattern, pattern_len)) {
|
2002-09-26 00:27:52 +00:00
|
|
|
result = VCWD_GETCWD(cwd, MAXPATHLEN);
|
|
|
|
if (!result) {
|
|
|
|
cwd[0] = '\0';
|
|
|
|
}
|
2003-09-20 02:51:20 +00:00
|
|
|
#ifdef PHP_WIN32
|
2004-06-07 18:30:16 +00:00
|
|
|
if (IS_SLASH(*pattern)) {
|
2003-09-20 02:51:20 +00:00
|
|
|
cwd[2] = '\0';
|
|
|
|
}
|
|
|
|
#endif
|
2014-10-22 17:46:51 +00:00
|
|
|
cwd_skip = (int)strlen(cwd)+1;
|
2004-06-07 18:30:16 +00:00
|
|
|
|
2003-01-27 16:29:47 +00:00
|
|
|
snprintf(work_pattern, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, pattern);
|
2002-09-26 00:27:52 +00:00
|
|
|
pattern = work_pattern;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-09-19 22:37:58 +00:00
|
|
|
|
2007-07-16 20:29:21 +00:00
|
|
|
memset(&globbuf, 0, sizeof(glob_t));
|
2002-03-21 19:18:13 +00:00
|
|
|
globbuf.gl_offs = 0;
|
2003-07-03 14:34:02 +00:00
|
|
|
if (0 != (ret = glob(pattern, flags & GLOB_FLAGMASK, NULL, &globbuf))) {
|
2002-05-18 13:31:31 +00:00
|
|
|
#ifdef GLOB_NOMATCH
|
|
|
|
if (GLOB_NOMATCH == ret) {
|
2005-06-12 07:53:24 +00:00
|
|
|
/* Some glob implementation simply return no data if no matches
|
|
|
|
were found, others return the GLOB_NOMATCH error code.
|
|
|
|
We don't want to treat GLOB_NOMATCH as an error condition
|
|
|
|
so that PHP glob() behaves the same on both types of
|
|
|
|
implementations and so that 'foreach (glob() as ...'
|
|
|
|
can be used for simple glob() calls without further error
|
|
|
|
checking.
|
|
|
|
*/
|
2007-09-19 22:37:58 +00:00
|
|
|
goto no_results;
|
2002-05-18 13:31:31 +00:00
|
|
|
}
|
|
|
|
#endif
|
2002-03-21 19:18:13 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-04 05:45:54 +00:00
|
|
|
/* now catch the FreeBSD style of "no matches" */
|
2003-10-29 18:48:37 +00:00
|
|
|
if (!globbuf.gl_pathc || !globbuf.gl_pathv) {
|
2007-09-19 22:37:58 +00:00
|
|
|
no_results:
|
2013-08-19 12:21:16 +00:00
|
|
|
#ifndef PHP_WIN32
|
|
|
|
/* Paths containing '*', '?' and some other chars are
|
|
|
|
illegal on Windows but legit on other platforms. For
|
|
|
|
this reason the direct basedir check against the glob
|
|
|
|
query is senseless on windows. For instance while *.txt
|
|
|
|
is a pretty valid filename on EXT3, it's invalid on NTFS. */
|
2010-04-26 23:53:30 +00:00
|
|
|
if (PG(open_basedir) && *PG(open_basedir)) {
|
2014-12-13 22:06:14 +00:00
|
|
|
if (php_check_open_basedir_ex(pattern, 0)) {
|
2007-09-19 22:37:58 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2013-08-19 12:21:16 +00:00
|
|
|
#endif
|
2003-06-04 05:45:54 +00:00
|
|
|
array_init(return_value);
|
|
|
|
return;
|
2003-06-03 11:01:16 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 19:18:13 +00:00
|
|
|
array_init(return_value);
|
2002-05-18 13:31:31 +00:00
|
|
|
for (n = 0; n < globbuf.gl_pathc; n++) {
|
2010-04-26 23:53:30 +00:00
|
|
|
if (PG(open_basedir) && *PG(open_basedir)) {
|
2014-12-13 22:06:14 +00:00
|
|
|
if (php_check_open_basedir_ex(globbuf.gl_pathv[n], 0)) {
|
2007-09-19 22:37:58 +00:00
|
|
|
basedir_limit = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-11-20 20:00:07 +00:00
|
|
|
/* we need to do this every time since GLOB_ONLYDIR does not guarantee that
|
2003-07-23 21:41:44 +00:00
|
|
|
* all directories will be filtered. GNU libc documentation states the
|
|
|
|
* following:
|
|
|
|
* If the information about the type of the file is easily available
|
|
|
|
* non-directories will be rejected but no extra work will be done to
|
|
|
|
* determine the information for each file. I.e., the caller must still be
|
|
|
|
* able to filter directories out.
|
|
|
|
*/
|
2003-07-03 14:34:02 +00:00
|
|
|
if (flags & GLOB_ONLYDIR) {
|
2014-08-25 18:22:49 +00:00
|
|
|
zend_stat_t s;
|
2003-07-03 14:34:02 +00:00
|
|
|
|
2003-07-03 14:54:03 +00:00
|
|
|
if (0 != VCWD_STAT(globbuf.gl_pathv[n], &s)) {
|
2003-07-03 14:34:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-07-04 13:24:47 +00:00
|
|
|
if (S_IFDIR != (s.st_mode & S_IFMT)) {
|
2003-07-03 14:34:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-04-15 11:40:40 +00:00
|
|
|
add_next_index_string(return_value, globbuf.gl_pathv[n]+cwd_skip);
|
2002-03-21 19:18:13 +00:00
|
|
|
}
|
2002-09-26 00:27:52 +00:00
|
|
|
|
2002-03-21 19:18:13 +00:00
|
|
|
globfree(&globbuf);
|
2007-09-19 22:37:58 +00:00
|
|
|
|
|
|
|
if (basedir_limit && !zend_hash_num_elements(Z_ARRVAL_P(return_value))) {
|
|
|
|
zval_dtor(return_value);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2002-03-21 19:18:13 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
#endif
|
1999-10-05 14:36:00 +00:00
|
|
|
|
2004-01-28 22:21:54 +00:00
|
|
|
/* {{{ proto array scandir(string dir [, int sorting_order [, resource context]])
|
2003-01-28 01:48:57 +00:00
|
|
|
List files & directories inside the specified path */
|
|
|
|
PHP_FUNCTION(scandir)
|
|
|
|
{
|
|
|
|
char *dirn;
|
2014-08-27 13:31:48 +00:00
|
|
|
size_t dirn_len;
|
2014-08-25 17:24:55 +00:00
|
|
|
zend_long flags = 0;
|
2014-03-02 14:47:59 +00:00
|
|
|
zend_string **namelist;
|
2003-01-28 01:48:57 +00:00
|
|
|
int n, i;
|
2004-01-28 22:21:54 +00:00
|
|
|
zval *zcontext = NULL;
|
|
|
|
php_stream_context *context = NULL;
|
2003-01-28 01:48:57 +00:00
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|lr", &dirn, &dirn_len, &flags, &zcontext) == FAILURE) {
|
2003-01-28 01:48:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-06-14 23:28:06 +00:00
|
|
|
if (dirn_len < 1) {
|
2014-12-13 22:06:14 +00:00
|
|
|
php_error_docref(NULL, E_WARNING, "Directory name cannot be empty");
|
2007-06-14 23:28:06 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-07-30 12:06:40 +00:00
|
|
|
if (zcontext) {
|
|
|
|
context = php_stream_context_from_zval(zcontext, 0);
|
|
|
|
}
|
2003-01-28 01:48:57 +00:00
|
|
|
|
2010-11-26 09:52:28 +00:00
|
|
|
if (flags == PHP_SCANDIR_SORT_ASCENDING) {
|
2004-01-28 22:21:54 +00:00
|
|
|
n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasort);
|
2010-11-26 09:52:28 +00:00
|
|
|
} else if (flags == PHP_SCANDIR_SORT_NONE) {
|
|
|
|
n = php_stream_scandir(dirn, &namelist, context, NULL);
|
2003-01-28 01:48:57 +00:00
|
|
|
} else {
|
2004-01-28 22:21:54 +00:00
|
|
|
n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasortr);
|
2003-01-28 01:48:57 +00:00
|
|
|
}
|
|
|
|
if (n < 0) {
|
2014-12-13 22:06:14 +00:00
|
|
|
php_error_docref(NULL, E_WARNING, "(errno %d): %s", errno, strerror(errno));
|
2004-01-28 22:21:54 +00:00
|
|
|
RETURN_FALSE;
|
2003-01-28 01:48:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2014-03-02 14:47:59 +00:00
|
|
|
add_next_index_str(return_value, namelist[i]);
|
2003-01-28 01:48:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n) {
|
2004-01-28 22:21:54 +00:00
|
|
|
efree(namelist);
|
2003-01-28 01:48:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-04-17 00:37:12 +00:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 13:29:31 +00:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
1999-04-17 00:37:12 +00:00
|
|
|
*/
|