1--TEST--
2Test fflush() function: usage variations - hard links as resource
3--SKIPIF--
4<?php
5if( substr(PHP_OS, 0, 3) == 'WIN')
6  die("skip not for Windows");
7?>
8--FILE--
9<?php
10
11/* test fflush() with handle to hard links as resource */
12
13$file_path = __DIR__;
14require $file_path.'/file.inc';
15
16echo "*** Testing fflush(): with hard links to files opened in diff modes ***\n";
17$file_types = array("empty", "numeric", "text", "text_with_new_line", "alphanumeric");
18$file_modes = array("w", "wb", "wt", "w+", "w+b","w+t",
19                    "a", "ab", "at", "a+","a+b", "a+t");
20
21$file_name = "$file_path/fflush_variation3.tmp";
22$link_name = "$file_path/lnk_fflush_variation3.tmp";
23
24$count = 1;
25
26foreach( $file_types as $type ) {
27  echo "-- Iteration $count with file containing $type data --\n";
28  foreach( $file_modes as $mode ) {
29
30    // creating the file
31    $file_handle = fopen($file_name, "w");
32    if($file_handle == false)
33      exit("Error:failed to open file $file_name");
34
35    // fill the fill with some data if mode is append mode
36    if( substr($mode, 0, 1) == "a" )
37      fill_file($file_handle, $type, 10);
38
39    // fclose($file_handle);
40
41    // creating hard link to the file
42    var_dump( link($file_name, $link_name) );
43
44    // opening the file in different modes
45    $file_handle = fopen($link_name, $mode);
46    if($file_handle == false)
47      exit("Error:failed to open link $link_name");
48
49    // writing data to the file
50    var_dump( fill_file($file_handle, $type, 50) );
51    var_dump( fflush($file_handle) );
52    fclose($file_handle);
53
54    // reading data from the file after flushing
55    var_dump( readfile($link_name) );
56
57    unlink($link_name);
58    unlink($file_name);
59  }
60  $count++;
61}
62
63echo "\n*** Done ***";
64?>
65--EXPECT--
66*** Testing fflush(): with hard links to files opened in diff modes ***
67-- Iteration 1 with file containing empty data --
68bool(true)
69bool(true)
70bool(true)
71int(0)
72bool(true)
73bool(true)
74bool(true)
75int(0)
76bool(true)
77bool(true)
78bool(true)
79int(0)
80bool(true)
81bool(true)
82bool(true)
83int(0)
84bool(true)
85bool(true)
86bool(true)
87int(0)
88bool(true)
89bool(true)
90bool(true)
91int(0)
92bool(true)
93bool(true)
94bool(true)
95int(0)
96bool(true)
97bool(true)
98bool(true)
99int(0)
100bool(true)
101bool(true)
102bool(true)
103int(0)
104bool(true)
105bool(true)
106bool(true)
107int(0)
108bool(true)
109bool(true)
110bool(true)
111int(0)
112bool(true)
113bool(true)
114bool(true)
115int(0)
116-- Iteration 2 with file containing numeric data --
117bool(true)
118bool(true)
119bool(true)
12022222222222222222222222222222222222222222222222222int(50)
121bool(true)
122bool(true)
123bool(true)
12422222222222222222222222222222222222222222222222222int(50)
125bool(true)
126bool(true)
127bool(true)
12822222222222222222222222222222222222222222222222222int(50)
129bool(true)
130bool(true)
131bool(true)
13222222222222222222222222222222222222222222222222222int(50)
133bool(true)
134bool(true)
135bool(true)
13622222222222222222222222222222222222222222222222222int(50)
137bool(true)
138bool(true)
139bool(true)
14022222222222222222222222222222222222222222222222222int(50)
141bool(true)
142bool(true)
143bool(true)
144222222222222222222222222222222222222222222222222222222222222int(60)
145bool(true)
146bool(true)
147bool(true)
148222222222222222222222222222222222222222222222222222222222222int(60)
149bool(true)
150bool(true)
151bool(true)
152222222222222222222222222222222222222222222222222222222222222int(60)
153bool(true)
154bool(true)
155bool(true)
156222222222222222222222222222222222222222222222222222222222222int(60)
157bool(true)
158bool(true)
159bool(true)
160222222222222222222222222222222222222222222222222222222222222int(60)
161bool(true)
162bool(true)
163bool(true)
164222222222222222222222222222222222222222222222222222222222222int(60)
165-- Iteration 3 with file containing text data --
166bool(true)
167bool(true)
168bool(true)
169text text text text text text text text text text int(50)
170bool(true)
171bool(true)
172bool(true)
173text text text text text text text text text text int(50)
174bool(true)
175bool(true)
176bool(true)
177text text text text text text text text text text int(50)
178bool(true)
179bool(true)
180bool(true)
181text text text text text text text text text text int(50)
182bool(true)
183bool(true)
184bool(true)
185text text text text text text text text text text int(50)
186bool(true)
187bool(true)
188bool(true)
189text text text text text text text text text text int(50)
190bool(true)
191bool(true)
192bool(true)
193text text text text text text text text text text text text int(60)
194bool(true)
195bool(true)
196bool(true)
197text text text text text text text text text text text text int(60)
198bool(true)
199bool(true)
200bool(true)
201text text text text text text text text text text text text int(60)
202bool(true)
203bool(true)
204bool(true)
205text text text text text text text text text text text text int(60)
206bool(true)
207bool(true)
208bool(true)
209text text text text text text text text text text text text int(60)
210bool(true)
211bool(true)
212bool(true)
213text text text text text text text text text text text text int(60)
214-- Iteration 4 with file containing text_with_new_line data --
215bool(true)
216bool(true)
217bool(true)
218line
219line of text
220line
221line of text
222line
223line of tint(50)
224bool(true)
225bool(true)
226bool(true)
227line
228line of text
229line
230line of text
231line
232line of tint(50)
233bool(true)
234bool(true)
235bool(true)
236line
237line of text
238line
239line of text
240line
241line of tint(50)
242bool(true)
243bool(true)
244bool(true)
245line
246line of text
247line
248line of text
249line
250line of tint(50)
251bool(true)
252bool(true)
253bool(true)
254line
255line of text
256line
257line of text
258line
259line of tint(50)
260bool(true)
261bool(true)
262bool(true)
263line
264line of text
265line
266line of text
267line
268line of tint(50)
269bool(true)
270bool(true)
271bool(true)
272line
273line line
274line of text
275line
276line of text
277line
278line of tint(60)
279bool(true)
280bool(true)
281bool(true)
282line
283line line
284line of text
285line
286line of text
287line
288line of tint(60)
289bool(true)
290bool(true)
291bool(true)
292line
293line line
294line of text
295line
296line of text
297line
298line of tint(60)
299bool(true)
300bool(true)
301bool(true)
302line
303line line
304line of text
305line
306line of text
307line
308line of tint(60)
309bool(true)
310bool(true)
311bool(true)
312line
313line line
314line of text
315line
316line of text
317line
318line of tint(60)
319bool(true)
320bool(true)
321bool(true)
322line
323line line
324line of text
325line
326line of text
327line
328line of tint(60)
329-- Iteration 5 with file containing alphanumeric data --
330bool(true)
331bool(true)
332bool(true)
333ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
334bool(true)
335bool(true)
336bool(true)
337ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
338bool(true)
339bool(true)
340bool(true)
341ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
342bool(true)
343bool(true)
344bool(true)
345ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
346bool(true)
347bool(true)
348bool(true)
349ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
350bool(true)
351bool(true)
352bool(true)
353ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
354bool(true)
355bool(true)
356bool(true)
357ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
358bool(true)
359bool(true)
360bool(true)
361ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
362bool(true)
363bool(true)
364bool(true)
365ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
366bool(true)
367bool(true)
368bool(true)
369ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
370bool(true)
371bool(true)
372bool(true)
373ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
374bool(true)
375bool(true)
376bool(true)
377ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
378
379*** Done ***
380