diff options
author | Michael Wallner <mike@php.net> | 2013-09-17 10:50:49 +0200 |
---|---|---|
committer | Michael Wallner <mike@php.net> | 2013-09-17 10:50:49 +0200 |
commit | 1c15d70cbd91e3f502694a31704e959cf734d8da (patch) | |
tree | 922fc946cf4c9a151e268a7adea06a6a4f86ce2a /ext/standard/php_fopen_wrapper.c | |
parent | 52ff129607a7193cccbc6bdfbf1c1e8586e8d0d2 (diff) | |
parent | 2438490addfbfba51e12246a74588b2382caa08a (diff) | |
download | php-git-1c15d70cbd91e3f502694a31704e959cf734d8da.tar.gz |
Merge branch 'slim-postdata'
* slim-postdata:
slim post data
add NEWS entry; add simple test
more precise condition
make this work in vc11 too
Use int64_t and atoll() after discussion with johannes
ws
Patch for https://bugs.php.net/bug.php?id=44522 to allow uploading files above 2G.
Diffstat (limited to 'ext/standard/php_fopen_wrapper.c')
-rw-r--r-- | ext/standard/php_fopen_wrapper.c | 62 |
1 files changed, 28 insertions, 34 deletions
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index 0fb27baacd..ca0b92ebde 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -71,43 +71,20 @@ static size_t php_stream_input_write(php_stream *stream, const char *buf, size_t static size_t php_stream_input_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) /* {{{ */ { - off_t *position = (off_t*)stream->abstract; - size_t read_bytes = 0; - - if (!stream->eof) { - if (SG(request_info).raw_post_data) { /* data has already been read by a post handler */ - read_bytes = SG(request_info).raw_post_data_length - *position; - if (read_bytes <= count) { - stream->eof = 1; - } else { - read_bytes = count; - } - if (read_bytes) { - memcpy(buf, SG(request_info).raw_post_data + *position, read_bytes); - } - } else if (sapi_module.read_post) { - read_bytes = sapi_module.read_post(buf, count TSRMLS_CC); - if (read_bytes <= 0) { - stream->eof = 1; - read_bytes = 0; - } - /* Increment SG(read_post_bytes) only when something was actually read. */ - SG(read_post_bytes) += read_bytes; - } else { - stream->eof = 1; - } - } + php_stream *inner = stream->abstract; - *position += read_bytes; + if (inner && inner->ops->read) { + size_t read = inner->ops->read(inner, buf, count TSRMLS_CC); + stream->eof = inner->eof; + return read; + } - return read_bytes; + return -1; } /* }}} */ static int php_stream_input_close(php_stream *stream, int close_handle TSRMLS_DC) /* {{{ */ { - efree(stream->abstract); - return 0; } /* }}} */ @@ -118,13 +95,25 @@ static int php_stream_input_flush(php_stream *stream TSRMLS_DC) /* {{{ */ } /* }}} */ +static int php_stream_input_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC) /* {{{ */ +{ + php_stream *inner = stream->abstract; + + if (inner && inner->ops->seek) { + return inner->ops->seek(inner, offset, whence, newoffset TSRMLS_CC); + } + + return -1; +} +/* }}} */ + php_stream_ops php_stream_input_ops = { php_stream_input_write, php_stream_input_read, php_stream_input_close, php_stream_input_flush, "Input", - NULL, /* seek */ + php_stream_input_seek, NULL, /* cast */ NULL, /* stat */ NULL /* set_option */ @@ -210,7 +199,12 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa } return NULL; } - return php_stream_alloc(&php_stream_input_ops, ecalloc(1, sizeof(off_t)), 0, "rb"); + if (SG(request_info).request_body) { + php_stream_rewind(SG(request_info).request_body); + } else { + sapi_read_standard_form_data(TSRMLS_C); + } + return php_stream_alloc(&php_stream_input_ops, SG(request_info).request_body, 0, "rb"); } if (!strcasecmp(path, "stdin")) { @@ -259,8 +253,8 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa fd = dup(STDERR_FILENO); } } else if (!strncasecmp(path, "fd/", 3)) { - char *start, - *end; + const char *start; + char *end; long fildes_ori; int dtablesize; |