Back to index

php5  5.3.10
Functions
php_dir.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 PHP_MINIT_FUNCTION (dir)
 PHP_RINIT_FUNCTION (dir)
 PHP_FUNCTION (opendir)
 PHP_FUNCTION (closedir)
 PHP_FUNCTION (chdir)
 PHP_FUNCTION (getcwd)
 PHP_FUNCTION (rewinddir)
 PHP_NAMED_FUNCTION (php_if_readdir)
 PHP_FUNCTION (getdir)
 PHP_FUNCTION (glob)
 PHP_FUNCTION (scandir)

Function Documentation

Definition at line 247 of file dir.c.

Here is the call graph for this function:

Definition at line 263 of file dir.c.

{
       zval *id = NULL, **tmp, *myself;
       php_stream *dirp;
       int rsrc_id;

       FETCH_DIRP();

       if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a valid Directory resource", dirp->rsrc_id);
              RETURN_FALSE;
       }

       rsrc_id = dirp->rsrc_id;
       zend_list_delete(dirp->rsrc_id);

       if (rsrc_id == DIRG(default_dir)) {
              php_set_default_dir(-1 TSRMLS_CC);
       }
}

Here is the call graph for this function:

Definition at line 319 of file dir.c.

{
       char *str;
       int ret, str_len;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
              RETURN_FALSE;
       }

       if (strlen(str) != str_len) {
              RETURN_FALSE;
       }

       if ((PG(safe_mode) && !php_checkuid(str, NULL, CHECKUID_CHECK_FILE_AND_DIR)) || php_check_open_basedir(str TSRMLS_CC)) {
              RETURN_FALSE;
       }
       ret = VCWD_CHDIR(str);
       
       if (ret != 0) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s (errno %d)", strerror(errno), errno);
              RETURN_FALSE;
       }

       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;
       }

       RETURN_TRUE;
}

Here is the call graph for this function:

Definition at line 357 of file dir.c.

{
       char path[MAXPATHLEN];
       char *ret=NULL;
       
       if (zend_parse_parameters_none() == FAILURE) {
              return;
       }

#if HAVE_GETCWD
       ret = VCWD_GETCWD(path, MAXPATHLEN);
#elif HAVE_GETWD
       ret = VCWD_GETWD(path);
#endif

       if (ret) {
              RETURN_STRING(path, 1);
       } else {
              RETURN_FALSE;
       }
}

Definition at line 382 of file dir.c.

{
       zval *id = NULL, **tmp, *myself;
       php_stream *dirp;
       
       FETCH_DIRP();

       if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a valid Directory resource", dirp->rsrc_id);
              RETURN_FALSE;
       }

       php_stream_rewinddir(dirp);
}
PHP_FUNCTION ( getdir  )

Definition at line 255 of file dir.c.

Here is the call graph for this function:

PHP_FUNCTION ( scandir  )

Definition at line 554 of file dir.c.

{
       char *dirn;
       int dirn_len;
       long flags = 0;
       char **namelist;
       int n, i;
       zval *zcontext = NULL;
       php_stream_context *context = NULL;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lr", &dirn, &dirn_len, &flags, &zcontext) == FAILURE) {
              return;
       }

       if (strlen(dirn) != dirn_len) {
              RETURN_FALSE;
       }

       if (dirn_len < 1) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Directory name cannot be empty");
              RETURN_FALSE;
       }

       if (zcontext) {
              context = php_stream_context_from_zval(zcontext, 0);
       }

       if (!flags) {
              n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasort);
       } else {
              n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasortr);
       }
       if (n < 0) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "(errno %d): %s", errno, strerror(errno));
              RETURN_FALSE;
       }
       
       array_init(return_value);

       for (i = 0; i < n; i++) {
              add_next_index_string(return_value, namelist[i], 0);
       }

       if (n) {
              efree(namelist);
       }
}

Here is the call graph for this function:

PHP_MINIT_FUNCTION ( dir  )

Definition at line 131 of file dir.c.

{
       static char dirsep_str[2], pathsep_str[2];
       zend_class_entry dir_class_entry;

       INIT_CLASS_ENTRY(dir_class_entry, "Directory", php_dir_class_functions);
       dir_class_entry_ptr = zend_register_internal_class(&dir_class_entry TSRMLS_CC);

#ifdef ZTS
       ts_allocate_id(&dir_globals_id, sizeof(php_dir_globals), NULL, NULL);
#endif

       dirsep_str[0] = DEFAULT_SLASH;
       dirsep_str[1] = '\0';
       REGISTER_STRING_CONSTANT("DIRECTORY_SEPARATOR", dirsep_str, CONST_CS|CONST_PERSISTENT);

       pathsep_str[0] = ZEND_PATHS_SEPARATOR;
       pathsep_str[1] = '\0';
       REGISTER_STRING_CONSTANT("PATH_SEPARATOR", pathsep_str, CONST_CS|CONST_PERSISTENT);

#ifdef HAVE_GLOB

#ifdef GLOB_BRACE
       REGISTER_LONG_CONSTANT("GLOB_BRACE", GLOB_BRACE, CONST_CS | CONST_PERSISTENT);
#else
# define GLOB_BRACE 0
#endif

#ifdef GLOB_MARK
       REGISTER_LONG_CONSTANT("GLOB_MARK", GLOB_MARK, CONST_CS | CONST_PERSISTENT);
#else
# define GLOB_MARK 0
#endif

#ifdef GLOB_NOSORT
       REGISTER_LONG_CONSTANT("GLOB_NOSORT", GLOB_NOSORT, CONST_CS | CONST_PERSISTENT);
#else 
# define GLOB_NOSORT 0
#endif

#ifdef GLOB_NOCHECK
       REGISTER_LONG_CONSTANT("GLOB_NOCHECK", GLOB_NOCHECK, CONST_CS | CONST_PERSISTENT);
#else 
# define GLOB_NOCHECK 0
#endif

#ifdef GLOB_NOESCAPE
       REGISTER_LONG_CONSTANT("GLOB_NOESCAPE", GLOB_NOESCAPE, CONST_CS | CONST_PERSISTENT);
#else 
# define GLOB_NOESCAPE 0
#endif

#ifdef GLOB_ERR
       REGISTER_LONG_CONSTANT("GLOB_ERR", GLOB_ERR, CONST_CS | 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_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("GLOB_AVAILABLE_FLAGS", GLOB_AVAILABLE_FLAGS, CONST_CS | CONST_PERSISTENT);

#endif /* HAVE_GLOB */

       return SUCCESS;
}

Here is the call graph for this function:

PHP_NAMED_FUNCTION ( php_if_readdir  )

Definition at line 400 of file dir.c.

{
       zval *id = NULL, **tmp, *myself;
       php_stream *dirp;
       php_stream_dirent entry;

       FETCH_DIRP();

       if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a valid Directory resource", dirp->rsrc_id);
              RETURN_FALSE;
       }

       if (php_stream_readdir(dirp, &entry)) {
              RETURN_STRINGL(entry.d_name, strlen(entry.d_name), 1);
       }
       RETURN_FALSE;
}
PHP_RINIT_FUNCTION ( dir  )

Definition at line 125 of file dir.c.

{
       DIRG(default_dir) = -1;
       return SUCCESS;
}