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 22 #ifndef ZEND_STREAM_H 23 #define ZEND_STREAM_H 24 25 #include <sys/types.h> 26 #include <sys/stat.h> 27 28 #include "zend_types.h" 29 30 /* Lightweight stream implementation for the ZE scanners. 31 * These functions are private to the engine. 32 * */ 33 typedef size_t (*zend_stream_fsizer_t)(void* handle); 34 typedef ssize_t (*zend_stream_reader_t)(void* handle, char *buf, size_t len); 35 typedef void (*zend_stream_closer_t)(void* handle); 36 37 #define ZEND_MMAP_AHEAD 32 38 39 typedef enum { 40 ZEND_HANDLE_FILENAME, 41 ZEND_HANDLE_FP, 42 ZEND_HANDLE_STREAM 43 } zend_stream_type; 44 45 typedef struct _zend_stream { 46 void *handle; 47 int isatty; 48 zend_stream_reader_t reader; 49 zend_stream_fsizer_t fsizer; 50 zend_stream_closer_t closer; 51 } zend_stream; 52 53 typedef struct _zend_file_handle { 54 union { 55 FILE *fp; 56 zend_stream stream; 57 } handle; 58 zend_string *filename; 59 zend_string *opened_path; 60 uint8_t type; /* packed zend_stream_type */ 61 bool primary_script; 62 bool in_list; /* added into CG(open_file) */ 63 char *buf; 64 size_t len; 65 } zend_file_handle; 66 67 BEGIN_EXTERN_C() 68 ZEND_API void zend_stream_init_fp(zend_file_handle *handle, FILE *fp, const char *filename); 69 ZEND_API void zend_stream_init_filename(zend_file_handle *handle, const char *filename); 70 ZEND_API void zend_stream_init_filename_ex(zend_file_handle *handle, zend_string *filename); 71 ZEND_API zend_result zend_stream_open(zend_file_handle *handle); 72 ZEND_API zend_result zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t *len); 73 ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle); 74 75 void zend_stream_init(void); 76 void zend_stream_shutdown(void); 77 END_EXTERN_C() 78 79 #ifdef ZEND_WIN32 80 # include "win32/ioutil.h" 81 typedef php_win32_ioutil_stat_t zend_stat_t; 82 #ifdef _WIN64 83 # define zend_fseek _fseeki64 84 # define zend_ftell _ftelli64 85 # define zend_lseek _lseeki64 86 # else 87 # define zend_fseek fseek 88 # define zend_ftell ftell 89 # define zend_lseek lseek 90 # endif 91 # define zend_fstat php_win32_ioutil_fstat 92 # define zend_stat php_win32_ioutil_stat 93 #else 94 typedef struct stat zend_stat_t; 95 # define zend_fseek fseek 96 # define zend_ftell ftell 97 # define zend_lseek lseek 98 # define zend_fstat fstat 99 # define zend_stat stat 100 #endif 101 102 #endif 103