spl_directory.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 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. #ifndef SPL_DIRECTORY_H
  19. #define SPL_DIRECTORY_H
  20. #include "php.h"
  21. #include "php_spl.h"
  22. extern PHPAPI zend_class_entry *spl_ce_SplFileInfo;
  23. extern PHPAPI zend_class_entry *spl_ce_DirectoryIterator;
  24. extern PHPAPI zend_class_entry *spl_ce_FilesystemIterator;
  25. extern PHPAPI zend_class_entry *spl_ce_RecursiveDirectoryIterator;
  26. extern PHPAPI zend_class_entry *spl_ce_GlobIterator;
  27. extern PHPAPI zend_class_entry *spl_ce_SplFileObject;
  28. extern PHPAPI zend_class_entry *spl_ce_SplTempFileObject;
  29. PHP_MINIT_FUNCTION(spl_directory);
  30. typedef enum {
  31. SPL_FS_INFO, /* must be 0 */
  32. SPL_FS_DIR,
  33. SPL_FS_FILE
  34. } SPL_FS_OBJ_TYPE;
  35. typedef struct _spl_filesystem_object spl_filesystem_object;
  36. typedef void (*spl_foreign_dtor_t)(spl_filesystem_object *object);
  37. typedef void (*spl_foreign_clone_t)(spl_filesystem_object *src, spl_filesystem_object *dst);
  38. PHPAPI char* spl_filesystem_object_get_path(spl_filesystem_object *intern, size_t *len);
  39. typedef struct _spl_other_handler {
  40. spl_foreign_dtor_t dtor;
  41. spl_foreign_clone_t clone;
  42. } spl_other_handler;
  43. /* define an overloaded iterator structure */
  44. typedef struct {
  45. zend_object_iterator intern;
  46. zval current;
  47. void *object;
  48. } spl_filesystem_iterator;
  49. struct _spl_filesystem_object {
  50. void *oth;
  51. const spl_other_handler *oth_handler;
  52. char *_path;
  53. size_t _path_len;
  54. char *orig_path;
  55. char *file_name;
  56. size_t file_name_len;
  57. SPL_FS_OBJ_TYPE type;
  58. zend_long flags;
  59. zend_class_entry *file_class;
  60. zend_class_entry *info_class;
  61. union {
  62. struct {
  63. php_stream *dirp;
  64. php_stream_dirent entry;
  65. char *sub_path;
  66. size_t sub_path_len;
  67. int index;
  68. int is_recursive;
  69. zend_function *func_rewind;
  70. zend_function *func_next;
  71. zend_function *func_valid;
  72. } dir;
  73. struct {
  74. php_stream *stream;
  75. php_stream_context *context;
  76. zval *zcontext;
  77. char *open_mode;
  78. size_t open_mode_len;
  79. zval current_zval;
  80. char *current_line;
  81. size_t current_line_len;
  82. size_t max_line_len;
  83. zend_long current_line_num;
  84. zval zresource;
  85. zend_function *func_getCurr;
  86. char delimiter;
  87. char enclosure;
  88. char escape;
  89. } file;
  90. } u;
  91. zend_object std;
  92. };
  93. static inline spl_filesystem_object *spl_filesystem_from_obj(zend_object *obj) /* {{{ */ {
  94. return (spl_filesystem_object*)((char*)(obj) - XtOffsetOf(spl_filesystem_object, std));
  95. }
  96. /* }}} */
  97. #define Z_SPLFILESYSTEM_P(zv) spl_filesystem_from_obj(Z_OBJ_P((zv)))
  98. static inline spl_filesystem_iterator* spl_filesystem_object_to_iterator(spl_filesystem_object *obj)
  99. {
  100. spl_filesystem_iterator *it;
  101. it = ecalloc(1, sizeof(spl_filesystem_iterator));
  102. it->object = (void *)obj;
  103. zend_iterator_init(&it->intern);
  104. return it;
  105. }
  106. static inline spl_filesystem_object* spl_filesystem_iterator_to_object(spl_filesystem_iterator *it)
  107. {
  108. return (spl_filesystem_object*)it->object;
  109. }
  110. #define SPL_FILE_OBJECT_DROP_NEW_LINE 0x00000001 /* drop new lines */
  111. #define SPL_FILE_OBJECT_READ_AHEAD 0x00000002 /* read on rewind/next */
  112. #define SPL_FILE_OBJECT_SKIP_EMPTY 0x00000004 /* skip empty lines */
  113. #define SPL_FILE_OBJECT_READ_CSV 0x00000008 /* read via fgetcsv */
  114. #define SPL_FILE_OBJECT_MASK 0x0000000F /* read via fgetcsv */
  115. #define SPL_FILE_DIR_CURRENT_AS_FILEINFO 0x00000000 /* make RecursiveDirectoryTree::current() return SplFileInfo */
  116. #define SPL_FILE_DIR_CURRENT_AS_SELF 0x00000010 /* make RecursiveDirectoryTree::current() return getSelf() */
  117. #define SPL_FILE_DIR_CURRENT_AS_PATHNAME 0x00000020 /* make RecursiveDirectoryTree::current() return getPathname() */
  118. #define SPL_FILE_DIR_CURRENT_MODE_MASK 0x000000F0 /* mask RecursiveDirectoryTree::current() */
  119. #define SPL_FILE_DIR_CURRENT(intern,mode) ((intern->flags&SPL_FILE_DIR_CURRENT_MODE_MASK)==mode)
  120. #define SPL_FILE_DIR_KEY_AS_PATHNAME 0x00000000 /* make RecursiveDirectoryTree::key() return getPathname() */
  121. #define SPL_FILE_DIR_KEY_AS_FILENAME 0x00000100 /* make RecursiveDirectoryTree::key() return getFilename() */
  122. #define SPL_FILE_DIR_FOLLOW_SYMLINKS 0x00000200 /* make RecursiveDirectoryTree::hasChildren() follow symlinks */
  123. #define SPL_FILE_DIR_KEY_MODE_MASK 0x00000F00 /* mask RecursiveDirectoryTree::key() */
  124. #define SPL_FILE_DIR_KEY(intern,mode) ((intern->flags&SPL_FILE_DIR_KEY_MODE_MASK)==mode)
  125. #define SPL_FILE_DIR_SKIPDOTS 0x00001000 /* Tells whether it should skip dots or not */
  126. #define SPL_FILE_DIR_UNIXPATHS 0x00002000 /* Whether to unixify path separators */
  127. #define SPL_FILE_DIR_OTHERS_MASK 0x00003000 /* mask used for get/setFlags */
  128. #endif /* SPL_DIRECTORY_H */
  129. /*
  130. * Local Variables:
  131. * c-basic-offset: 4
  132. * tab-width: 4
  133. * End:
  134. * vim600: fdm=marker
  135. * vim: noet sw=4 ts=4
  136. */