zend_stream.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2016 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. /* $Id$ */
  22. #ifndef ZEND_STREAM_H
  23. #define ZEND_STREAM_H
  24. /* Lightweight stream implementation for the ZE scanners.
  25. * These functions are private to the engine.
  26. * */
  27. typedef size_t (*zend_stream_fsizer_t)(void* handle TSRMLS_DC);
  28. typedef size_t (*zend_stream_reader_t)(void* handle, char *buf, size_t len TSRMLS_DC);
  29. typedef void (*zend_stream_closer_t)(void* handle TSRMLS_DC);
  30. #define ZEND_MMAP_AHEAD 32
  31. typedef enum {
  32. ZEND_HANDLE_FILENAME,
  33. ZEND_HANDLE_FD,
  34. ZEND_HANDLE_FP,
  35. ZEND_HANDLE_STREAM,
  36. ZEND_HANDLE_MAPPED
  37. } zend_stream_type;
  38. typedef struct _zend_mmap {
  39. size_t len;
  40. size_t pos;
  41. void *map;
  42. char *buf;
  43. void *old_handle;
  44. zend_stream_closer_t old_closer;
  45. } zend_mmap;
  46. typedef struct _zend_stream {
  47. void *handle;
  48. int isatty;
  49. zend_mmap mmap;
  50. zend_stream_reader_t reader;
  51. zend_stream_fsizer_t fsizer;
  52. zend_stream_closer_t closer;
  53. } zend_stream;
  54. typedef struct _zend_file_handle {
  55. zend_stream_type type;
  56. const char *filename;
  57. char *opened_path;
  58. union {
  59. int fd;
  60. FILE *fp;
  61. zend_stream stream;
  62. } handle;
  63. zend_bool free_filename;
  64. } zend_file_handle;
  65. BEGIN_EXTERN_C()
  66. ZEND_API int zend_stream_open(const char *filename, zend_file_handle *handle TSRMLS_DC);
  67. ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t *len TSRMLS_DC);
  68. ZEND_API void zend_file_handle_dtor(zend_file_handle *fh TSRMLS_DC);
  69. ZEND_API int zend_compare_file_handles(zend_file_handle *fh1, zend_file_handle *fh2);
  70. END_EXTERN_C()
  71. #endif