diff --git a/ext/standard/dir.c b/ext/standard/dir.c index 863ce00588a72..7426a7360eee1 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -20,6 +20,7 @@ #include "fopen_wrappers.h" #include "file.h" #include "php_dir.h" +#include "php_dir_int.h" #include "php_string.h" #include "php_scandir.h" #include "basic_functions.h" @@ -35,15 +36,6 @@ #include "win32/readdir.h" #endif - -#ifdef HAVE_GLOB -#ifndef PHP_WIN32 -#include -#else -#include "win32/glob.h" -#endif -#endif - typedef struct { zend_resource *default_dir; } php_dir_globals; @@ -117,6 +109,8 @@ PHP_MINIT_FUNCTION(dir) { static char dirsep_str[2], pathsep_str[2]; + register_dir_symbols(module_number); + dir_class_entry_ptr = register_class_Directory(); #ifdef ZTS @@ -131,64 +125,6 @@ PHP_MINIT_FUNCTION(dir) pathsep_str[1] = '\0'; REGISTER_STRING_CONSTANT("PATH_SEPARATOR", pathsep_str, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SCANDIR_SORT_ASCENDING", PHP_SCANDIR_SORT_ASCENDING, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SCANDIR_SORT_DESCENDING", PHP_SCANDIR_SORT_DESCENDING, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SCANDIR_SORT_NONE", PHP_SCANDIR_SORT_NONE, CONST_PERSISTENT); - -#ifdef HAVE_GLOB - -#ifdef GLOB_BRACE - REGISTER_LONG_CONSTANT("GLOB_BRACE", GLOB_BRACE, CONST_PERSISTENT); -#else -# define GLOB_BRACE 0 -#endif - -#ifdef GLOB_MARK - REGISTER_LONG_CONSTANT("GLOB_MARK", GLOB_MARK, CONST_PERSISTENT); -#else -# define GLOB_MARK 0 -#endif - -#ifdef GLOB_NOSORT - REGISTER_LONG_CONSTANT("GLOB_NOSORT", GLOB_NOSORT, CONST_PERSISTENT); -#else -# define GLOB_NOSORT 0 -#endif - -#ifdef GLOB_NOCHECK - REGISTER_LONG_CONSTANT("GLOB_NOCHECK", GLOB_NOCHECK, CONST_PERSISTENT); -#else -# define GLOB_NOCHECK 0 -#endif - -#ifdef GLOB_NOESCAPE - REGISTER_LONG_CONSTANT("GLOB_NOESCAPE", GLOB_NOESCAPE, CONST_PERSISTENT); -#else -# define GLOB_NOESCAPE 0 -#endif - -#ifdef GLOB_ERR - REGISTER_LONG_CONSTANT("GLOB_ERR", GLOB_ERR, CONST_PERSISTENT); -#else -# define GLOB_ERR 0 -#endif - -#ifndef GLOB_ONLYDIR -# define GLOB_ONLYDIR (1<<30) -# define GLOB_EMULATE_ONLYDIR -# define GLOB_FLAGMASK (~GLOB_ONLYDIR) -#else -# define GLOB_FLAGMASK (~0) -#endif - -/* 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) - - REGISTER_LONG_CONSTANT("GLOB_ONLYDIR", GLOB_ONLYDIR, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("GLOB_AVAILABLE_FLAGS", GLOB_AVAILABLE_FLAGS, CONST_PERSISTENT); - -#endif /* HAVE_GLOB */ - return SUCCESS; } /* }}} */ diff --git a/ext/standard/dir.stub.php b/ext/standard/dir.stub.php index 2c2ca05a66ff3..b0c12e011674d 100755 --- a/ext/standard/dir.stub.php +++ b/ext/standard/dir.stub.php @@ -2,6 +2,80 @@ /** @generate-class-entries */ +#ifdef HAVE_GLOB +#if (defined(GLOB_BRACE) && GLOB_BRACE != 0) +/** + * @var int + * @cvalue GLOB_BRACE + */ +const GLOB_BRACE = UNKNOWN; +#endif +#if (defined(GLOB_ERR) && GLOB_ERR != 0) +/** + * @var int + * @cvalue GLOB_ERR + */ +const GLOB_ERR = UNKNOWN; +#endif +#if (defined(GLOB_MARK) && GLOB_MARK != 0) +/** + * @var int + * @cvalue GLOB_MARK + */ +const GLOB_MARK = UNKNOWN; +#endif +#if (defined(GLOB_NOCHECK) && GLOB_NOCHECK != 0) +/** + * @var int + * @cvalue GLOB_NOCHECK + */ +const GLOB_NOCHECK = UNKNOWN; +#endif +#if (defined(GLOB_NOESCAPE) && GLOB_NOESCAPE != 0) +/** + * @var int + * @cvalue GLOB_NOESCAPE + */ +const GLOB_NOESCAPE = UNKNOWN; +#endif +#if (defined(GLOB_NOSORT) && GLOB_NOSORT != 0) +/** + * @var int + * @cvalue GLOB_NOSORT + */ +const GLOB_NOSORT = UNKNOWN; +#endif +#ifdef GLOB_ONLYDIR +/** + * @var int + * @cvalue GLOB_ONLYDIR + */ +const GLOB_ONLYDIR = UNKNOWN; +#endif +#ifdef GLOB_AVAILABLE_FLAGS +/** + * @var int + * @cvalue GLOB_AVAILABLE_FLAGS + */ +const GLOB_AVAILABLE_FLAGS = UNKNOWN; +#endif +#endif +/** + * @var int + * @cvalue PHP_SCANDIR_SORT_ASCENDING + */ +const SCANDIR_SORT_ASCENDING = UNKNOWN; +/** + * @var int + * @cvalue PHP_SCANDIR_SORT_DESCENDING + */ +const SCANDIR_SORT_DESCENDING = UNKNOWN; +/** + * @var int + * @cvalue PHP_SCANDIR_SORT_NONE + */ +const SCANDIR_SORT_NONE = UNKNOWN; + class Directory { public readonly string $path; diff --git a/ext/standard/dir_arginfo.h b/ext/standard/dir_arginfo.h index f46d0b2484e5a..e1889eac6ac48 100644 --- a/ext/standard/dir_arginfo.h +++ b/ext/standard/dir_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: b3890e798e609e306027b4717ce0c5e782884087 */ + * Stub hash: f2571fbbcff57095abcb846f148644e10b2db2e8 */ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_Directory_close, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() @@ -22,6 +22,37 @@ static const zend_function_entry class_Directory_methods[] = { ZEND_FE_END }; +static void register_dir_symbols(int module_number) +{ +#if defined(HAVE_GLOB) && (defined(GLOB_BRACE) && GLOB_BRACE != 0) + REGISTER_LONG_CONSTANT("GLOB_BRACE", GLOB_BRACE, CONST_PERSISTENT); +#endif +#if defined(HAVE_GLOB) && (defined(GLOB_ERR) && GLOB_ERR != 0) + REGISTER_LONG_CONSTANT("GLOB_ERR", GLOB_ERR, CONST_PERSISTENT); +#endif +#if defined(HAVE_GLOB) && (defined(GLOB_MARK) && GLOB_MARK != 0) + REGISTER_LONG_CONSTANT("GLOB_MARK", GLOB_MARK, CONST_PERSISTENT); +#endif +#if defined(HAVE_GLOB) && (defined(GLOB_NOCHECK) && GLOB_NOCHECK != 0) + REGISTER_LONG_CONSTANT("GLOB_NOCHECK", GLOB_NOCHECK, CONST_PERSISTENT); +#endif +#if defined(HAVE_GLOB) && (defined(GLOB_NOESCAPE) && GLOB_NOESCAPE != 0) + REGISTER_LONG_CONSTANT("GLOB_NOESCAPE", GLOB_NOESCAPE, CONST_PERSISTENT); +#endif +#if defined(HAVE_GLOB) && (defined(GLOB_NOSORT) && GLOB_NOSORT != 0) + REGISTER_LONG_CONSTANT("GLOB_NOSORT", GLOB_NOSORT, CONST_PERSISTENT); +#endif +#if defined(HAVE_GLOB) && defined(GLOB_ONLYDIR) + REGISTER_LONG_CONSTANT("GLOB_ONLYDIR", GLOB_ONLYDIR, CONST_PERSISTENT); +#endif +#if defined(HAVE_GLOB) && defined(GLOB_AVAILABLE_FLAGS) + REGISTER_LONG_CONSTANT("GLOB_AVAILABLE_FLAGS", GLOB_AVAILABLE_FLAGS, CONST_PERSISTENT); +#endif + REGISTER_LONG_CONSTANT("SCANDIR_SORT_ASCENDING", PHP_SCANDIR_SORT_ASCENDING, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SCANDIR_SORT_DESCENDING", PHP_SCANDIR_SORT_DESCENDING, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SCANDIR_SORT_NONE", PHP_SCANDIR_SORT_NONE, CONST_PERSISTENT); +} + static zend_class_entry *register_class_Directory(void) { zend_class_entry ce, *class_entry; diff --git a/ext/standard/php_dir_int.h b/ext/standard/php_dir_int.h new file mode 100644 index 0000000000000..df9a9078ee4a3 --- /dev/null +++ b/ext/standard/php_dir_int.h @@ -0,0 +1,65 @@ +/* + +----------------------------------------------------------------------+ + | Copyright (c) The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | https://www.php.net/license/3_01.txt | + | 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. | + +----------------------------------------------------------------------+ + */ + +#ifndef PHP_DIR_INT_H +#define PHP_DIR_INT_H + +#ifdef HAVE_GLOB +#ifndef PHP_WIN32 +#include +#else +#include "win32/glob.h" +#endif +#endif + +#ifdef HAVE_GLOB + +#ifndef GLOB_BRACE +#define GLOB_BRACE 0 +#endif + +#ifndef GLOB_ERR +#define GLOB_ERR 0 +#endif + +#ifndef GLOB_MARK +#define GLOB_MARK 0 +#endif + +#ifndef GLOB_NOCHECK +#define GLOB_NOCHECK 0 +#endif + +#ifndef GLOB_NOESCAPE +#define GLOB_NOESCAPE 0 +#endif + +#ifndef GLOB_NOSORT +#define GLOB_NOSORT 0 +#endif + +#ifndef GLOB_ONLYDIR +#define GLOB_ONLYDIR (1<<30) +#define GLOB_EMULATE_ONLYDIR +#define GLOB_FLAGMASK (~GLOB_ONLYDIR) +#else +#define GLOB_FLAGMASK (~0) +#endif + +/* 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) + +#endif /* HAVE_GLOB */ + +#endif /* PHP_DIR_INT_H */