]> granicus.if.org Git - php/commitdiff
New testcases for fwrite(), fgetc() and fgets() functions
authorRaghubansh Kumar <kraghuba@php.net>
Sat, 21 Jul 2007 08:01:25 +0000 (08:01 +0000)
committerRaghubansh Kumar <kraghuba@php.net>
Sat, 21 Jul 2007 08:01:25 +0000 (08:01 +0000)
15 files changed:
ext/standard/tests/file/fgetc_variation1.phpt [new file with mode: 0644]
ext/standard/tests/file/fgetc_variation2.phpt [new file with mode: 0644]
ext/standard/tests/file/fgetc_variation3.phpt [new file with mode: 0644]
ext/standard/tests/file/fgetc_variation4.phpt [new file with mode: 0644]
ext/standard/tests/file/fgets_basic.phpt [new file with mode: 0644]
ext/standard/tests/file/fgets_error.phpt [new file with mode: 0644]
ext/standard/tests/file/fgets_variation1.phpt [new file with mode: 0644]
ext/standard/tests/file/fgets_variation2.phpt [new file with mode: 0644]
ext/standard/tests/file/fgets_variation3.phpt [new file with mode: 0644]
ext/standard/tests/file/fgets_variation4-win32.phpt [new file with mode: 0644]
ext/standard/tests/file/fgets_variation4.phpt [new file with mode: 0644]
ext/standard/tests/file/fgets_variation5.phpt [new file with mode: 0644]
ext/standard/tests/file/fgets_variation6-win32.phpt [new file with mode: 0644]
ext/standard/tests/file/fgets_variation6.phpt [new file with mode: 0644]
ext/standard/tests/file/fwrite_error.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/file/fgetc_variation1.phpt b/ext/standard/tests/file/fgetc_variation1.phpt
new file mode 100644 (file)
index 0000000..0e41e38
--- /dev/null
@@ -0,0 +1,140 @@
+--TEST--
+Test fgetc() function : usage variations - read when file pointer at EOF(fails, see bug#42037)
+--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
+--UEXPECTF--
+*** 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
diff --git a/ext/standard/tests/file/fgetc_variation2.phpt b/ext/standard/tests/file/fgetc_variation2.phpt
new file mode 100644 (file)
index 0000000..4977fa0
--- /dev/null
@@ -0,0 +1,91 @@
+--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
+--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
+--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
diff --git a/ext/standard/tests/file/fgetc_variation3.phpt b/ext/standard/tests/file/fgetc_variation3.phpt
new file mode 100644 (file)
index 0000000..5a6ac6f
--- /dev/null
@@ -0,0 +1,183 @@
+--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
+--UEXPECTF--
+*** 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
diff --git a/ext/standard/tests/file/fgetc_variation4.phpt b/ext/standard/tests/file/fgetc_variation4.phpt
new file mode 100644 (file)
index 0000000..a8a4061
--- /dev/null
@@ -0,0 +1,528 @@
+--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, (binary)$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
+--UEXPECTF--
+*** 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)
+unicode(1) "f"
+int(1)
+bool(false)
+unicode(1) "g"
+int(2)
+bool(false)
+unicode(1) "e"
+int(3)
+bool(false)
+unicode(1) "t"
+int(4)
+bool(false)
+unicode(1) "c"
+int(5)
+bool(false)
+unicode(1) "
+"
+int(6)
+bool(false)
+unicode(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)
+unicode(1) "f"
+int(1)
+bool(false)
+unicode(1) "g"
+int(2)
+bool(false)
+unicode(1) "e"
+int(3)
+bool(false)
+unicode(1) "t"
+int(4)
+bool(false)
+unicode(1) "c"
+int(5)
+bool(false)
+unicode(1) "
+"
+int(6)
+bool(false)
+unicode(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)
+unicode(1) "f"
+int(1)
+bool(false)
+unicode(1) "g"
+int(2)
+bool(false)
+unicode(1) "e"
+int(3)
+bool(false)
+unicode(1) "t"
+int(4)
+bool(false)
+unicode(1) "c"
+int(5)
+bool(false)
+unicode(1) "
+"
+int(6)
+bool(false)
+unicode(1) " "
+int(7)
+bool(false)
+Done
diff --git a/ext/standard/tests/file/fgets_basic.phpt b/ext/standard/tests/file/fgets_basic.phpt
new file mode 100644 (file)
index 0000000..476f750
--- /dev/null
@@ -0,0 +1,585 @@
+--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
+--UEXPECTF--
+*** 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 --
+unicode(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+unicode(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+unicode(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)
+unicode(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 --
+unicode(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+unicode(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+unicode(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)
+unicode(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 --
+unicode(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+unicode(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+unicode(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)
+unicode(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 --
+unicode(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+bool(true)
+unicode(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+unicode(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)
+unicode(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/file/fgets_error.phpt b/ext/standard/tests/file/fgets_error.phpt
new file mode 100644 (file)
index 0000000..06629d6
--- /dev/null
@@ -0,0 +1,157 @@
+--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: fgets() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+-- Testing fgets() with more than expected number of arguments --
+
+Warning: fgets() expects at most 2 parameters, 3 given 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() expects parameter 1 to be resource, string given in %s on line %d
+NULL
+-- Iteration 2 --
+
+Warning: fgets() expects parameter 1 to be resource, integer given in %s on line %d
+NULL
+-- Iteration 3 --
+
+Warning: fgets() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+-- Iteration 4 --
+
+Warning: fgets() expects parameter 1 to be resource, boolean given in %s on line %d
+NULL
+-- Iteration 5 --
+
+Warning: fgets() expects parameter 1 to be resource, array given in %s on line %d
+NULL
+-- Iteration 6 --
+
+Warning: fgets() expects parameter 1 to be resource, object given in %s on line %d
+NULL
+-- 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() expects parameter 1 to be resource, null given in %s on line %d
+NULL
+Done
+--UEXPECTF--
+*** Testing error conditions ***
+-- Testing fgets() with zero argument --
+
+Warning: fgets() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+-- Testing fgets() with more than expected number of arguments --
+
+Warning: fgets() expects at most 2 parameters, 3 given 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() expects parameter 1 to be resource, Unicode string given in %s on line %d
+NULL
+-- Iteration 2 --
+
+Warning: fgets() expects parameter 1 to be resource, integer given in %s on line %d
+NULL
+-- Iteration 3 --
+
+Warning: fgets() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+-- Iteration 4 --
+
+Warning: fgets() expects parameter 1 to be resource, boolean given in %s on line %d
+NULL
+-- Iteration 5 --
+
+Warning: fgets() expects parameter 1 to be resource, array given in %s on line %d
+NULL
+-- Iteration 6 --
+
+Warning: fgets() expects parameter 1 to be resource, object given in %s on line %d
+NULL
+-- 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() expects parameter 1 to be resource, null given in %s on line %d
+NULL
+Done
diff --git a/ext/standard/tests/file/fgets_variation1.phpt b/ext/standard/tests/file/fgets_variation1.phpt
new file mode 100644 (file)
index 0000000..08b3439
--- /dev/null
@@ -0,0 +1,182 @@
+--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, (binary)$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
+--UEXPECTF--
+*** 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
diff --git a/ext/standard/tests/file/fgets_variation2.phpt b/ext/standard/tests/file/fgets_variation2.phpt
new file mode 100644 (file)
index 0000000..ea70e4d
--- /dev/null
@@ -0,0 +1,83 @@
+--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 %s
+bool(false)
+
+Warning: fgets(): 6 is not a valid stream resource in %s on line %s
+bool(false)
+-- Testing fgets() with unset handle --
+
+Notice: Undefined variable: file_handle in %s on line %s
+
+Warning: fgets() expects parameter 1 to be resource, null given in %s on line %s
+NULL
+
+Notice: Undefined variable: file_handle in %s on line %s
+
+Warning: fgets() expects parameter 1 to be resource, null given in %s on line %s
+NULL
+Done
+--UEXPECTF--
+*** Testing fgets() : usage variations ***
+-- Testing fgets() with closed handle --
+
+Warning: fgets(): 6 is not a valid stream resource in %s on line %s
+bool(false)
+
+Warning: fgets(): 6 is not a valid stream resource in %s on line %s
+bool(false)
+-- Testing fgets() with unset handle --
+
+Notice: Undefined variable: file_handle in %s on line %s
+
+Warning: fgets() expects parameter 1 to be resource, null given in %s on line %s
+NULL
+
+Notice: Undefined variable: file_handle in %s on line %s
+
+Warning: fgets() expects parameter 1 to be resource, null given in %s on line %s
+NULL
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/file/fgets_variation3.phpt b/ext/standard/tests/file/fgets_variation3.phpt
new file mode 100644 (file)
index 0000000..4bb3f52
--- /dev/null
@@ -0,0 +1,935 @@
+--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
+--UEXPECTF--
+*** 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)
+unicode(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+unicode(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+unicode(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)
+unicode(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)
+unicode(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+unicode(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+unicode(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)
+unicode(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)
+unicode(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+unicode(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+unicode(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)
+unicode(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)
+unicode(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+unicode(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+unicode(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)
+unicode(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)
+unicode(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+unicode(22) "2222222222222222222222"
+int(22)
+bool(false)
+-- File content type : text --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+unicode(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)
+unicode(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)
+unicode(5) "line
+"
+int(5)
+bool(false)
+-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
+int(0)
+unicode(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with default length, file pointer at 0 --
+int(0)
+unicode(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)
+unicode(22) "ab12 ab12 ab12 ab12 ab"
+int(22)
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/file/fgets_variation4-win32.phpt b/ext/standard/tests/file/fgets_variation4-win32.phpt
new file mode 100644 (file)
index 0000000..e03d90a
--- /dev/null
@@ -0,0 +1,1081 @@
+--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
+--UEXPECTF--
+*** 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)
+unicode(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+unicode(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+unicode(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)
+unicode(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)
+unicode(1) "
+"
+int(6)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+unicode(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)
+unicode(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)
+unicode(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)
+unicode(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+unicode(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+unicode(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)
+unicode(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)
+unicode(1) "
+"
+int(6)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+unicode(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)
+unicode(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)
+unicode(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)
+unicode(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+unicode(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+unicode(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)
+unicode(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)
+unicode(1) "
+"
+int(6)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+unicode(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)
+unicode(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)
+unicode(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+Done
diff --git a/ext/standard/tests/file/fgets_variation4.phpt b/ext/standard/tests/file/fgets_variation4.phpt
new file mode 100644 (file)
index 0000000..66f87a0
--- /dev/null
@@ -0,0 +1,1080 @@
+--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
+--UEXPECTF--
+*** 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)
+unicode(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+unicode(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+unicode(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)
+unicode(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)
+unicode(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+unicode(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)
+unicode(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)
+unicode(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)
+unicode(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+unicode(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+unicode(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)
+unicode(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)
+unicode(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+unicode(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)
+unicode(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)
+unicode(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)
+unicode(45) "222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+unicode(19) "2222222222222222222"
+int(44)
+bool(false)
+-- File content type : text --
+-- fgets() with location set by fseek() with default length --
+int(0)
+int(5)
+unicode(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)
+unicode(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)
+unicode(13) "line of text
+"
+int(18)
+bool(false)
+-- fgets() with location set by fseek() with length = 20 --
+int(0)
+int(25)
+unicode(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)
+unicode(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)
+unicode(19) "ab12 ab12 ab12 ab12"
+int(44)
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/file/fgets_variation5.phpt b/ext/standard/tests/file/fgets_variation5.phpt
new file mode 100644 (file)
index 0000000..738ba37
--- /dev/null
@@ -0,0 +1,548 @@
+--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
+--UEXPECTF--
+*** 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)
+unicode(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with length > filesize --
+int(0)
+unicode(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)
+unicode(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with length > filesize --
+int(0)
+unicode(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)
+unicode(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with length > filesize --
+int(0)
+unicode(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)
+unicode(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with length > filesize --
+int(0)
+unicode(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)
+unicode(50) "22222222222222222222222222222222222222222222222222"
+int(50)
+bool(true)
+-- File content type : text --
+-- fgets() with length > filesize --
+int(0)
+unicode(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)
+unicode(5) "line
+"
+int(5)
+bool(false)
+-- File content type : alphanumeric --
+-- fgets() with length > filesize --
+int(0)
+unicode(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+int(50)
+bool(true)
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/file/fgets_variation6-win32.phpt b/ext/standard/tests/file/fgets_variation6-win32.phpt
new file mode 100644 (file)
index 0000000..07bb35e
--- /dev/null
@@ -0,0 +1,681 @@
+--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
+--UEXPECTF--
+*** 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
diff --git a/ext/standard/tests/file/fgets_variation6.phpt b/ext/standard/tests/file/fgets_variation6.phpt
new file mode 100644 (file)
index 0000000..7a71b4f
--- /dev/null
@@ -0,0 +1,680 @@
+--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
+--UEXPECTF--
+*** 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
diff --git a/ext/standard/tests/file/fwrite_error.phpt b/ext/standard/tests/file/fwrite_error.phpt
new file mode 100644 (file)
index 0000000..fc05c77
--- /dev/null
@@ -0,0 +1,169 @@
+--TEST--
+Test fwrite() function : error conditions (fails, see bug#42057)
+--FILE--
+<?php
+/*
+ Prototype: int fwrite ( resource $handle,string string, [, int $length] );
+ Description: fwrite() writes the contents of string to the file stream pointed to by handle.
+              If the length arquement is given,writing will stop after length bytes have been
+              written or the end of string reached, whichever comes first.
+              fwrite() returns the number of bytes written or FALSE on error
+*/
+
+// include the file.inc for Function: function delete_file($filename)
+include ("file.inc");
+
+echo "*** Testing fwrite() : error conditions ***\n";
+
+$filename = dirname(__FILE__)."/fwrite_error.tmp";
+
+echo "-- Testing fwrite() with less than expected number of arguments --\n";
+// zero argument
+var_dump( fwrite() ); 
+// less than expected, 1 arg
+$file_handle  = fopen ( $filename, "w");
+var_dump( fwrite($file_handle) );
+
+// more than expected no. of args
+echo "-- Testing fwrite() with more than expected number of arguments --\n";
+$data = "data";
+var_dump( fwrite($file_handle, $data, strlen($data), 10) );
+
+// invalid length argument
+echo "-- Testing fwrite() with invalid length arguments --\n";
+$len = 0;
+var_dump( fwrite($file_handle, $data, $len) );
+$len = -10;
+var_dump( fwrite($file_handle, (binary)$data, $len) );
+
+// test invalid arguments : non-resources
+echo "-- Testing fwrite() with invalid arguments --\n";
+$invalid_args = array (
+  "string",
+  10,
+  10.5,
+  true,
+  array(1,2,3),
+  new stdclass,
+);
+/* loop to test fwrite() with different invalid type of args */
+for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
+  echo "-- Iteration $loop_counter --\n";
+  var_dump( fwrite($invalid_args[$loop_counter - 1], 10) );
+}
+
+// fwrite() on a file handle which is already closed 
+echo "-- Testing fwrite() with closed/unset file handle --\n";
+fclose($file_handle);
+var_dump(fwrite($file_handle,"data"));
+
+// fwrite on a file handle which is unset 
+$fp = fopen($filename, "w");
+unset($fp); //unset file handle 
+var_dump( fwrite(@$fp,"data"));
+
+echo "Done\n";
+?>
+--CLEAN--
+<?php
+$filename = dirname(__FILE__)."/fwrite_error.tmp";
+unlink( $filename );
+?>
+--EXPECTF--
+*** Testing fwrite() : error conditions ***
+-- Testing fwrite() with less than expected number of arguments --
+
+Warning: fwrite() expects at least 2 parameters, 0 given in %s on line %d
+NULL
+
+Warning: fwrite() expects at least 2 parameters, 1 given in %s on line %d
+NULL
+-- Testing fwrite() with more than expected number of arguments --
+
+Warning: fwrite() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+-- Testing fwrite() with invalid length arguments --
+int(0)
+int(0)
+-- Testing fwrite() with invalid arguments --
+-- Iteration 1 --
+
+Warning: fwrite() expects parameter 1 to be resource, string given in %s on line %d
+NULL
+-- Iteration 2 --
+
+Warning: fwrite() expects parameter 1 to be resource, integer given in %s on line %d
+NULL
+-- Iteration 3 --
+
+Warning: fwrite() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+-- Iteration 4 --
+
+Warning: fwrite() expects parameter 1 to be resource, boolean given in %s on line %d
+NULL
+-- Iteration 5 --
+
+Warning: fwrite() expects parameter 1 to be resource, array given in %s on line %d
+NULL
+-- Iteration 6 --
+
+Warning: fwrite() expects parameter 1 to be resource, object given in %s on line %d
+NULL
+-- Testing fwrite() with closed/unset file handle --
+
+Warning: fwrite(): 6 is not a valid stream resource in %s on line %d
+bool(false)
+
+Warning: fwrite() expects parameter 1 to be resource, null given in %s on line %d
+NULL
+Done
+--UEXPECTF--
+*** Testing fwrite() : error conditions ***
+-- Testing fwrite() with less than expected number of arguments --
+
+Warning: fwrite() expects at least 2 parameters, 0 given in %s on line %d
+NULL
+
+Warning: fwrite() expects at least 2 parameters, 1 given in %s on line %d
+NULL
+-- Testing fwrite() with more than expected number of arguments --
+
+Warning: fwrite() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+-- Testing fwrite() with invalid length arguments --
+int(0)
+int(0)
+-- Testing fwrite() with invalid arguments --
+-- Iteration 1 --
+
+Warning: fwrite() expects parameter 1 to be resource, Unicode string given in %s on line %d
+NULL
+-- Iteration 2 --
+
+Warning: fwrite() expects parameter 1 to be resource, integer given in %s on line %d
+NULL
+-- Iteration 3 --
+
+Warning: fwrite() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+-- Iteration 4 --
+
+Warning: fwrite() expects parameter 1 to be resource, boolean given in %s on line %d
+NULL
+-- Iteration 5 --
+
+Warning: fwrite() expects parameter 1 to be resource, array given in %s on line %d
+NULL
+-- Iteration 6 --
+
+Warning: fwrite() expects parameter 1 to be resource, object given in %s on line %d
+NULL
+-- Testing fwrite() with closed/unset file handle --
+
+Warning: fwrite(): 6 is not a valid stream resource in %s on line %d
+bool(false)
+
+Warning: fwrite() expects parameter 1 to be resource, null given in %s on line %d
+NULL
+Done