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