summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo André dos Santos Lopes <cataphract@php.net>2010-10-14 03:15:15 +0000
committerGustavo André dos Santos Lopes <cataphract@php.net>2010-10-14 03:15:15 +0000
commitc99251f87e822958e34b455511e22fd4c8c63cf1 (patch)
treeb9391874672b775d64fab6d195c669d1dcaf59b5
parentdb633fb71d9e48e3cbb955db682e1b79bd3aa8fc (diff)
downloadphp-git-c99251f87e822958e34b455511e22fd4c8c63cf1.tar.gz
- [DOC] Reverted rev #304382 and rev #304380, as I figured out a way to
fix the erratic behavior without breaking backwards compatibility. Namely, $offset retains SEEK_SET behavior but actually SEEK_CUR is passed to _php_stream_seek, if possible, by moving the offset stream->position bytes. - Addresses bug #53006.
-rw-r--r--ext/standard/streamsfuncs.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c
index bc4cd935a6..b15d3efef7 100644
--- a/ext/standard/streamsfuncs.c
+++ b/ext/standard/streamsfuncs.c
@@ -415,7 +415,7 @@ PHP_FUNCTION(stream_get_contents)
{
php_stream *stream;
zval *zsrc;
- long maxlen = PHP_STREAM_COPY_ALL, pos = 0;
+ long maxlen = PHP_STREAM_COPY_ALL, pos = -1L;
int len, newlen;
char *contents = NULL;
@@ -425,9 +425,19 @@ PHP_FUNCTION(stream_get_contents)
php_stream_from_zval(stream, &zsrc);
- if ((pos > 0 || (pos == 0 && ZEND_NUM_ARGS() > 2)) && php_stream_seek(stream, pos, SEEK_SET) < 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to position %ld in the stream", pos);
- RETURN_FALSE;
+ if (pos >= 0) {
+ int seek_res = 0;
+ if (pos > stream->position) {
+ /* use SEEK_CUR to allow emulation in streams that don't support seeking */
+ seek_res = php_stream_seek(stream, pos - stream->position, SEEK_CUR);
+ } else if (pos < stream->position) {
+ seek_res = php_stream_seek(stream, pos, SEEK_SET);
+ }
+
+ if (seek_res != 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to position %ld in the stream", pos);
+ RETURN_FALSE;
+ }
}
len = php_stream_copy_to_mem(stream, &contents, maxlen, 0);