import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / fseek_ftell_rewind_variation2-win32.php
blob91a40347a4e7f9e8f5bc49986430b14806537015
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 write and create with write modes
17 2. Testing fseek() without using argument whence
20 echo "*** Testing fseek(), ftell(), rewind() : default whence & all w and x modes ***\n";
21 $file_modes = array( "w","wb","wt","w+","w+b","w+t",
22 "x","xb","xt","x+","x+b","x+t");
23 $file_content_types = array( "text_with_new_line","alphanumeric");
25 $offset = array(-1, 0, 1, 513); // different offsets, including negative and beyond size
27 $filename = dirname(__FILE__)."/fseek_ftell_rewind_variation2.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 "\n-- 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 $file_handle = fopen($filename, $file_mode);
36 if (!$file_handle){
37 echo "Error: failed to fopen() file: $filename!";
38 exit();
40 $data_to_be_written="";
41 fill_buffer($data_to_be_written, $file_content_type, 512); //get the data of size 512
42 $data_to_be_written = $data_to_be_written;
43 fwrite($file_handle,(binary)$data_to_be_written);
44 rewind($file_handle);
46 echo "-- Testing fseek() without using argument whence --\n";
47 foreach($offset as $count){
48 var_dump( fseek($file_handle,$count) );
49 var_dump( ftell($file_handle) ); // confirm the file pointer position
50 var_dump( feof($file_handle) ); //ensure that file pointer is not at end
51 } //end of offset loop
53 //close the file and check the size
54 fclose($file_handle);
55 var_dump( filesize($filename) );
57 delete_file($filename); // delete file with name
58 } //end of file_mode loop
59 } //end of file_content_types loop
61 echo "Done\n";