zend_stream.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend 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.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Wez Furlong <wez@thebrainroom.com> |
  16. | Scott MacVicar <scottmac@php.net> |
  17. | Nuno Lopes <nlopess@php.net> |
  18. | Marcus Boerger <helly@php.net> |
  19. +----------------------------------------------------------------------+
  20. */
  21. #ifndef ZEND_STREAM_H
  22. #define ZEND_STREAM_H
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25. /* Lightweight stream implementation for the ZE scanners.
  26. * These functions are private to the engine.
  27. * */
  28. typedef size_t (*zend_stream_fsizer_t)(void* handle);
  29. typedef ssize_t (*zend_stream_reader_t)(void* handle, char *buf, size_t len);
  30. typedef void (*zend_stream_closer_t)(void* handle);
  31. #define ZEND_MMAP_AHEAD 32
  32. typedef enum {
  33. ZEND_HANDLE_FILENAME,
  34. ZEND_HANDLE_FP,
  35. ZEND_HANDLE_STREAM
  36. } zend_stream_type;
  37. typedef struct _zend_stream {
  38. void *handle;
  39. int isatty;
  40. zend_stream_reader_t reader;
  41. zend_stream_fsizer_t fsizer;
  42. zend_stream_closer_t closer;
  43. } zend_stream;
  44. typedef struct _zend_file_handle {
  45. union {
  46. FILE *fp;
  47. zend_stream stream;
  48. } handle;
  49. zend_string *filename;
  50. zend_string *opened_path;
  51. zend_uchar type; /* packed zend_stream_type */
  52. bool primary_script;
  53. bool in_list; /* added into CG(open_file) */
  54. char *buf;
  55. size_t len;
  56. } zend_file_handle;
  57. BEGIN_EXTERN_C()
  58. ZEND_API void zend_stream_init_fp(zend_file_handle *handle, FILE *fp, const char *filename);
  59. ZEND_API void zend_stream_init_filename(zend_file_handle *handle, const char *filename);
  60. ZEND_API void zend_stream_init_filename_ex(zend_file_handle *handle, zend_string *filename);
  61. ZEND_API zend_result zend_stream_open(zend_file_handle *handle);
  62. ZEND_API zend_result zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t *len);
  63. ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle);
  64. void zend_stream_init(void);
  65. void zend_stream_shutdown(void);
  66. END_EXTERN_C()
  67. #ifdef ZEND_WIN32
  68. # include "win32/ioutil.h"
  69. typedef php_win32_ioutil_stat_t zend_stat_t;
  70. #ifdef _WIN64
  71. # define zend_fseek _fseeki64
  72. # define zend_ftell _ftelli64
  73. # define zend_lseek _lseeki64
  74. # else
  75. # define zend_fseek fseek
  76. # define zend_ftell ftell
  77. # define zend_lseek lseek
  78. # endif
  79. # define zend_fstat php_win32_ioutil_fstat
  80. # define zend_stat php_win32_ioutil_stat
  81. #else
  82. typedef struct stat zend_stat_t;
  83. # define zend_fseek fseek
  84. # define zend_ftell ftell
  85. # define zend_lseek lseek
  86. # define zend_fstat fstat
  87. # define zend_stat stat
  88. #endif
  89. #endif