import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / fseek_ftell_rewind_variation5.php
blob7e48bccfe6acf6c76c5aa36bf6b16b914887c547
1 <?php
2 /* Prototype: int fseek ( resource $handle, int $offset [, int $whence] );
3 Description: Seeks on a file pointer
5 Prototype: bool rewind ( resource $handle );
6 Description: Rewind the position of a file pointer
8 Prototype: int ftell ( resource $handle );
9 Description: Tells file pointer read/write position
12 // include the file.inc for common functions for test
13 include ("file.inc");
15 /* Testing fseek(),ftell(),rewind() functions
16 1. All read and append modes
17 2. Testing fseek() with whence = SEEK_CUR
19 echo "*** Testing fseek(), ftell(), rewind() : whence = SEEK_CUR & all r and a modes ***\n";
21 $file_modes = array( "r","rb","rt","r+","r+b","r+t",
22 "a","ab","at","a+","a+b","a+t");
23 $file_content_types = array( "text_with_new_line","alphanumeric");
25 $offset = array(-1, 0, 1, 512, 600);// different offsets
27 $filename = dirname(__FILE__)."/fseek_ftell_rewind_variation5.tmp"; // this is name of the file created by create_files()
29 /* open the file using $files_modes and perform fseek(),ftell() and rewind() on it */
30 foreach($file_content_types as $file_content_type){
31 echo "-- File having data of type ". $file_content_type ." --\n";
33 foreach($file_modes as $file_mode) {
34 echo "-- File opened in mode ".$file_mode." --\n";
35 create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 512, "w", "fseek_ftell_rewind_variation"
36 ,5,"bytes",".tmp"); //create a file with 512 bytes size
37 $file_handle = fopen($filename, $file_mode);
38 if (!$file_handle) {
39 echo "Error: failed to fopen() file: $filename!";
40 exit();
42 rewind($file_handle);
43 foreach($offset as $count){
44 var_dump( fseek($file_handle,$count,SEEK_CUR) );
45 var_dump( ftell($file_handle) ); // confirm the file pointer position
46 var_dump( feof($file_handle) ); //ensure that file pointer is not at end
47 } //end of offset loop
49 //close the file and check the size
50 fclose($file_handle);
51 var_dump( filesize($filename) );
53 delete_file($filename); // delete file with name
54 } //end of file_mode loop
55 } //end of file_content_types loop
57 echo "Done\n";