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