spl_directory.h 5.8 KB

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