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