spl_directory.h 5.7 KB

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