From fbd3eb6439de8c9dbf05b42449911f6206e10a50 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gustavo=20Andr=C3=A9=20dos=20Santos=20Lopes?= Date: Thu, 14 Oct 2010 02:39:21 +0000 Subject: [PATCH] - Ooops. Fixed tests for rev #304380 (stream_get_contents() related) and a small error. --- ext/standard/streamsfuncs.c | 2 +- ext/standard/tests/streams/bug46426.phpt | 20 +++++++++++-------- .../streams/stream_get_contents_001.phpt | 5 ++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 29a62fe076..a01c58c3fe 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -425,7 +425,7 @@ PHP_FUNCTION(stream_get_contents) php_stream_from_zval(stream, &zsrc); - if ((pos != 0L) && php_stream_seek(stream, pos, SEEK_CUR) < 0) { + if ((pos > 0L) && php_stream_seek(stream, pos, SEEK_CUR) < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek %ld bytes from current position in the stream", pos); RETURN_FALSE; } else if (pos < 0L) { diff --git a/ext/standard/tests/streams/bug46426.phpt b/ext/standard/tests/streams/bug46426.phpt index 80dbcded80..cd3c3254ef 100644 --- a/ext/standard/tests/streams/bug46426.phpt +++ b/ext/standard/tests/streams/bug46426.phpt @@ -7,19 +7,23 @@ $tmp = tmpfile(); fwrite($tmp, b"12345"); -echo stream_get_contents($tmp, 2, 1); +fseek($tmp, 0); +echo stream_get_contents($tmp, 2, 1); //23 echo "\n"; -echo stream_get_contents($tmp, -1); +echo stream_get_contents($tmp, -1); //45 echo "\n"; -echo stream_get_contents($tmp, -1, 0); +fseek($tmp, -1, SEEK_CUR); +echo stream_get_contents($tmp, -1, 0); //5 echo "\n"; -echo stream_get_contents($tmp, -1, 2); +fseek($tmp, 0); +echo stream_get_contents($tmp, -1, 2); //345 echo "\n"; -echo stream_get_contents($tmp, 0, 0); +fseek($tmp, 0); +echo stream_get_contents($tmp, 0, 0); //"" echo "\n"; -echo stream_get_contents($tmp, 1, 0); +echo stream_get_contents($tmp, 1, 0); //1 echo "\n"; -echo stream_get_contents($tmp, -1); +echo stream_get_contents($tmp, -1); //2345 @unlink($tmp); @@ -27,7 +31,7 @@ echo stream_get_contents($tmp, -1); --EXPECT-- 23 45 -12345 +5 345 1 diff --git a/ext/standard/tests/streams/stream_get_contents_001.phpt b/ext/standard/tests/streams/stream_get_contents_001.phpt index e8e1c3d26b..0b7db1fbcb 100644 --- a/ext/standard/tests/streams/stream_get_contents_001.phpt +++ b/ext/standard/tests/streams/stream_get_contents_001.phpt @@ -9,14 +9,17 @@ fwrite($tmp, b"12345"); echo stream_get_contents($tmp, 2, 5), "--\n"; echo stream_get_contents($tmp, 2), "--\n"; +fseek($tmp, 0); echo stream_get_contents($tmp, 2, 3), "--\n"; echo stream_get_contents($tmp, 2, -1), "--\n"; @unlink($tmp); ?> ---EXPECT-- +--EXPECTF-- -- -- 45-- + +Warning: stream_get_contents(): Number of bytes to seek must be non-negative, given -1 in %s on line %d -- -- 2.40.0