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