1--TEST--
2stream_copy_to_stream() tests
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.txt';
9
10$src = fopen($initial_file, 'r');
11stream_filter_append($src, "string.rot13", STREAM_FILTER_READ);
12
13$dest = fopen($new_file, 'w');
14var_dump(stream_copy_to_stream($src, $dest, 0));
15var_dump(ftell($src));
16var_dump(ftell($dest));
17fclose($src); fclose($dest);
18
19var_dump(file_get_contents($new_file));
20unlink($new_file);
21
22/* --- */
23
24$src = fopen($initial_file, 'r');
25stream_filter_append($src, "string.rot13", STREAM_FILTER_READ);
26
27$dest = fopen($new_file, 'w');
28var_dump(stream_copy_to_stream($src, $dest, -1));
29var_dump(ftell($src));
30var_dump(ftell($dest));
31fclose($src); fclose($dest);
32if (WIN) {
33  var_dump(str_replace("\r\n","\n", file_get_contents($new_file)));
34} else {
35  var_dump(file_get_contents($new_file));
36}
37unlink($new_file);
38
39/* --- */
40
41$src = fopen($initial_file, 'r');
42stream_filter_append($src, "string.rot13", STREAM_FILTER_READ);
43
44$dest = fopen($new_file, 'w');
45var_dump(stream_copy_to_stream($src, $dest));
46var_dump(ftell($src));
47var_dump(ftell($dest));
48fclose($src); fclose($dest);
49
50if (WIN) {
51  var_dump(str_replace("\r\n","\n", file_get_contents($new_file)));
52} else {
53  var_dump(file_get_contents($new_file));
54}
55unlink($new_file);
56
57/* --- */
58
59$src = fopen($initial_file, 'r');
60
61$dest = fopen($new_file, 'w');
62var_dump(stream_copy_to_stream($src, $dest));
63var_dump(ftell($src));
64var_dump(ftell($dest));
65fclose($src); fclose($dest);
66
67if (WIN) {
68  var_dump(str_replace("\r\n","\n", file_get_contents($new_file)));
69} else {
70  var_dump(file_get_contents($new_file));
71}
72unlink($new_file);
73
74/* --- */
75
76$src = fopen($initial_file, 'r');
77
78$dest = fopen($new_file, 'w');
79var_dump(stream_copy_to_stream($src, $dest, 1000000));
80var_dump(ftell($src));
81var_dump(ftell($dest));
82fclose($src); fclose($dest);
83
84if (WIN) {
85  var_dump(str_replace("\r\n","\n", file_get_contents($new_file)));
86} else {
87  var_dump(file_get_contents($new_file));
88}
89
90unlink($new_file);
91
92/* --- */
93
94$src = fopen($initial_file, 'r');
95
96$dest = fopen($new_file, 'w');
97var_dump(stream_copy_to_stream($src, $dest, 10));
98var_dump(ftell($src));
99var_dump(ftell($dest));
100fclose($src); fclose($dest);
101
102if (WIN) {
103  var_dump(str_replace("\r\n","\n", file_get_contents($new_file)));
104} else {
105  var_dump(file_get_contents($new_file));
106}
107unlink($new_file);
108
109/* --- */
110
111$src = fopen($initial_file, 'r');
112
113$dest = fopen($new_file, 'w');
114var_dump(stream_copy_to_stream($src, $dest, -1));
115var_dump(ftell($src));
116var_dump(ftell($dest));
117fclose($src); fclose($dest);
118
119if (WIN) {
120  var_dump(str_replace("\r\n","\n", file_get_contents($new_file)));
121} else {
122  var_dump(file_get_contents($new_file));
123}
124unlink($new_file);
125
126echo "Done\n";
127?>
128--EXPECTF--
129int(0)
130int(0)
131int(0)
132string(0) ""
133int(%d)
134int(134)
135int(134)
136string(134) "Nabgure qnl
137Jura gur cnvaf bs yvsr jba'g one zl jnl
138V'yy oernx gurfr punvaf
139Gung ubyq zr qbja
140V'yy grne lbh qbja vagb zl cevingr uryy
141"
142int(%d)
143int(134)
144int(134)
145string(134) "Nabgure qnl
146Jura gur cnvaf bs yvsr jba'g one zl jnl
147V'yy oernx gurfr punvaf
148Gung ubyq zr qbja
149V'yy grne lbh qbja vagb zl cevingr uryy
150"
151int(%d)
152int(134)
153int(134)
154string(134) "Another day
155When the pains of life won't bar my way
156I'll break these chains
157That hold me down
158I'll tear you down into my private hell
159"
160int(%d)
161int(134)
162int(134)
163string(134) "Another day
164When the pains of life won't bar my way
165I'll break these chains
166That hold me down
167I'll tear you down into my private hell
168"
169int(%d)
170int(10)
171int(10)
172string(10) "Another da"
173int(%d)
174int(134)
175int(134)
176string(134) "Another day
177When the pains of life won't bar my way
178I'll break these chains
179That hold me down
180I'll tear you down into my private hell
181"
182Done
183