1--TEST--
2Test fseek(), ftell() & rewind() functions : usage variations - all w and x modes, SEEK_END
3--SKIPIF--
4<?php
5if( substr(PHP_OS, 0, 3) != "WIN" )
6  die("skip.. only valid for Windows");
7?>
8--FILE--
9<?php
10// include the file.inc for common functions for test
11include ("file.inc");
12
13/* Testing fseek(),ftell(),rewind() functions
14     1. All  write and create with write modes
15     2. Testing fseek() with whence = SEEK_END
16*/
17echo "*** Testing fseek(), ftell(), rewind() : whence = SEEK_END & all r and a modes ***\n";
18
19$file_modes = array( "w","wb","wt","w+","w+b","w+t",
20                     "x","xb","xt","x+","x+b","x+t");
21$file_content_types = array( "text_with_new_line","alphanumeric");
22
23$offset = array(-1,0,1,512,600); // different offsets
24
25$filename = __DIR__."/fseek_ftell_rewind_variation8.tmp"; // this is name of the file created by create_files()
26
27/* open the file using $files_modes and perform fseek(),ftell() and rewind() on it */
28foreach($file_content_types as $file_content_type){
29  echo "\n-- File having data of type ". $file_content_type ." --\n";
30
31  foreach($file_modes as $file_mode) {
32    echo "-- File opened in mode ".$file_mode." --\n";
33    $file_handle = fopen($filename, $file_mode);
34    if (!$file_handle){
35      echo "Error: failed to fopen() file: $filename!";
36      exit();
37    }
38    $data_to_be_written="";
39    fill_buffer($data_to_be_written, $file_content_type, 512); //get the data of size 512
40    $data_to_be_written = $data_to_be_written;
41    fwrite($file_handle,$data_to_be_written);
42    rewind($file_handle);
43
44    foreach($offset as $count){
45      var_dump( fseek($file_handle,$count,SEEK_END) );
46      var_dump( ftell($file_handle) ); // confirm the file pointer position
47      var_dump( feof($file_handle) ); //ensure that file pointer is not at end
48    } //end of offset loop
49
50    //close the file and check the size
51    fclose($file_handle);
52    var_dump( filesize($filename) );
53
54    delete_file($filename); // delete file with name
55  } //end of file_mode loop
56} //end of file_content_types loop
57
58echo "Done\n";
59?>
60--EXPECT--
61*** Testing fseek(), ftell(), rewind() : whence = SEEK_END & all r and a modes ***
62
63-- File having data of type text_with_new_line --
64-- File opened in mode w --
65int(0)
66int(511)
67bool(false)
68int(0)
69int(512)
70bool(false)
71int(0)
72int(513)
73bool(false)
74int(0)
75int(1024)
76bool(false)
77int(0)
78int(1112)
79bool(false)
80int(512)
81-- File opened in mode wb --
82int(0)
83int(511)
84bool(false)
85int(0)
86int(512)
87bool(false)
88int(0)
89int(513)
90bool(false)
91int(0)
92int(1024)
93bool(false)
94int(0)
95int(1112)
96bool(false)
97int(512)
98-- File opened in mode wt --
99int(0)
100int(568)
101bool(false)
102int(0)
103int(569)
104bool(false)
105int(0)
106int(570)
107bool(false)
108int(0)
109int(1081)
110bool(false)
111int(0)
112int(1169)
113bool(false)
114int(569)
115-- File opened in mode w+ --
116int(0)
117int(511)
118bool(false)
119int(0)
120int(512)
121bool(false)
122int(0)
123int(513)
124bool(false)
125int(0)
126int(1024)
127bool(false)
128int(0)
129int(1112)
130bool(false)
131int(512)
132-- File opened in mode w+b --
133int(0)
134int(511)
135bool(false)
136int(0)
137int(512)
138bool(false)
139int(0)
140int(513)
141bool(false)
142int(0)
143int(1024)
144bool(false)
145int(0)
146int(1112)
147bool(false)
148int(512)
149-- File opened in mode w+t --
150int(0)
151int(568)
152bool(false)
153int(0)
154int(569)
155bool(false)
156int(0)
157int(570)
158bool(false)
159int(0)
160int(1081)
161bool(false)
162int(0)
163int(1169)
164bool(false)
165int(569)
166-- File opened in mode x --
167int(0)
168int(511)
169bool(false)
170int(0)
171int(512)
172bool(false)
173int(0)
174int(513)
175bool(false)
176int(0)
177int(1024)
178bool(false)
179int(0)
180int(1112)
181bool(false)
182int(512)
183-- File opened in mode xb --
184int(0)
185int(511)
186bool(false)
187int(0)
188int(512)
189bool(false)
190int(0)
191int(513)
192bool(false)
193int(0)
194int(1024)
195bool(false)
196int(0)
197int(1112)
198bool(false)
199int(512)
200-- File opened in mode xt --
201int(0)
202int(568)
203bool(false)
204int(0)
205int(569)
206bool(false)
207int(0)
208int(570)
209bool(false)
210int(0)
211int(1081)
212bool(false)
213int(0)
214int(1169)
215bool(false)
216int(569)
217-- File opened in mode x+ --
218int(0)
219int(511)
220bool(false)
221int(0)
222int(512)
223bool(false)
224int(0)
225int(513)
226bool(false)
227int(0)
228int(1024)
229bool(false)
230int(0)
231int(1112)
232bool(false)
233int(512)
234-- File opened in mode x+b --
235int(0)
236int(511)
237bool(false)
238int(0)
239int(512)
240bool(false)
241int(0)
242int(513)
243bool(false)
244int(0)
245int(1024)
246bool(false)
247int(0)
248int(1112)
249bool(false)
250int(512)
251-- File opened in mode x+t --
252int(0)
253int(568)
254bool(false)
255int(0)
256int(569)
257bool(false)
258int(0)
259int(570)
260bool(false)
261int(0)
262int(1081)
263bool(false)
264int(0)
265int(1169)
266bool(false)
267int(569)
268
269-- File having data of type alphanumeric --
270-- File opened in mode w --
271int(0)
272int(511)
273bool(false)
274int(0)
275int(512)
276bool(false)
277int(0)
278int(513)
279bool(false)
280int(0)
281int(1024)
282bool(false)
283int(0)
284int(1112)
285bool(false)
286int(512)
287-- File opened in mode wb --
288int(0)
289int(511)
290bool(false)
291int(0)
292int(512)
293bool(false)
294int(0)
295int(513)
296bool(false)
297int(0)
298int(1024)
299bool(false)
300int(0)
301int(1112)
302bool(false)
303int(512)
304-- File opened in mode wt --
305int(0)
306int(511)
307bool(false)
308int(0)
309int(512)
310bool(false)
311int(0)
312int(513)
313bool(false)
314int(0)
315int(1024)
316bool(false)
317int(0)
318int(1112)
319bool(false)
320int(512)
321-- File opened in mode w+ --
322int(0)
323int(511)
324bool(false)
325int(0)
326int(512)
327bool(false)
328int(0)
329int(513)
330bool(false)
331int(0)
332int(1024)
333bool(false)
334int(0)
335int(1112)
336bool(false)
337int(512)
338-- File opened in mode w+b --
339int(0)
340int(511)
341bool(false)
342int(0)
343int(512)
344bool(false)
345int(0)
346int(513)
347bool(false)
348int(0)
349int(1024)
350bool(false)
351int(0)
352int(1112)
353bool(false)
354int(512)
355-- File opened in mode w+t --
356int(0)
357int(511)
358bool(false)
359int(0)
360int(512)
361bool(false)
362int(0)
363int(513)
364bool(false)
365int(0)
366int(1024)
367bool(false)
368int(0)
369int(1112)
370bool(false)
371int(512)
372-- File opened in mode x --
373int(0)
374int(511)
375bool(false)
376int(0)
377int(512)
378bool(false)
379int(0)
380int(513)
381bool(false)
382int(0)
383int(1024)
384bool(false)
385int(0)
386int(1112)
387bool(false)
388int(512)
389-- File opened in mode xb --
390int(0)
391int(511)
392bool(false)
393int(0)
394int(512)
395bool(false)
396int(0)
397int(513)
398bool(false)
399int(0)
400int(1024)
401bool(false)
402int(0)
403int(1112)
404bool(false)
405int(512)
406-- File opened in mode xt --
407int(0)
408int(511)
409bool(false)
410int(0)
411int(512)
412bool(false)
413int(0)
414int(513)
415bool(false)
416int(0)
417int(1024)
418bool(false)
419int(0)
420int(1112)
421bool(false)
422int(512)
423-- File opened in mode x+ --
424int(0)
425int(511)
426bool(false)
427int(0)
428int(512)
429bool(false)
430int(0)
431int(513)
432bool(false)
433int(0)
434int(1024)
435bool(false)
436int(0)
437int(1112)
438bool(false)
439int(512)
440-- File opened in mode x+b --
441int(0)
442int(511)
443bool(false)
444int(0)
445int(512)
446bool(false)
447int(0)
448int(513)
449bool(false)
450int(0)
451int(1024)
452bool(false)
453int(0)
454int(1112)
455bool(false)
456int(512)
457-- File opened in mode x+t --
458int(0)
459int(511)
460bool(false)
461int(0)
462int(512)
463bool(false)
464int(0)
465int(513)
466bool(false)
467int(0)
468int(1024)
469bool(false)
470int(0)
471int(1112)
472bool(false)
473int(512)
474Done
475