Skip to content

Commit fbd3eb6

Browse files
committed
- Ooops. Fixed tests for rev #304380 (stream_get_contents() related) and a small error.
1 parent 1ee489f commit fbd3eb6

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

ext/standard/streamsfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ PHP_FUNCTION(stream_get_contents)
425425

426426
php_stream_from_zval(stream, &zsrc);
427427

428-
if ((pos != 0L) && php_stream_seek(stream, pos, SEEK_CUR) < 0) {
428+
if ((pos > 0L) && php_stream_seek(stream, pos, SEEK_CUR) < 0) {
429429
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek %ld bytes from current position in the stream", pos);
430430
RETURN_FALSE;
431431
} else if (pos < 0L) {

ext/standard/tests/streams/bug46426.phpt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,31 @@ $tmp = tmpfile();
77

88
fwrite($tmp, b"12345");
99

10-
echo stream_get_contents($tmp, 2, 1);
10+
fseek($tmp, 0);
11+
echo stream_get_contents($tmp, 2, 1); //23
1112
echo "\n";
12-
echo stream_get_contents($tmp, -1);
13+
echo stream_get_contents($tmp, -1); //45
1314
echo "\n";
14-
echo stream_get_contents($tmp, -1, 0);
15+
fseek($tmp, -1, SEEK_CUR);
16+
echo stream_get_contents($tmp, -1, 0); //5
1517
echo "\n";
16-
echo stream_get_contents($tmp, -1, 2);
18+
fseek($tmp, 0);
19+
echo stream_get_contents($tmp, -1, 2); //345
1720
echo "\n";
18-
echo stream_get_contents($tmp, 0, 0);
21+
fseek($tmp, 0);
22+
echo stream_get_contents($tmp, 0, 0); //""
1923
echo "\n";
20-
echo stream_get_contents($tmp, 1, 0);
24+
echo stream_get_contents($tmp, 1, 0); //1
2125
echo "\n";
22-
echo stream_get_contents($tmp, -1);
26+
echo stream_get_contents($tmp, -1); //2345
2327

2428
@unlink($tmp);
2529

2630
?>
2731
--EXPECT--
2832
23
2933
45
30-
12345
34+
5
3135
345
3236

3337
1

ext/standard/tests/streams/stream_get_contents_001.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ fwrite($tmp, b"12345");
99

1010
echo stream_get_contents($tmp, 2, 5), "--\n";
1111
echo stream_get_contents($tmp, 2), "--\n";
12+
fseek($tmp, 0);
1213
echo stream_get_contents($tmp, 2, 3), "--\n";
1314
echo stream_get_contents($tmp, 2, -1), "--\n";
1415

1516
@unlink($tmp);
1617

1718
?>
18-
--EXPECT--
19+
--EXPECTF--
1920
--
2021
--
2122
45--
23+
24+
Warning: stream_get_contents(): Number of bytes to seek must be non-negative, given -1 in %s on line %d
2225
--

0 commit comments

Comments
 (0)