@@ -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,17 +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
- handle -> free_filename = 0 ;
120
- memset (& handle -> handle .stream .mmap , 0 , sizeof (zend_mmap ));
121
92
122
- 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 ;
123
96
} /* }}} */
124
97
125
98
static int zend_stream_getc (zend_file_handle * file_handle ) /* {{{ */
@@ -134,7 +107,7 @@ static int zend_stream_getc(zend_file_handle *file_handle) /* {{{ */
134
107
135
108
static size_t zend_stream_read (zend_file_handle * file_handle , char * buf , size_t len ) /* {{{ */
136
109
{
137
- if (! zend_stream_is_mmap ( file_handle ) && file_handle -> handle .stream .isatty ) {
110
+ if (file_handle -> handle .stream .isatty ) {
138
111
int c = '*' ;
139
112
size_t n ;
140
113
@@ -155,35 +128,29 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
155
128
size_t size ;
156
129
zend_stream_type old_type ;
157
130
131
+ if (file_handle -> buf ) {
132
+ * buf = file_handle -> buf ;
133
+ * len = file_handle -> len ;
134
+ return SUCCESS ;
135
+ }
136
+
158
137
if (file_handle -> type == ZEND_HANDLE_FILENAME ) {
159
138
if (zend_stream_open (file_handle -> filename , file_handle ) == FAILURE ) {
160
139
return FAILURE ;
161
140
}
162
141
}
163
142
164
- switch (file_handle -> type ) {
165
- case ZEND_HANDLE_FP :
166
- if (!file_handle -> handle .fp ) {
167
- return FAILURE ;
168
- }
169
- memset (& file_handle -> handle .stream .mmap , 0 , sizeof (zend_mmap ));
170
- file_handle -> handle .stream .isatty = isatty (fileno ((FILE * )file_handle -> handle .stream .handle ));
171
- file_handle -> handle .stream .reader = (zend_stream_reader_t )zend_stream_stdio_reader ;
172
- file_handle -> handle .stream .closer = (zend_stream_closer_t )zend_stream_stdio_closer ;
173
- file_handle -> handle .stream .fsizer = (zend_stream_fsizer_t )zend_stream_stdio_fsizer ;
174
- memset (& file_handle -> handle .stream .mmap , 0 , sizeof (file_handle -> handle .stream .mmap ));
175
- /* no break; */
176
- case ZEND_HANDLE_STREAM :
177
- /* nothing to do */
178
- break ;
179
-
180
- case ZEND_HANDLE_MAPPED :
181
- * buf = file_handle -> handle .stream .mmap .buf ;
182
- * len = file_handle -> handle .stream .mmap .len ;
183
- return SUCCESS ;
184
-
185
- default :
143
+ if (file_handle -> type == ZEND_HANDLE_FP ) {
144
+ if (!file_handle -> handle .fp ) {
186
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 ;
187
154
}
188
155
189
156
size = zend_stream_fsize (file_handle );
@@ -195,8 +162,8 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
195
162
file_handle -> type = ZEND_HANDLE_STREAM ; /* we might still be _FP but we need fsize() work */
196
163
197
164
if (old_type == ZEND_HANDLE_FP && !file_handle -> handle .stream .isatty && size ) {
198
- file_handle -> handle . stream . mmap . buf = * buf = safe_emalloc (1 , size , ZEND_MMAP_AHEAD );
199
- 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 );
200
167
} else {
201
168
size_t read , remain = 4 * 1024 ;
202
169
* buf = emalloc (remain );
@@ -211,29 +178,22 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
211
178
remain = size ;
212
179
}
213
180
}
214
- file_handle -> handle . stream . mmap . len = size ;
181
+ file_handle -> len = size ;
215
182
if (size && remain < ZEND_MMAP_AHEAD ) {
216
183
* buf = safe_erealloc (* buf , size , 1 , ZEND_MMAP_AHEAD );
217
184
}
218
- file_handle -> handle . stream . mmap . buf = * buf ;
185
+ file_handle -> buf = * buf ;
219
186
}
220
187
221
- if (file_handle -> handle . stream . mmap . len == 0 ) {
188
+ if (file_handle -> len == 0 ) {
222
189
* buf = erealloc (* buf , ZEND_MMAP_AHEAD );
223
- file_handle -> handle . stream . mmap . buf = * buf ;
190
+ file_handle -> buf = * buf ;
224
191
}
225
192
226
- if (ZEND_MMAP_AHEAD ) {
227
- memset (file_handle -> handle .stream .mmap .buf + file_handle -> handle .stream .mmap .len , 0 , ZEND_MMAP_AHEAD );
228
- }
229
- file_handle -> type = ZEND_HANDLE_MAPPED ;
230
- file_handle -> handle .stream .mmap .old_handle = file_handle -> handle .stream .handle ;
231
- file_handle -> handle .stream .mmap .old_closer = file_handle -> handle .stream .closer ;
232
- file_handle -> handle .stream .handle = & file_handle -> handle .stream ;
233
- 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 );
234
194
235
- * buf = file_handle -> handle . stream . mmap . buf ;
236
- * len = file_handle -> handle . stream . mmap . len ;
195
+ * buf = file_handle -> buf ;
196
+ * len = file_handle -> len ;
237
197
238
198
return SUCCESS ;
239
199
} /* }}} */
@@ -245,7 +205,6 @@ ZEND_API void zend_file_handle_dtor(zend_file_handle *fh) /* {{{ */
245
205
fclose (fh -> handle .fp );
246
206
break ;
247
207
case ZEND_HANDLE_STREAM :
248
- case ZEND_HANDLE_MAPPED :
249
208
if (fh -> handle .stream .closer && fh -> handle .stream .handle ) {
250
209
fh -> handle .stream .closer (fh -> handle .stream .handle );
251
210
}
@@ -261,9 +220,9 @@ ZEND_API void zend_file_handle_dtor(zend_file_handle *fh) /* {{{ */
261
220
zend_string_release_ex (fh -> opened_path , 0 );
262
221
fh -> opened_path = NULL ;
263
222
}
264
- if (fh -> free_filename && fh -> filename ) {
265
- efree (( char * ) fh -> filename );
266
- fh -> filename = NULL ;
223
+ if (fh -> buf ) {
224
+ efree (fh -> buf );
225
+ fh -> buf = NULL ;
267
226
}
268
227
}
269
228
/* }}} */
@@ -278,11 +237,6 @@ ZEND_API int zend_compare_file_handles(zend_file_handle *fh1, zend_file_handle *
278
237
return fh1 -> handle .fp == fh2 -> handle .fp ;
279
238
case ZEND_HANDLE_STREAM :
280
239
return fh1 -> handle .stream .handle == fh2 -> handle .stream .handle ;
281
- case ZEND_HANDLE_MAPPED :
282
- return (fh1 -> handle .stream .handle == & fh1 -> handle .stream &&
283
- fh2 -> handle .stream .handle == & fh2 -> handle .stream &&
284
- fh1 -> handle .stream .mmap .old_handle == fh2 -> handle .stream .mmap .old_handle )
285
- || fh1 -> handle .stream .handle == fh2 -> handle .stream .handle ;
286
240
default :
287
241
return 0 ;
288
242
}
0 commit comments