xref: /PHP-7.2/Zend/zend_stream.h (revision 7a7ec01a)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1998-2018 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 /* $Id$ */
23 
24 #ifndef ZEND_STREAM_H
25 #define ZEND_STREAM_H
26 
27 #include <sys/types.h>
28 #include <sys/stat.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 size_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_FD,
42 	ZEND_HANDLE_FP,
43 	ZEND_HANDLE_STREAM,
44 	ZEND_HANDLE_MAPPED
45 } zend_stream_type;
46 
47 typedef struct _zend_mmap {
48 	size_t      len;
49 	size_t      pos;
50 	void        *map;
51 	char        *buf;
52 	void                  *old_handle;
53 	zend_stream_closer_t   old_closer;
54 } zend_mmap;
55 
56 typedef struct _zend_stream {
57 	void        *handle;
58 	int         isatty;
59 	zend_mmap   mmap;
60 	zend_stream_reader_t   reader;
61 	zend_stream_fsizer_t   fsizer;
62 	zend_stream_closer_t   closer;
63 } zend_stream;
64 
65 typedef struct _zend_file_handle {
66 	union {
67 		int           fd;
68 		FILE          *fp;
69 		zend_stream   stream;
70 	} handle;
71 	const char        *filename;
72 	zend_string       *opened_path;
73 	zend_stream_type  type;
74 	zend_bool free_filename;
75 } zend_file_handle;
76 
77 BEGIN_EXTERN_C()
78 ZEND_API int zend_stream_open(const char *filename, zend_file_handle *handle);
79 ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t *len);
80 ZEND_API void zend_file_handle_dtor(zend_file_handle *fh);
81 ZEND_API int zend_compare_file_handles(zend_file_handle *fh1, zend_file_handle *fh2);
82 END_EXTERN_C()
83 
84 #ifdef _WIN64
85 # define zend_fseek _fseeki64
86 # define zend_ftell _ftelli64
87 # define zend_lseek _lseeki64
88 # define zend_fstat _fstat64
89 # define zend_stat  _stat64
90 typedef struct __stat64 zend_stat_t;
91 #else
92 # define zend_fseek fseek
93 # define zend_ftell ftell
94 # define zend_lseek lseek
95 # define zend_fstat fstat
96 # define zend_stat stat
97 typedef struct stat zend_stat_t;
98 #endif
99 
100 #endif
101 
102 /*
103  * Local variables:
104  * tab-width: 4
105  * c-basic-offset: 4
106  * indent-tabs-mode: t
107  * End:
108  * vim600: sw=4 ts=4 fdm=marker
109  * vim<600: sw=4 ts=4
110  */
111