--- /dev/null
+--TEST--
+Test fgetc() function : usage variations - read when file pointer at EOF
+--FILE--
+<?php
+/*
+ Prototype: string fgetc ( resource $handle );
+ Description: Gets character from file pointer
+*/
+// include the header for common test function
+include ("file.inc");
+
+echo "*** Testing fgetc() : usage variations ***\n";
+echo "-- Testing fgetc() with file whose file pointer is pointing to EOF --\n";
+// create a file
+create_files(dirname(__FILE__), 1, "text_with_new_line", 0755, 1, "w", "fgetc_variation");
+
+$filename = dirname(__FILE__)."/fgetc_variation1.tmp";
+
+// loop to check the file opened in different read modes
+$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t");
+$loop_counter =0;
+for(; $loop_counter < count($file_modes); $loop_counter++) {
+ // print the hearder
+ echo "-- File opened in mode : $file_modes[$loop_counter] --\n";
+ // open the file
+ $file_handle = fopen ($filename, $file_modes[$loop_counter]);
+ if (!$file_handle) {
+ echo "Error: failed to open file $filename! \n";
+ exit();
+ }
+
+ // seek to end of the file and try fgetc()
+ var_dump( fseek($file_handle, 0, SEEK_END) ); // set file pointer to eof
+ var_dump( feof($file_handle) ); // expected false
+ var_dump( ftell($file_handle) ); // ensure that file pointer is at eof
+ var_dump( fgetc($file_handle) ); // try n read a char, none expected
+ var_dump( feof($file_handle) ); // ensure thta file pointer is at eof
+ var_dump( ftell($file_handle) ); // file pointer position
+
+ // close the file handle
+ fclose($file_handle);
+}
+echo "Done\n";
+?>
+--CLEAN--
+<?php
+unlink( dirname(__FILE__)."/fgetc_variation1.tmp");
+?>
+--EXPECTF--
+*** Testing fgetc() : usage variations ***
+-- Testing fgetc() with file whose file pointer is pointing to EOF --
+-- File opened in mode : r --
+int(0)
+bool(false)
+int(1024)
+bool(false)
+bool(true)
+int(1024)
+-- File opened in mode : rb --
+int(0)
+bool(false)
+int(1024)
+bool(false)
+bool(true)
+int(1024)
+-- File opened in mode : rt --
+int(0)
+bool(false)
+int(1024)
+bool(false)
+bool(true)
+int(1024)
+-- File opened in mode : r+ --
+int(0)
+bool(false)
+int(1024)
+bool(false)
+bool(true)
+int(1024)
+-- File opened in mode : r+b --
+int(0)
+bool(false)
+int(1024)
+bool(false)
+bool(true)
+int(1024)
+-- File opened in mode : r+t --
+int(0)
+bool(false)
+int(1024)
+bool(false)
+bool(true)
+int(1024)
+Done
--- /dev/null
+--TEST--
+Test fgetc() function : usage variations - closed handle
+--FILE--
+<?php
+/*
+ Prototype: string fgetc ( resource $handle );
+ Description: Gets character from file pointer
+*/
+
+/* try reading a char using fgetc() using invalid handles
+ - closed file handle
+ - unset file handle
+*/
+
+// include the header for common test function
+include ("file.inc");
+
+echo "*** Testing fgetc() : usage variations ***\n";
+
+echo "-- Testing fgetc() with closed handle --\n";
+// open the file for reading
+$file_handle = fopen(__FILE__, "r");
+// close the file
+fclose($file_handle);
+
+// read from closed file
+var_dump( fgetc($file_handle) );
+
+echo "-- Testing fgetc() with unset handle --\n";
+// open the file for reading
+$file_handle = fopen(__FILE__, "r");
+// unset the file handle
+unset($file_handle);
+
+//fgetc using unset handle
+var_dump( fgetc($file_handle) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing fgetc() : usage variations ***
+-- Testing fgetc() with closed handle --
+
+Warning: fgetc(): 6 is not a valid stream resource in %s on line %d
+bool(false)
+-- Testing fgetc() with unset handle --
+
+Notice: Undefined variable: file_handle in %s on line %d
+
+Warning: fgetc(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+Done
+--UEXPECTF--
+*** Testing fgetc() : usage variations ***
+-- Testing fgetc() with closed handle --
+
+Warning: fgetc(): 6 is not a valid stream resource in %s on line %d
+bool(false)
+-- Testing fgetc() with unset handle --
+
+Notice: Undefined variable: file_handle in %s on line %d
+
+Warning: fgetc(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+Done
--- /dev/null
+--TEST--
+Test fgetc() function : usage variations - write only modes (fails, see bug#42036)
+--FILE--
+<?php
+/*
+ Prototype: string fgetc ( resource $handle );
+ Description: Gets character from file pointer
+*/
+
+/* try fgetc on files which are opened in non readable modes
+ w, wb, wt,
+ a, ab, at,
+ x, xb, xt
+*/
+// include the header for common test function
+include ("file.inc");
+
+echo "*** Testing fgetc() with file opened in write only mode ***\n";
+
+$file_modes = array("w", "wb", "wt", "a", "ab", "at", "x", "xb", "xt");
+$filename = dirname(__FILE__)."/fgetc_variation3.tmp";
+foreach ($file_modes as $file_mode ) {
+ echo "-- File opened in mode : $file_mode --\n";
+
+ $file_handle = fopen($filename, $file_mode);
+ if(!$file_handle) {
+ echo "Error: failed to open file $filename!\n";
+ exit();
+ }
+ $data = "fgetc_variation test";
+ fwrite($file_handle, $data);
+
+ // rewind the file pointer to begining of the file
+ var_dump( rewind($file_handle) );
+ var_dump( ftell($file_handle) );
+ var_dump( feof($file_handle) );
+
+ // read from file
+ var_dump( fgetc($file_handle) ); // expected : no chars should be read
+ var_dump( ftell($file_handle) ); // ensure that file pointer position is not changed
+ var_dump( feof($file_handle) ); // check if end of file pointer is set
+
+ // close the file
+ fclose($file_handle);
+
+ // delete the file
+ unlink($filename);
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing fgetc() with file opened in write only mode ***
+-- File opened in mode : w --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : wb --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : wt --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : a --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : ab --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : at --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : x --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : xb --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : xt --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+Done
--- /dev/null
+--TEST--
+Test fgetc() function : usage variations - different read modes
+--FILE--
+<?php
+/*
+ Prototype: string fgetc ( resource $handle );
+ Description: Gets character from file pointer
+*/
+
+/* read from fie using fgetc, file opened using different
+ read read modes */
+
+echo "*** Testing fgetc() : usage variations ***\n";
+echo "-- Testing fgetc() with files opened with different read modes --\n";
+
+$file_modes = array( "a+", "a+b", "a+t",
+ "x+", "x+b", "x+t",
+ "w+", "w+b", "w+t" );
+
+$filename = dirname(__FILE__)."/fgetc_variation4.tmp";
+foreach ($file_modes as $file_mode ) {
+ echo "-- File opened in mode : $file_mode --\n";
+
+ $file_handle = fopen($filename, $file_mode);
+ if(!$file_handle) {
+ echo "Error: failed to open file $filename!\n";
+ exit();
+ }
+ $data = "fgetc\n test";
+ fwrite($file_handle, $data);
+
+ // rewind the file pointer to begining of the file
+ var_dump( rewind($file_handle) );
+ var_dump( ftell($file_handle) );
+ var_dump( feof($file_handle) );
+
+ // read from file, atleast 7 chars
+ for($counter =0; $counter < 7; $counter ++) {
+ var_dump( fgetc($file_handle) ); // expected : 1 char
+ var_dump( ftell($file_handle) );
+ var_dump( feof($file_handle) ); // check if end of file pointer is set
+ }
+
+ // close the file
+ fclose($file_handle);
+
+ // delete the file
+ unlink($filename);
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+ *** Testing fgetc() : usage variations ***
+-- Testing fgetc() with files opened with different read modes --
+-- File opened in mode : a+ --
+bool(true)
+int(0)
+bool(false)
+string(1) "f"
+int(1)
+bool(false)
+string(1) "g"
+int(2)
+bool(false)
+string(1) "e"
+int(3)
+bool(false)
+string(1) "t"
+int(4)
+bool(false)
+string(1) "c"
+int(5)
+bool(false)
+string(1) "
+"
+int(6)
+bool(false)
+string(1) " "
+int(7)
+bool(false)
+-- File opened in mode : a+b --
+bool(true)
+int(0)
+bool(false)
+string(1) "f"
+int(1)
+bool(false)
+string(1) "g"
+int(2)
+bool(false)
+string(1) "e"
+int(3)
+bool(false)
+string(1) "t"
+int(4)
+bool(false)
+string(1) "c"
+int(5)
+bool(false)
+string(1) "
+"
+int(6)
+bool(false)
+string(1) " "
+int(7)
+bool(false)
+-- File opened in mode : a+t --
+bool(true)
+int(0)
+bool(false)
+string(1) "f"
+int(1)
+bool(false)
+string(1) "g"
+int(2)
+bool(false)
+string(1) "e"
+int(3)
+bool(false)
+string(1) "t"
+int(4)
+bool(false)
+string(1) "c"
+int(5)
+bool(false)
+string(1) "
+"
+int(6)
+bool(false)
+string(1) " "
+int(7)
+bool(false)
+-- File opened in mode : x+ --
+bool(true)
+int(0)
+bool(false)
+string(1) "f"
+int(1)
+bool(false)
+string(1) "g"
+int(2)
+bool(false)
+string(1) "e"
+int(3)
+bool(false)
+string(1) "t"
+int(4)
+bool(false)
+string(1) "c"
+int(5)
+bool(false)
+string(1) "
+"
+int(6)
+bool(false)
+string(1) " "
+int(7)
+bool(false)
+-- File opened in mode : x+b --
+bool(true)
+int(0)
+bool(false)
+string(1) "f"
+int(1)
+bool(false)
+string(1) "g"
+int(2)
+bool(false)
+string(1) "e"
+int(3)
+bool(false)
+string(1) "t"
+int(4)
+bool(false)
+string(1) "c"
+int(5)
+bool(false)
+string(1) "
+"
+int(6)
+bool(false)
+string(1) " "
+int(7)
+bool(false)
+-- File opened in mode : x+t --
+bool(true)
+int(0)
+bool(false)
+string(1) "f"
+int(1)
+bool(false)
+string(1) "g"
+int(2)
+bool(false)
+string(1) "e"
+int(3)
+bool(false)
+string(1) "t"
+int(4)
+bool(false)
+string(1) "c"
+int(5)
+bool(false)
+string(1) "
+"
+int(6)
+bool(false)
+string(1) " "
+int(7)
+bool(false)
+-- File opened in mode : w+ --
+bool(true)
+int(0)
+bool(false)
+string(1) "f"
+int(1)
+bool(false)
+string(1) "g"
+int(2)
+bool(false)
+string(1) "e"
+int(3)
+bool(false)
+string(1) "t"
+int(4)
+bool(false)
+string(1) "c"
+int(5)
+bool(false)
+string(1) "
+"
+int(6)
+bool(false)
+string(1) " "
+int(7)
+bool(false)
+-- File opened in mode : w+b --
+bool(true)
+int(0)
+bool(false)
+string(1) "f"
+int(1)
+bool(false)
+string(1) "g"
+int(2)
+bool(false)
+string(1) "e"
+int(3)
+bool(false)
+string(1) "t"
+int(4)
+bool(false)
+string(1) "c"
+int(5)
+bool(false)
+string(1) "
+"
+int(6)
+bool(false)
+string(1) " "
+int(7)
+bool(false)
+-- File opened in mode : w+t --
+bool(true)
+int(0)
+bool(false)
+string(1) "f"
+int(1)
+bool(false)
+string(1) "g"
+int(2)
+bool(false)
+string(1) "e"
+int(3)
+bool(false)
+string(1) "t"
+int(4)
+bool(false)
+string(1) "c"
+int(5)
+bool(false)
+string(1) "
+"
+int(6)
+bool(false)
+string(1) " "
+int(7)
+bool(false)
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test fgets() function : basic functionality
+--FILE--
+<?php
+/*
+ Prototype: string fgets ( resource $handle [, int $length] );
+ Description: Gets a line from file pointer
+*/
+
+// include the file.inc for common test funcitons
+include ("file.inc");
+
+$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t");
+
+$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
+
+echo "*** Testing fgets() : basic functionality ***\n";
+foreach($file_modes as $file_mode) {
+ echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
+ foreach($file_content_types as $file_content_type) {
+ echo "-- File content type : $file_content_type --\n";
+ /* create files with $file_content_type */
+ create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 50, "w", "fgets_basic", 1, "bytes"); //create a file
+ $filename = dirname(__FILE__)."/fgets_basic1.tmp"; // this is name of the file created by create_files()
+ $file_handle = fopen($filename, $file_mode);
+ if ( !$file_handle ) {
+ echo "Error: failed to open file $filename!";
+ exit();
+ }
+
+ echo "-- fgets() with default length, file pointer at 0 --\n";
+ var_dump( fgets($file_handle) ); // with default length
+ var_dump( ftell($file_handle) ); // ensure the file pointer position
+ var_dump( feof($file_handle) ); // enusre if eof set
+
+ echo "-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --\n";
+ var_dump( rewind($file_handle) );
+ var_dump( fgets($file_handle, 23) ); // expected: 22 chars
+ var_dump( ftell($file_handle) ); // ensure the file pointer position
+ var_dump( feof($file_handle) ); // enusre if eof set
+
+ //close file
+ fclose($file_handle);
+
+ // delete file
+ delete_file($filename);
+ } // file_content_type loop
+} // file_mode loop
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing fgets() : basic functionality ***
+
+-- Testing fgets() with file opened using mode r --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+
+-- Testing fgets() with file opened using mode rb --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+
+-- Testing fgets() with file opened using mode rt --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+
+-- Testing fgets() with file opened using mode r+ --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+
+-- Testing fgets() with file opened using mode r+b --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+
+-- Testing fgets() with file opened using mode r+t --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test fgets() function : error conditions
+--FILE--
+<?php
+/*
+ Prototype: string fgets ( resource $handle [, int $length] );
+ Description: Gets line from file pointer
+*/
+
+echo "*** Testing error conditions ***\n";
+// zero argument
+echo "-- Testing fgets() with zero argument --\n";
+var_dump( fgets() );
+
+// more than expected no. of args
+echo "-- Testing fgets() with more than expected number of arguments --\n";
+$fp = fopen(__FILE__, "r");
+var_dump( fgets($fp, 10, $fp) );
+
+// invalid length argument
+echo "-- Testing fgets() with invalid length arguments --\n";
+$len = 0;
+var_dump( fgets($fp, $len) );
+$len = -10;
+var_dump( fgets($fp, $len) );
+$len = 1;
+var_dump( fgets($fp, $len) ); // return length - 1 always, expect false
+
+
+// test invalid arguments : non-resources
+echo "-- Testing fgets() with invalid arguments --\n";
+$invalid_args = array (
+ "string",
+ 10,
+ 10.5,
+ true,
+ array(1,2,3),
+ new stdclass,
+);
+/* loop to test fgets() with different invalid type of args */
+for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
+ echo "-- Iteration $loop_counter --\n";
+ var_dump( fgets($invalid_args[$loop_counter - 1], 10) );
+}
+
+// fgets() on a file handle which is already closed
+echo "-- Testing fgets() with closed/unset file handle --";
+fclose($fp);
+var_dump(fgets($fp,10));
+
+// fgets() on a file handle which is unset
+$file_handle = fopen(__FILE__, "r");
+unset($file_handle); //unset file handle
+var_dump( fgets(@$file_handle,10));
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing error conditions ***
+-- Testing fgets() with zero argument --
+
+Warning: Wrong parameter count for fgets() in %s on line %d
+NULL
+-- Testing fgets() with more than expected number of arguments --
+
+Warning: Wrong parameter count for fgets() in %s on line %d
+NULL
+-- Testing fgets() with invalid length arguments --
+
+Warning: fgets(): Length parameter must be greater than 0 in %s on line %d
+bool(false)
+
+Warning: fgets(): Length parameter must be greater than 0 in %s on line %d
+bool(false)
+bool(false)
+-- Testing fgets() with invalid arguments --
+-- Iteration 1 --
+
+Warning: fgets(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+-- Iteration 2 --
+
+Warning: fgets(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+-- Iteration 3 --
+
+Warning: fgets(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+-- Iteration 4 --
+
+Warning: fgets(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+-- Iteration 5 --
+
+Warning: fgets(): supplied argument is not a valid stream resource in %s on line %s
+bool(false)
+-- Iteration 6 --
+
+Warning: fgets(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+-- Testing fgets() with closed/unset file handle --
+Warning: fgets(): 5 is not a valid stream resource in %s on line %d
+bool(false)
+
+Warning: fgets(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+Done
--- /dev/null
+--TEST--
+Test fgets() function : usage variations - write only modes(fails, see bug#42036)
+--FILE--
+<?php
+/*
+ Prototype: string fgets ( resource $handle [, int $length] );
+ Description: Gets a line from file pointer
+*/
+/* try fgets on files which are opened in non readable modes
+ w, wb, wt,
+ a, ab, at,
+ x, xb, xt
+*/
+// include the header for common test function
+include ("file.inc");
+
+echo "*** Testing fgets() with file opened in write only mode ***\n";
+
+$file_modes = array("w", "wb", "wt", "a", "ab", "at", "x", "xb", "xt");
+$filename = dirname(__FILE__)."/fgets_variation1.tmp";
+foreach ($file_modes as $file_mode ) {
+ echo "-- File opened in mode : $file_mode --\n";
+
+ $file_handle = fopen($filename, $file_mode);
+ if(!$file_handle) {
+ echo "Error: failed to open file $filename!\n";
+ exit();
+ }
+ $data = "fgets_variation test";
+ fwrite($file_handle, $data);
+
+ // rewind the file pointer to begining of the file
+ var_dump( rewind($file_handle) );
+ var_dump( ftell($file_handle) );
+ var_dump( feof($file_handle) );
+
+ // read from file
+ var_dump( fgets($file_handle) ); // expected : no chars should be read
+ var_dump( ftell($file_handle) ); // ensure that file pointer position is not changed
+ var_dump( feof($file_handle) ); // check if end of file pointer is set
+
+ // close the file
+ fclose($file_handle);
+
+ // delete the file
+ unlink($filename);
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing fgets() with file opened in write only mode ***
+-- File opened in mode : w --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : wb --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : wt --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : a --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : ab --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(true)
+-- File opened in mode : at --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : x --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : xb --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+-- File opened in mode : xt --
+bool(true)
+int(0)
+bool(false)
+bool(false)
+int(0)
+bool(false)
+Done
--- /dev/null
+--TEST--
+Test fgets() function : usage variations - closed handle
+--FILE--
+<?php
+/*
+ Prototype: string fgets ( resource $handle [, int $length] );
+ Description: Gets a line from file pointer
+*/
+
+/* try reading a line using fgets() using invalid handles
+ - closed file handle
+ - unset file handle
+*/
+
+// include the header for common test function
+include ("file.inc");
+
+echo "*** Testing fgets() : usage variations ***\n";
+
+echo "-- Testing fgets() with closed handle --\n";
+// open the file for reading
+$file_handle = fopen(__FILE__, "r");
+// close the file
+fclose($file_handle);
+
+// read from closed file
+var_dump( fgets($file_handle) ); // default length
+var_dump( fgets($file_handle, 10) ); // with specific length
+
+echo "-- Testing fgets() with unset handle --\n";
+// open the file for reading
+$file_handle = fopen(__FILE__, "r");
+// unset the file handle
+unset($file_handle);
+
+//fgets using unset handle
+var_dump( fgets($file_handle) ); // default length
+var_dump( fgets($file_handle, 10) ); // with specific length
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing fgets() : usage variations ***
+-- Testing fgets() with closed handle --
+
+Warning: fgets(): 6 is not a valid stream resource in %s on line %d
+bool(false)
+
+Warning: fgets(): 6 is not a valid stream resource in %s on line %d
+bool(false)
+-- Testing fgets() with unset handle --
+
+Notice: Undefined variable: file_handle in %s on line %d
+
+Warning: fgets(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+
+Notice: Undefined variable: file_handle in %s on line %d
+
+Warning: fgets(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test fgets() function : usage variations - read with/without length
+--FILE--
+<?php
+/*
+ Prototype: string fgets ( resource $handle [, int $length] );
+ Description: Gets a line from file pointer
+*/
+
+// include the file.inc for common test funcitons
+include ("file.inc");
+
+$file_modes = array("w+", "w+b", "w+t",
+ "a+", "a+b", "a+t",
+ "x+", "x+b", "x+t");
+
+$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
+
+echo "*** Testing fgets() : usage variations ***\n";
+
+$filename = dirname(__FILE__)."/fgets_variation3.tmp";
+
+foreach($file_modes as $file_mode) {
+ echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
+
+ foreach($file_content_types as $file_content_type) {
+ echo "-- File content type : $file_content_type --\n";
+
+ /* create files with $file_content_type */
+ $file_handle = fopen($filename, $file_mode);
+ $data = fill_file($file_handle, $file_content_type, 50);
+
+ if ( !$file_handle ) {
+ echo "Error: failed to open file $filename!";
+ exit();
+ }
+
+ echo "-- fgets() with default length, file pointer at 0 --\n";
+ // get the file pointer to begining of the file
+ rewind($file_handle);
+
+ var_dump( ftell($file_handle) );
+ var_dump( fgets($file_handle) ); // with default length
+ var_dump( ftell($file_handle) ); // ensure the file pointer position
+ var_dump( feof($file_handle) ); // enusre if eof set
+
+ echo "-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --\n";
+ // get the file pointer to begining of the file
+ rewind($file_handle);
+
+ var_dump( ftell($file_handle) );
+ var_dump( fgets($file_handle, 23) ); // expected: 22 chars
+ var_dump( ftell($file_handle) ); // ensure the file pointer position
+ var_dump( feof($file_handle) ); // enusre if eof set
+
+ //close file
+ fclose($file_handle);
+
+ // delete file
+ delete_file($filename);
+ } // file_content_type loop
+} // file_mode loop
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing fgets() : usage variations ***
+
+-- Testing fgets() with file opened using mode w+ --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+
+-- Testing fgets() with file opened using mode w+b --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+
+-- Testing fgets() with file opened using mode w+t --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+
+-- Testing fgets() with file opened using mode a+ --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+
+-- Testing fgets() with file opened using mode a+b --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+
+-- Testing fgets() with file opened using mode a+t --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+
+-- Testing fgets() with file opened using mode x+ --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+
+-- Testing fgets() with file opened using mode x+b --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+
+-- Testing fgets() with file opened using mode x+t --
+-- File content type : numeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "text text text text te"
+int(22)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+string(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test fgets() function : usage variations - seek n read
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) != 'WIN') {
+ die('skip only valid for Windows');
+}
+?>
+--FILE--
+<?php
+/*
+ Prototype: string fgets ( resource $handle [, int $length] );
+ Description: Gets a line from file pointer
+*/
+
+// include the file.inc for common test funcitons
+include ("file.inc");
+
+$file_modes = array("w+", "w+b", "w+t",
+ "a+", "a+b", "a+t",
+ "x+", "x+b", "x+t");
+
+$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
+
+echo "*** Testing fgets() : usage variations ***\n";
+
+$filename = dirname(__FILE__)."/fgets_variation4.tmp";
+
+foreach($file_modes as $file_mode) {
+ echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
+
+ foreach($file_content_types as $file_content_type) {
+ echo "-- File content type : $file_content_type --\n";
+
+ /* create files with $file_content_type */
+ $file_handle = fopen($filename, $file_mode);
+ $data = fill_file($file_handle, $file_content_type, 50);
+
+ if ( !$file_handle ) {
+ echo "Error: failed to open file $filename!";
+ exit();
+ }
+
+ echo "-- fgets() with location set by fseek() with default length --\n";
+ var_dump( fseek($file_handle, 5, SEEK_SET) );
+ var_dump( ftell($file_handle) );
+ var_dump( fgets($file_handle ) );
+ var_dump( ftell($file_handle) ); // ensure the file pointer position
+ var_dump( feof($file_handle) ); // enusre if eof set
+
+ echo "-- fgets() with location set by fseek() with length = 20 --\n";
+ var_dump( fseek($file_handle, 25, SEEK_SET) );
+ var_dump( ftell($file_handle) );
+ var_dump( fgets($file_handle, 20 ) ); // expected 19 chars
+ var_dump( ftell($file_handle) ); // ensure the file pointer position
+ var_dump( feof($file_handle) ); // enusre if eof set
+
+ //close file
+ fclose($file_handle);
+
+ // delete file
+ delete_file($filename);
+ } // file_content_type loop
+} // file_mode loop
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing fgets() : usage variations ***
+
+-- Testing fgets() with file opened using mode w+ --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode w+b --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode w+t --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(1) "
+"
+int(6)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(12) "ine of text
+"
+int(37)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode a+ --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode a+b --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode a+t --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(1) "
+"
+int(6)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(12) "ine of text
+"
+int(37)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode x+ --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode x+b --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode x+t --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(1) "
+"
+int(6)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(12) "ine of text
+"
+int(37)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+Done
--- /dev/null
+--TEST--
+Test fgets() function : usage variations - seek n read
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ die('skip Not valid for Windows');
+}
+?>
+--FILE--
+<?php
+/*
+ Prototype: string fgets ( resource $handle [, int $length] );
+ Description: Gets a line from file pointer
+*/
+
+// include the file.inc for common test funcitons
+include ("file.inc");
+
+$file_modes = array("w+", "w+b", "w+t",
+ "a+", "a+b", "a+t",
+ "x+", "x+b", "x+t");
+
+$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
+
+echo "*** Testing fgets() : usage variations ***\n";
+
+$filename = dirname(__FILE__)."/fgets_variation4.tmp";
+
+foreach($file_modes as $file_mode) {
+ echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
+
+ foreach($file_content_types as $file_content_type) {
+ echo "-- File content type : $file_content_type --\n";
+
+ /* create files with $file_content_type */
+ $file_handle = fopen($filename, $file_mode);
+ $data = fill_file($file_handle, $file_content_type, 50);
+
+ if ( !$file_handle ) {
+ echo "Error: failed to open file $filename!";
+ exit();
+ }
+
+ echo "-- fgets() with location set by fseek() with default length --\n";
+ var_dump( fseek($file_handle, 5, SEEK_SET) );
+ var_dump( ftell($file_handle) );
+ var_dump( fgets($file_handle ) );
+ var_dump( ftell($file_handle) ); // ensure the file pointer position
+ var_dump( feof($file_handle) ); // enusre if eof set
+
+ echo "-- fgets() with location set by fseek() with length = 20 --\n";
+ var_dump( fseek($file_handle, 25, SEEK_SET) );
+ var_dump( ftell($file_handle) );
+ var_dump( fgets($file_handle, 20 ) ); // expected 19 chars
+ var_dump( ftell($file_handle) ); // ensure the file pointer position
+ var_dump( feof($file_handle) ); // enusre if eof set
+
+ //close file
+ fclose($file_handle);
+
+ // delete file
+ delete_file($filename);
+ } // file_content_type loop
+} // file_mode loop
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing fgets() : usage variations ***
+
+-- Testing fgets() with file opened using mode w+ --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode w+b --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode w+t --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode a+ --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode a+b --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode a+t --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode x+ --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode x+b --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+
+-- Testing fgets() with file opened using mode x+t --
+-- File content type : numeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "text text text text text text text text text "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "text text text text"
+int(44)
+bool(false)
+-- File content type : text_with_new_line --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(11) "ne of text
+"
+int(36)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+string(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test fgets() function : usage variations - read beyond filesize
+--FILE--
+<?php
+/*
+ Prototype: string fgets ( resource $handle [, int $length] );
+ Description: Gets a line from file pointer
+*/
+
+// include the file.inc for common test funcitons
+include ("file.inc");
+
+$file_modes = array("w+", "w+b", "w+t",
+ "a+", "a+b", "a+t",
+ "x+", "x+b", "x+t");
+
+$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
+
+echo "*** Testing fgets() : usage variations ***\n";
+
+$filename = dirname(__FILE__)."/fgets_variation5.tmp";
+
+foreach($file_modes as $file_mode) {
+ echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
+
+ foreach($file_content_types as $file_content_type) {
+ echo "-- File content type : $file_content_type --\n";
+
+ /* create files with $file_content_type */
+ $file_handle = fopen($filename, $file_mode);
+ $data = fill_file($file_handle, $file_content_type, 50);
+
+ if ( !$file_handle ) {
+ echo "Error: failed to open file $filename!";
+ exit();
+ }
+
+ /* read with length beyong file size */
+ echo "-- fgets() with length > filesize --\n";
+ rewind($file_handle);
+
+ var_dump( ftell($file_handle) );
+ var_dump( fgets($file_handle, 50 + 23) ); // expected: 50
+ var_dump( ftell($file_handle) ); // ensure the file pointer position
+ var_dump( feof($file_handle) ); // enusre if eof set
+
+ //close file
+ fclose($file_handle);
+
+ // delete file
+ delete_file($filename);
+ } // file_content_type loop
+} // file_mode loop
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing fgets() : usage variations ***
+
+-- Testing fgets() with file opened using mode w+ --
+-- File content type : numeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with length > filesize --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with length > filesize --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode w+b --
+-- File content type : numeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with length > filesize --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with length > filesize --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode w+t --
+-- File content type : numeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with length > filesize --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with length > filesize --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode a+ --
+-- File content type : numeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with length > filesize --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with length > filesize --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode a+b --
+-- File content type : numeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with length > filesize --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with length > filesize --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode a+t --
+-- File content type : numeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with length > filesize --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with length > filesize --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode x+ --
+-- File content type : numeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with length > filesize --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with length > filesize --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode x+b --
+-- File content type : numeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with length > filesize --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with length > filesize --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode x+t --
+-- File content type : numeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with length > filesize --
+int(0)
+string(50) "text text text text text text text text text text "
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with length > filesize --
+int(0)
+string(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with length > filesize --
+int(0)
+string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test fgets() function : usage variations - read when file pointer at EOF
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) != 'WIN') {
+ die('skip only valid for Windows');
+}
+?>
+--FILE--
+<?php
+/*
+ Prototype: string fgets ( resource $handle [, int $length] );
+ Description: Gets a line from file pointer
+*/
+
+// include the file.inc for common test funcitons
+include ("file.inc");
+
+$file_modes = array("w+", "w+b", "w+t",
+ "a+", "a+b", "a+t",
+ "x+", "x+b", "x+t");
+
+$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
+
+echo "*** Testing fgets() : usage variations ***\n";
+
+$filename = dirname(__FILE__)."/fgets_variation4.tmp";
+
+foreach($file_modes as $file_mode) {
+ echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
+
+ foreach($file_content_types as $file_content_type) {
+ echo "-- File content type : $file_content_type --\n";
+
+ /* create files with $file_content_type */
+ $file_handle = fopen($filename, $file_mode);
+ $data = fill_file($file_handle, $file_content_type, 50);
+
+ if ( !$file_handle ) {
+ echo "Error: failed to open file $filename!";
+ exit();
+ }
+
+ echo "-- fgets() with file pointer pointing at EOF --\n";
+ // seek to end of the file and try fgets()
+ var_dump( fseek($file_handle, 0, SEEK_END) ); // set file pointer to eof
+ var_dump( ftell($file_handle) ); // ensure that file pointer is at eof
+ var_dump( feof($file_handle) ); // expected false
+
+ var_dump( fgets($file_handle) ); // try n read a line, none expected
+ var_dump( ftell($file_handle) ); // file pointer position
+ var_dump( feof($file_handle) ); // ensure thta file pointer is at eof
+
+ //close file
+ fclose($file_handle);
+
+ // delete file
+ delete_file($filename);
+ } // file_content_type loop
+} // file_mode loop
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing fgets() : usage variations ***
+
+-- Testing fgets() with file opened using mode w+ --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode w+b --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode w+t --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(55)
+bool(false)
+bool(false)
+int(55)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode a+ --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode a+b --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode a+t --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(55)
+bool(false)
+bool(false)
+int(55)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode x+ --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode x+b --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode x+t --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(55)
+bool(false)
+bool(false)
+int(55)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+Done
--- /dev/null
+--TEST--
+Test fgets() function : usage variations - read when file pointer at EOF
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ die('skip Not valid for Windows');
+}
+?>
+--FILE--
+<?php
+/*
+ Prototype: string fgets ( resource $handle [, int $length] );
+ Description: Gets a line from file pointer
+*/
+
+// include the file.inc for common test funcitons
+include ("file.inc");
+
+$file_modes = array("w+", "w+b", "w+t",
+ "a+", "a+b", "a+t",
+ "x+", "x+b", "x+t");
+
+$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
+
+echo "*** Testing fgets() : usage variations ***\n";
+
+$filename = dirname(__FILE__)."/fgets_variation4.tmp";
+
+foreach($file_modes as $file_mode) {
+ echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
+
+ foreach($file_content_types as $file_content_type) {
+ echo "-- File content type : $file_content_type --\n";
+
+ /* create files with $file_content_type */
+ $file_handle = fopen($filename, $file_mode);
+ $data = fill_file($file_handle, $file_content_type, 50);
+
+ if ( !$file_handle ) {
+ echo "Error: failed to open file $filename!";
+ exit();
+ }
+
+ echo "-- fgets() with file pointer pointing at EOF --\n";
+ // seek to end of the file and try fgets()
+ var_dump( fseek($file_handle, 0, SEEK_END) ); // set file pointer to eof
+ var_dump( ftell($file_handle) ); // ensure that file pointer is at eof
+ var_dump( feof($file_handle) ); // expected false
+
+ var_dump( fgets($file_handle) ); // try n read a line, none expected
+ var_dump( ftell($file_handle) ); // file pointer position
+ var_dump( feof($file_handle) ); // ensure thta file pointer is at eof
+
+ //close file
+ fclose($file_handle);
+
+ // delete file
+ delete_file($filename);
+ } // file_content_type loop
+} // file_mode loop
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing fgets() : usage variations ***
+
+-- Testing fgets() with file opened using mode w+ --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode w+b --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode w+t --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode a+ --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode a+b --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode a+t --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode x+ --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode x+b --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+
+-- Testing fgets() with file opened using mode x+t --
+-- File content type : numeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : text_with_new_line --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+-- File content type : alphanumeric --
+-- fgets() with file pointer pointing at EOF --
+int(0)
+int(50)
+bool(false)
+bool(false)
+int(50)
+bool(true)
+Done
\ No newline at end of file