root/ext/spl/spl_directory.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. spl_filesystem_from_obj
  2. spl_filesystem_object_to_iterator
  3. spl_filesystem_iterator_to_object

   1 /*
   2    +----------------------------------------------------------------------+
   3    | PHP Version 7                                                        |
   4    +----------------------------------------------------------------------+
   5    | Copyright (c) 1997-2016 The PHP Group                                |
   6    +----------------------------------------------------------------------+
   7    | This source file is subject to version 3.01 of the PHP license,      |
   8    | that is bundled with this package in the file LICENSE, and is        |
   9    | available through the world-wide-web at the following url:           |
  10    | http://www.php.net/license/3_01.txt                                  |
  11    | If you did not receive a copy of the PHP license and are unable to   |
  12    | obtain it through the world-wide-web, please send a note to          |
  13    | license@php.net so we can mail you a copy immediately.               |
  14    +----------------------------------------------------------------------+
  15    | Authors: Marcus Boerger <helly@php.net>                              |
  16    +----------------------------------------------------------------------+
  17  */
  18 
  19 /* $Id$ */
  20 
  21 #ifndef SPL_DIRECTORY_H
  22 #define SPL_DIRECTORY_H
  23 
  24 #include "php.h"
  25 #include "php_spl.h"
  26 
  27 extern PHPAPI zend_class_entry *spl_ce_SplFileInfo;
  28 extern PHPAPI zend_class_entry *spl_ce_DirectoryIterator;
  29 extern PHPAPI zend_class_entry *spl_ce_FilesystemIterator;
  30 extern PHPAPI zend_class_entry *spl_ce_RecursiveDirectoryIterator;
  31 extern PHPAPI zend_class_entry *spl_ce_GlobIterator;
  32 extern PHPAPI zend_class_entry *spl_ce_SplFileObject;
  33 extern PHPAPI zend_class_entry *spl_ce_SplTempFileObject;
  34 
  35 PHP_MINIT_FUNCTION(spl_directory);
  36 
  37 typedef enum {
  38         SPL_FS_INFO, /* must be 0 */
  39         SPL_FS_DIR,
  40         SPL_FS_FILE
  41 } SPL_FS_OBJ_TYPE;
  42 
  43 typedef struct _spl_filesystem_object  spl_filesystem_object;
  44 
  45 typedef void (*spl_foreign_dtor_t)(spl_filesystem_object *object);
  46 typedef void (*spl_foreign_clone_t)(spl_filesystem_object *src, spl_filesystem_object *dst);
  47 
  48 PHPAPI char* spl_filesystem_object_get_path(spl_filesystem_object *intern, size_t *len);
  49 
  50 typedef struct _spl_other_handler {
  51         spl_foreign_dtor_t     dtor;
  52         spl_foreign_clone_t    clone;
  53 } spl_other_handler;
  54 
  55 /* define an overloaded iterator structure */
  56 typedef struct {
  57         zend_object_iterator  intern;
  58         zval                  current;
  59         void                 *object;
  60 } spl_filesystem_iterator;
  61 
  62 struct _spl_filesystem_object {
  63         void               *oth;
  64         spl_other_handler  *oth_handler;
  65         char               *_path;
  66         size_t             _path_len;
  67         char               *orig_path;
  68         char               *file_name;
  69         size_t             file_name_len;
  70         SPL_FS_OBJ_TYPE    type;
  71         zend_long               flags;
  72         zend_class_entry   *file_class;
  73         zend_class_entry   *info_class;
  74         union {
  75                 struct {
  76                         php_stream         *dirp;
  77                         php_stream_dirent  entry;
  78                         char               *sub_path;
  79                         size_t             sub_path_len;
  80                         int                index;
  81                         int                is_recursive;
  82                         zend_function      *func_rewind;
  83                         zend_function      *func_next;
  84                         zend_function      *func_valid;
  85                 } dir;
  86                 struct {
  87                         php_stream         *stream;
  88                         php_stream_context *context;
  89                         zval               *zcontext;
  90                         char               *open_mode;
  91                         size_t             open_mode_len;
  92                         zval               current_zval;
  93                         char               *current_line;
  94                         size_t             current_line_len;
  95                         size_t             max_line_len;
  96                         zend_long               current_line_num;
  97                         zval               zresource;
  98                         zend_function      *func_getCurr;
  99                         char               delimiter;
 100                         char               enclosure;
 101                         char               escape;
 102                 } file;
 103         } u;
 104         zend_object        std;
 105 };
 106 
 107 static inline spl_filesystem_object *spl_filesystem_from_obj(zend_object *obj) /* {{{ */ {
 108         return (spl_filesystem_object*)((char*)(obj) - XtOffsetOf(spl_filesystem_object, std));
 109 }
 110 /* }}} */
 111 
 112 #define Z_SPLFILESYSTEM_P(zv)  spl_filesystem_from_obj(Z_OBJ_P((zv)))
 113 
 114 static inline spl_filesystem_iterator* spl_filesystem_object_to_iterator(spl_filesystem_object *obj)
 115 {
 116         spl_filesystem_iterator    *it;
 117 
 118         it = ecalloc(1, sizeof(spl_filesystem_iterator));
 119         it->object = (void *)obj;
 120         zend_iterator_init(&it->intern);
 121         return it;
 122 }
 123 
 124 static inline spl_filesystem_object* spl_filesystem_iterator_to_object(spl_filesystem_iterator *it)
 125 {
 126         return (spl_filesystem_object*)it->object;
 127 }
 128 
 129 #define SPL_FILE_OBJECT_DROP_NEW_LINE      0x00000001 /* drop new lines */
 130 #define SPL_FILE_OBJECT_READ_AHEAD         0x00000002 /* read on rewind/next */
 131 #define SPL_FILE_OBJECT_SKIP_EMPTY         0x00000004 /* skip empty lines */
 132 #define SPL_FILE_OBJECT_READ_CSV           0x00000008 /* read via fgetcsv */
 133 #define SPL_FILE_OBJECT_MASK               0x0000000F /* read via fgetcsv */
 134 
 135 #define SPL_FILE_DIR_CURRENT_AS_FILEINFO   0x00000000 /* make RecursiveDirectoryTree::current() return SplFileInfo */
 136 #define SPL_FILE_DIR_CURRENT_AS_SELF       0x00000010 /* make RecursiveDirectoryTree::current() return getSelf() */
 137 #define SPL_FILE_DIR_CURRENT_AS_PATHNAME   0x00000020 /* make RecursiveDirectoryTree::current() return getPathname() */
 138 #define SPL_FILE_DIR_CURRENT_MODE_MASK     0x000000F0 /* mask RecursiveDirectoryTree::current() */
 139 #define SPL_FILE_DIR_CURRENT(intern,mode)  ((intern->flags&SPL_FILE_DIR_CURRENT_MODE_MASK)==mode)
 140 
 141 #define SPL_FILE_DIR_KEY_AS_PATHNAME       0x00000000 /* make RecursiveDirectoryTree::key() return getPathname() */
 142 #define SPL_FILE_DIR_KEY_AS_FILENAME       0x00000100 /* make RecursiveDirectoryTree::key() return getFilename() */
 143 #define SPL_FILE_DIR_FOLLOW_SYMLINKS       0x00000200 /* make RecursiveDirectoryTree::hasChildren() follow symlinks */
 144 #define SPL_FILE_DIR_KEY_MODE_MASK         0x00000F00 /* mask RecursiveDirectoryTree::key() */
 145 #define SPL_FILE_DIR_KEY(intern,mode)      ((intern->flags&SPL_FILE_DIR_KEY_MODE_MASK)==mode)
 146 
 147 #define SPL_FILE_DIR_SKIPDOTS              0x00001000 /* Tells whether it should skip dots or not */
 148 #define SPL_FILE_DIR_UNIXPATHS             0x00002000 /* Whether to unixify path separators */
 149 #define SPL_FILE_DIR_OTHERS_MASK           0x00003000 /* mask used for get/setFlags */
 150 
 151 #endif /* SPL_DIRECTORY_H */
 152 
 153 /*
 154  * Local Variables:
 155  * c-basic-offset: 4
 156  * tab-width: 4
 157  * End:
 158  * vim600: fdm=marker
 159  * vim: noet sw=4 ts=4
 160  */

/* [<][>][^][v][top][bottom][index][help] */