1--TEST--
2Test fflush() function: usage variations - 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 symbollic link */
12
13$file_path = __DIR__;
14require $file_path.'/file.inc';
15
16echo "*** Testing fflush(): with soft 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_variation2.tmp";
22$symlink_name = "$file_path/symlnk_fflush_variation2.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    echo "-- link opened in $mode mode --\n";
30
31    //creating the file
32    $file_handle = fopen($file_name, "w");
33    if($file_handle == false)
34      exit("Error:failed to open file $file_name");
35
36    //fill the file with some data if mode is append mode
37    if( substr($mode, 0, 1) == "a" )
38      fill_file($file_handle, $type, 10);
39
40    //close the file
41    fclose($file_handle);
42
43    // creating the sym link
44    var_dump( symlink($file_name, $symlink_name) );
45    $file_handle = fopen($symlink_name, $mode);
46    if($file_handle == false)
47      exit("Error:failed to open link $symlink_name");
48
49    // filling data into the file
50    var_dump( fill_file($file_handle, $type, 50) );
51    var_dump( fflush($file_handle) );
52    fclose($file_handle);
53
54    // reading the data from the file
55    var_dump( readfile($symlink_name) );
56
57    unlink($symlink_name);
58    unlink($file_name);
59  }
60  $count++;
61}
62
63echo "\n*** Done ***";
64?>
65--EXPECT--
66*** Testing fflush(): with soft links to files opened in diff modes ***
67-- Iteration 1 with file containing empty data --
68-- link opened in w mode --
69bool(true)
70bool(true)
71bool(true)
72int(0)
73-- link opened in wb mode --
74bool(true)
75bool(true)
76bool(true)
77int(0)
78-- link opened in wt mode --
79bool(true)
80bool(true)
81bool(true)
82int(0)
83-- link opened in w+ mode --
84bool(true)
85bool(true)
86bool(true)
87int(0)
88-- link opened in w+b mode --
89bool(true)
90bool(true)
91bool(true)
92int(0)
93-- link opened in w+t mode --
94bool(true)
95bool(true)
96bool(true)
97int(0)
98-- link opened in a mode --
99bool(true)
100bool(true)
101bool(true)
102int(0)
103-- link opened in ab mode --
104bool(true)
105bool(true)
106bool(true)
107int(0)
108-- link opened in at mode --
109bool(true)
110bool(true)
111bool(true)
112int(0)
113-- link opened in a+ mode --
114bool(true)
115bool(true)
116bool(true)
117int(0)
118-- link opened in a+b mode --
119bool(true)
120bool(true)
121bool(true)
122int(0)
123-- link opened in a+t mode --
124bool(true)
125bool(true)
126bool(true)
127int(0)
128-- Iteration 2 with file containing numeric data --
129-- link opened in w mode --
130bool(true)
131bool(true)
132bool(true)
13322222222222222222222222222222222222222222222222222int(50)
134-- link opened in wb mode --
135bool(true)
136bool(true)
137bool(true)
13822222222222222222222222222222222222222222222222222int(50)
139-- link opened in wt mode --
140bool(true)
141bool(true)
142bool(true)
14322222222222222222222222222222222222222222222222222int(50)
144-- link opened in w+ mode --
145bool(true)
146bool(true)
147bool(true)
14822222222222222222222222222222222222222222222222222int(50)
149-- link opened in w+b mode --
150bool(true)
151bool(true)
152bool(true)
15322222222222222222222222222222222222222222222222222int(50)
154-- link opened in w+t mode --
155bool(true)
156bool(true)
157bool(true)
15822222222222222222222222222222222222222222222222222int(50)
159-- link opened in a mode --
160bool(true)
161bool(true)
162bool(true)
163222222222222222222222222222222222222222222222222222222222222int(60)
164-- link opened in ab mode --
165bool(true)
166bool(true)
167bool(true)
168222222222222222222222222222222222222222222222222222222222222int(60)
169-- link opened in at mode --
170bool(true)
171bool(true)
172bool(true)
173222222222222222222222222222222222222222222222222222222222222int(60)
174-- link opened in a+ mode --
175bool(true)
176bool(true)
177bool(true)
178222222222222222222222222222222222222222222222222222222222222int(60)
179-- link opened in a+b mode --
180bool(true)
181bool(true)
182bool(true)
183222222222222222222222222222222222222222222222222222222222222int(60)
184-- link opened in a+t mode --
185bool(true)
186bool(true)
187bool(true)
188222222222222222222222222222222222222222222222222222222222222int(60)
189-- Iteration 3 with file containing text data --
190-- link opened in w mode --
191bool(true)
192bool(true)
193bool(true)
194text text text text text text text text text text int(50)
195-- link opened in wb mode --
196bool(true)
197bool(true)
198bool(true)
199text text text text text text text text text text int(50)
200-- link opened in wt mode --
201bool(true)
202bool(true)
203bool(true)
204text text text text text text text text text text int(50)
205-- link opened in w+ mode --
206bool(true)
207bool(true)
208bool(true)
209text text text text text text text text text text int(50)
210-- link opened in w+b mode --
211bool(true)
212bool(true)
213bool(true)
214text text text text text text text text text text int(50)
215-- link opened in w+t mode --
216bool(true)
217bool(true)
218bool(true)
219text text text text text text text text text text int(50)
220-- link opened in a mode --
221bool(true)
222bool(true)
223bool(true)
224text text text text text text text text text text text text int(60)
225-- link opened in ab mode --
226bool(true)
227bool(true)
228bool(true)
229text text text text text text text text text text text text int(60)
230-- link opened in at mode --
231bool(true)
232bool(true)
233bool(true)
234text text text text text text text text text text text text int(60)
235-- link opened in a+ mode --
236bool(true)
237bool(true)
238bool(true)
239text text text text text text text text text text text text int(60)
240-- link opened in a+b mode --
241bool(true)
242bool(true)
243bool(true)
244text text text text text text text text text text text text int(60)
245-- link opened in a+t mode --
246bool(true)
247bool(true)
248bool(true)
249text text text text text text text text text text text text int(60)
250-- Iteration 4 with file containing text_with_new_line data --
251-- link opened in w mode --
252bool(true)
253bool(true)
254bool(true)
255line
256line of text
257line
258line of text
259line
260line of tint(50)
261-- link opened in wb mode --
262bool(true)
263bool(true)
264bool(true)
265line
266line of text
267line
268line of text
269line
270line of tint(50)
271-- link opened in wt mode --
272bool(true)
273bool(true)
274bool(true)
275line
276line of text
277line
278line of text
279line
280line of tint(50)
281-- link opened in w+ mode --
282bool(true)
283bool(true)
284bool(true)
285line
286line of text
287line
288line of text
289line
290line of tint(50)
291-- link opened in w+b mode --
292bool(true)
293bool(true)
294bool(true)
295line
296line of text
297line
298line of text
299line
300line of tint(50)
301-- link opened in w+t mode --
302bool(true)
303bool(true)
304bool(true)
305line
306line of text
307line
308line of text
309line
310line of tint(50)
311-- link opened in a mode --
312bool(true)
313bool(true)
314bool(true)
315line
316line line
317line of text
318line
319line of text
320line
321line of tint(60)
322-- link opened in ab mode --
323bool(true)
324bool(true)
325bool(true)
326line
327line line
328line of text
329line
330line of text
331line
332line of tint(60)
333-- link opened in at mode --
334bool(true)
335bool(true)
336bool(true)
337line
338line line
339line of text
340line
341line of text
342line
343line of tint(60)
344-- link opened in a+ mode --
345bool(true)
346bool(true)
347bool(true)
348line
349line line
350line of text
351line
352line of text
353line
354line of tint(60)
355-- link opened in a+b mode --
356bool(true)
357bool(true)
358bool(true)
359line
360line line
361line of text
362line
363line of text
364line
365line of tint(60)
366-- link opened in a+t mode --
367bool(true)
368bool(true)
369bool(true)
370line
371line line
372line of text
373line
374line of text
375line
376line of tint(60)
377-- Iteration 5 with file containing alphanumeric data --
378-- link opened in w mode --
379bool(true)
380bool(true)
381bool(true)
382ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
383-- link opened in wb mode --
384bool(true)
385bool(true)
386bool(true)
387ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
388-- link opened in wt mode --
389bool(true)
390bool(true)
391bool(true)
392ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
393-- link opened in w+ mode --
394bool(true)
395bool(true)
396bool(true)
397ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
398-- link opened in w+b mode --
399bool(true)
400bool(true)
401bool(true)
402ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
403-- link opened in w+t mode --
404bool(true)
405bool(true)
406bool(true)
407ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
408-- link opened in a mode --
409bool(true)
410bool(true)
411bool(true)
412ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
413-- link opened in ab mode --
414bool(true)
415bool(true)
416bool(true)
417ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
418-- link opened in at mode --
419bool(true)
420bool(true)
421bool(true)
422ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
423-- link opened in a+ mode --
424bool(true)
425bool(true)
426bool(true)
427ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
428-- link opened in a+b mode --
429bool(true)
430bool(true)
431bool(true)
432ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
433-- link opened in a+t mode --
434bool(true)
435bool(true)
436bool(true)
437ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
438
439*** Done ***
440