@@ -51,35 +51,11 @@ static size_t zend_stream_stdio_fsizer(void *handle) /* {{{ */
51
51
return 0 ;
52
52
} /* }}} */
53
53
54
- static void zend_stream_unmap (zend_stream * stream ) { /* {{{ */
55
- if (stream -> mmap .buf ) {
56
- efree (stream -> mmap .buf );
57
- }
58
- stream -> mmap .len = 0 ;
59
- stream -> mmap .buf = 0 ;
60
- stream -> handle = stream -> mmap .old_handle ;
61
- } /* }}} */
62
-
63
- static void zend_stream_mmap_closer (zend_stream * stream ) /* {{{ */
64
- {
65
- zend_stream_unmap (stream );
66
- if (stream -> mmap .old_closer && stream -> handle ) {
67
- stream -> mmap .old_closer (stream -> handle );
68
- }
69
- } /* }}} */
70
-
71
- static inline int zend_stream_is_mmap (zend_file_handle * file_handle ) { /* {{{ */
72
- return file_handle -> type == ZEND_HANDLE_MAPPED ;
73
- } /* }}} */
74
-
75
54
static size_t zend_stream_fsize (zend_file_handle * file_handle ) /* {{{ */
76
55
{
77
56
zend_stat_t buf ;
78
57
79
- if (zend_stream_is_mmap (file_handle )) {
80
- return file_handle -> handle .stream .mmap .len ;
81
- }
82
- if (file_handle -> type == ZEND_HANDLE_STREAM || file_handle -> type == ZEND_HANDLE_MAPPED ) {
58
+ if (file_handle -> type == ZEND_HANDLE_STREAM ) {
83
59
return file_handle -> handle .stream .fsizer (file_handle -> handle .stream .handle );
84
60
}
85
61
if (file_handle -> handle .fp && zend_fstat (fileno (file_handle -> handle .fp ), & buf ) == 0 ) {
@@ -109,16 +85,14 @@ ZEND_API void zend_stream_init_filename(zend_file_handle *handle, const char *fi
109
85
110
86
ZEND_API int zend_stream_open (const char * filename , zend_file_handle * handle ) /* {{{ */
111
87
{
88
+ zend_string * opened_path ;
112
89
if (zend_stream_open_function ) {
113
90
return zend_stream_open_function (filename , handle );
114
91
}
115
- handle -> type = ZEND_HANDLE_FP ;
116
- handle -> opened_path = NULL ;
117
- handle -> handle .fp = zend_fopen (filename , & handle -> opened_path );
118
- handle -> filename = filename ;
119
- memset (& handle -> handle .stream .mmap , 0 , sizeof (zend_mmap ));
120
92
121
- return (handle -> handle .fp ) ? SUCCESS : FAILURE ;
93
+ zend_stream_init_fp (handle , zend_fopen (filename , & opened_path ), filename );
94
+ handle -> opened_path = opened_path ;
95
+ return handle -> handle .fp ? SUCCESS : FAILURE ;
122
96
} /* }}} */
123
97
124
98
static int zend_stream_getc (zend_file_handle * file_handle ) /* {{{ */
@@ -133,7 +107,7 @@ static int zend_stream_getc(zend_file_handle *file_handle) /* {{{ */
133
107
134
108
static size_t zend_stream_read (zend_file_handle * file_handle , char * buf , size_t len ) /* {{{ */
135
109
{
136
- if (! zend_stream_is_mmap ( file_handle ) && file_handle -> handle .stream .isatty ) {
110
+ if (file_handle -> handle .stream .isatty ) {
137
111
int c = '*' ;
138
112
size_t n ;
139
113
@@ -154,35 +128,29 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
154
128
size_t size ;
155
129
zend_stream_type old_type ;
156
130
131
+ if (file_handle -> buf ) {
132
+ * buf = file_handle -> buf ;
133
+ * len = file_handle -> len ;
134
+ return SUCCESS ;
135
+ }
136
+
157
137
if (file_handle -> type == ZEND_HANDLE_FILENAME ) {
158
138
if (zend_stream_open (file_handle -> filename , file_handle ) == FAILURE ) {
159
139
return FAILURE ;
160
140
}
161
141
}
162
142
163
- switch (file_handle -> type ) {
164
- case ZEND_HANDLE_FP :
165
- if (!file_handle -> handle .fp ) {
166
- return FAILURE ;
167
- }
168
- memset (& file_handle -> handle .stream .mmap , 0 , sizeof (zend_mmap ));
169
- file_handle -> handle .stream .isatty = isatty (fileno ((FILE * )file_handle -> handle .stream .handle ));
170
- file_handle -> handle .stream .reader = (zend_stream_reader_t )zend_stream_stdio_reader ;
171
- file_handle -> handle .stream .closer = (zend_stream_closer_t )zend_stream_stdio_closer ;
172
- file_handle -> handle .stream .fsizer = (zend_stream_fsizer_t )zend_stream_stdio_fsizer ;
173
- memset (& file_handle -> handle .stream .mmap , 0 , sizeof (file_handle -> handle .stream .mmap ));
174
- /* no break; */
175
- case ZEND_HANDLE_STREAM :
176
- /* nothing to do */
177
- break ;
178
-
179
- case ZEND_HANDLE_MAPPED :
180
- * buf = file_handle -> handle .stream .mmap .buf ;
181
- * len = file_handle -> handle .stream .mmap .len ;
182
- return SUCCESS ;
183
-
184
- default :
143
+ if (file_handle -> type == ZEND_HANDLE_FP ) {
144
+ if (!file_handle -> handle .fp ) {
185
145
return FAILURE ;
146
+ }
147
+
148
+ file_handle -> type = ZEND_HANDLE_STREAM ;
149
+ file_handle -> handle .stream .handle = file_handle -> handle .fp ;
150
+ file_handle -> handle .stream .isatty = isatty (fileno ((FILE * )file_handle -> handle .stream .handle ));
151
+ file_handle -> handle .stream .reader = (zend_stream_reader_t )zend_stream_stdio_reader ;
152
+ file_handle -> handle .stream .closer = (zend_stream_closer_t )zend_stream_stdio_closer ;
153
+ file_handle -> handle .stream .fsizer = (zend_stream_fsizer_t )zend_stream_stdio_fsizer ;
186
154
}
187
155
188
156
size = zend_stream_fsize (file_handle );
@@ -194,8 +162,8 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
194
162
file_handle -> type = ZEND_HANDLE_STREAM ; /* we might still be _FP but we need fsize() work */
195
163
196
164
if (old_type == ZEND_HANDLE_FP && !file_handle -> handle .stream .isatty && size ) {
197
- file_handle -> handle . stream . mmap . buf = * buf = safe_emalloc (1 , size , ZEND_MMAP_AHEAD );
198
- file_handle -> handle . stream . mmap . len = zend_stream_read (file_handle , * buf , size );
165
+ file_handle -> buf = * buf = safe_emalloc (1 , size , ZEND_MMAP_AHEAD );
166
+ file_handle -> len = zend_stream_read (file_handle , * buf , size );
199
167
} else {
200
168
size_t read , remain = 4 * 1024 ;
201
169
* buf = emalloc (remain );
@@ -210,29 +178,22 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
210
178
remain = size ;
211
179
}
212
180
}
213
- file_handle -> handle . stream . mmap . len = size ;
181
+ file_handle -> len = size ;
214
182
if (size && remain < ZEND_MMAP_AHEAD ) {
215
183
* buf = safe_erealloc (* buf , size , 1 , ZEND_MMAP_AHEAD );
216
184
}
217
- file_handle -> handle . stream . mmap . buf = * buf ;
185
+ file_handle -> buf = * buf ;
218
186
}
219
187
220
- if (file_handle -> handle . stream . mmap . len == 0 ) {
188
+ if (file_handle -> len == 0 ) {
221
189
* buf = erealloc (* buf , ZEND_MMAP_AHEAD );
222
- file_handle -> handle . stream . mmap . buf = * buf ;
190
+ file_handle -> buf = * buf ;
223
191
}
224
192
225
- if (ZEND_MMAP_AHEAD ) {
226
- memset (file_handle -> handle .stream .mmap .buf + file_handle -> handle .stream .mmap .len , 0 , ZEND_MMAP_AHEAD );
227
- }
228
- file_handle -> type = ZEND_HANDLE_MAPPED ;
229
- file_handle -> handle .stream .mmap .old_handle = file_handle -> handle .stream .handle ;
230
- file_handle -> handle .stream .mmap .old_closer = file_handle -> handle .stream .closer ;
231
- file_handle -> handle .stream .handle = & file_handle -> handle .stream ;
232
- file_handle -> handle .stream .closer = (zend_stream_closer_t )zend_stream_mmap_closer ;
193
+ memset (file_handle -> buf + file_handle -> len , 0 , ZEND_MMAP_AHEAD );
233
194
234
- * buf = file_handle -> handle . stream . mmap . buf ;
235
- * len = file_handle -> handle . stream . mmap . len ;
195
+ * buf = file_handle -> buf ;
196
+ * len = file_handle -> len ;
236
197
237
198
return SUCCESS ;
238
199
} /* }}} */
@@ -244,7 +205,6 @@ ZEND_API void zend_file_handle_dtor(zend_file_handle *fh) /* {{{ */
244
205
fclose (fh -> handle .fp );
245
206
break ;
246
207
case ZEND_HANDLE_STREAM :
247
- case ZEND_HANDLE_MAPPED :
248
208
if (fh -> handle .stream .closer && fh -> handle .stream .handle ) {
249
209
fh -> handle .stream .closer (fh -> handle .stream .handle );
250
210
}
@@ -260,6 +220,10 @@ ZEND_API void zend_file_handle_dtor(zend_file_handle *fh) /* {{{ */
260
220
zend_string_release_ex (fh -> opened_path , 0 );
261
221
fh -> opened_path = NULL ;
262
222
}
223
+ if (fh -> buf ) {
224
+ efree (fh -> buf );
225
+ fh -> buf = NULL ;
226
+ }
263
227
}
264
228
/* }}} */
265
229
@@ -273,11 +237,6 @@ ZEND_API int zend_compare_file_handles(zend_file_handle *fh1, zend_file_handle *
273
237
return fh1 -> handle .fp == fh2 -> handle .fp ;
274
238
case ZEND_HANDLE_STREAM :
275
239
return fh1 -> handle .stream .handle == fh2 -> handle .stream .handle ;
276
- case ZEND_HANDLE_MAPPED :
277
- return (fh1 -> handle .stream .handle == & fh1 -> handle .stream &&
278
- fh2 -> handle .stream .handle == & fh2 -> handle .stream &&
279
- fh1 -> handle .stream .mmap .old_handle == fh2 -> handle .stream .mmap .old_handle )
280
- || fh1 -> handle .stream .handle == fh2 -> handle .stream .handle ;
281
240
default :
282
241
return 0 ;
283
242
}
0 commit comments