Skip to content

Move constants from dir.c to stub file #13312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 3 additions & 67 deletions ext/standard/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -35,15 +36,6 @@
#include "win32/readdir.h"
#endif


#ifdef HAVE_GLOB
#ifndef PHP_WIN32
#include <glob.h>
#else
#include "win32/glob.h"
#endif
#endif

typedef struct {
zend_resource *default_dir;
} php_dir_globals;
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
/* }}} */
Expand Down
74 changes: 74 additions & 0 deletions ext/standard/dir.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 32 additions & 1 deletion ext/standard/dir_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions ext/standard/php_dir_int.h
Original file line number Diff line number Diff line change
@@ -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 <glob.h>
#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 */