1--TEST--
2stream_copy_to_stream() tests with interleaved read/write calls
3--FILE--
4<?php
5define('WIN', substr(PHP_OS, 0, 3) == 'WIN');
6
7$initial_file = __DIR__.'/bug38086.txt';
8$new_file = __DIR__.'/stream_copy_to_stream_interleaved.txt';
9
10$src = fopen($initial_file, 'r');
11
12$dest = fopen($new_file, 'w');
13
14var_dump(fread($src, 10));
15var_dump(fwrite($dest, "foo"));
16var_dump(stream_copy_to_stream($src, $dest, 10));
17var_dump(ftell($src));
18var_dump(ftell($dest));
19var_dump(fread($src, 10));
20var_dump(fwrite($dest, "bar"));
21var_dump(stream_copy_to_stream($src, $dest, 10));
22var_dump(ftell($src));
23var_dump(ftell($dest));
24fclose($src); fclose($dest);
25
26if (WIN) {
27  var_dump(str_replace("\r\n","\n", file_get_contents($new_file)));
28} else {
29  var_dump(file_get_contents($new_file));
30}
31unlink($new_file);
32
33echo "Done\n";
34?>
35--EXPECTF--
36string(10) "Another da"
37int(3)
38int(10)
39int(20)
40int(13)
41string(10) " pains of "
42int(3)
43int(10)
44int(40)
45int(26)
46string(26) "fooy
47When thebarlife won't"
48Done
49