Lines Matching refs:file_handle
103 static inline int zend_stream_is_mmap(zend_file_handle *file_handle) { /* {{{ */ in zend_stream_is_mmap() argument
104 return file_handle->type == ZEND_HANDLE_MAPPED; in zend_stream_is_mmap()
107 static size_t zend_stream_fsize(zend_file_handle *file_handle TSRMLS_DC) /* {{{ */ in zend_stream_fsize()
111 if (zend_stream_is_mmap(file_handle)) { in zend_stream_fsize()
112 return file_handle->handle.stream.mmap.len; in zend_stream_fsize()
114 if (file_handle->type == ZEND_HANDLE_STREAM || file_handle->type == ZEND_HANDLE_MAPPED) { in zend_stream_fsize()
115 return file_handle->handle.stream.fsizer(file_handle->handle.stream.handle TSRMLS_CC); in zend_stream_fsize()
117 if (file_handle->handle.fp && fstat(fileno(file_handle->handle.fp), &buf) == 0) { in zend_stream_fsize()
144 static int zend_stream_getc(zend_file_handle *file_handle TSRMLS_DC) /* {{{ */ in zend_stream_getc()
148 …if (file_handle->handle.stream.reader(file_handle->handle.stream.handle, &buf, sizeof(buf) TSRMLS_… in zend_stream_getc()
154 static size_t zend_stream_read(zend_file_handle *file_handle, char *buf, size_t len TSRMLS_DC) /* {… argument
156 if (!zend_stream_is_mmap(file_handle) && file_handle->handle.stream.isatty) {
166 …for (n = 0; n < len && (c = zend_stream_getc(file_handle TSRMLS_CC)) != EOF && c != 4 && c != '\n'…
168 for (n = 0; n < len && (c = zend_stream_getc(file_handle TSRMLS_CC)) != EOF && c != '\n'; ++n) {
178 return file_handle->handle.stream.reader(file_handle->handle.stream.handle, buf, len TSRMLS_CC);
181 ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t *len TSRMLS_DC) /*… argument
186 if (file_handle->type == ZEND_HANDLE_FILENAME) {
187 if (zend_stream_open(file_handle->filename, file_handle TSRMLS_CC) == FAILURE) {
192 switch (file_handle->type) {
194 file_handle->type = ZEND_HANDLE_FP;
195 file_handle->handle.fp = fdopen(file_handle->handle.fd, "rb");
198 if (!file_handle->handle.fp) {
201 memset(&file_handle->handle.stream.mmap, 0, sizeof(zend_mmap));
202 …file_handle->handle.stream.isatty = isatty(fileno((FILE *)file_handle->handle.stream.handle)) …
203 file_handle->handle.stream.reader = (zend_stream_reader_t)zend_stream_stdio_reader;
204 file_handle->handle.stream.closer = (zend_stream_closer_t)zend_stream_stdio_closer;
205 file_handle->handle.stream.fsizer = (zend_stream_fsizer_t)zend_stream_stdio_fsizer;
206 memset(&file_handle->handle.stream.mmap, 0, sizeof(file_handle->handle.stream.mmap));
213 file_handle->handle.stream.mmap.pos = 0;
214 *buf = file_handle->handle.stream.mmap.buf;
215 *len = file_handle->handle.stream.mmap.len;
222 size = zend_stream_fsize(file_handle TSRMLS_CC);
227 old_type = file_handle->type;
228 file_handle->type = ZEND_HANDLE_STREAM; /* we might still be _FP but we need fsize() work */
230 if (old_type == ZEND_HANDLE_FP && !file_handle->handle.stream.isatty && size) {
234 if (file_handle->handle.fp &&
238 … *buf = mmap(0, size + ZEND_MMAP_AHEAD, PROT_READ, MAP_PRIVATE, fileno(file_handle->handle.fp), 0);
240 long offset = ftell(file_handle->handle.fp);
241 file_handle->handle.stream.mmap.map = *buf;
247 file_handle->handle.stream.mmap.buf = *buf;
248 file_handle->handle.stream.mmap.len = size;
254 file_handle->handle.stream.mmap.map = 0;
255 file_handle->handle.stream.mmap.buf = *buf = safe_emalloc(1, size, ZEND_MMAP_AHEAD);
256 file_handle->handle.stream.mmap.len = zend_stream_read(file_handle, *buf, size TSRMLS_CC);
262 while ((read = zend_stream_read(file_handle, *buf + size, remain TSRMLS_CC)) > 0) {
271 file_handle->handle.stream.mmap.map = 0;
272 file_handle->handle.stream.mmap.len = size;
276 file_handle->handle.stream.mmap.buf = *buf;
279 if (file_handle->handle.stream.mmap.len == 0) {
281 file_handle->handle.stream.mmap.buf = *buf;
285 …memset(file_handle->handle.stream.mmap.buf + file_handle->handle.stream.mmap.len, 0, ZEND_MMAP_AHE…
290 file_handle->type = ZEND_HANDLE_MAPPED;
291 file_handle->handle.stream.mmap.pos = 0;
292 file_handle->handle.stream.mmap.old_handle = file_handle->handle.stream.handle;
293 file_handle->handle.stream.mmap.old_closer = file_handle->handle.stream.closer;
294 file_handle->handle.stream.handle = &file_handle->handle.stream;
295 file_handle->handle.stream.closer = (zend_stream_closer_t)zend_stream_mmap_closer;
297 *buf = file_handle->handle.stream.mmap.buf;
298 *len = file_handle->handle.stream.mmap.len;