Bug #67371 [Opn->Nab]: fread does not return error (false) while reading out of file
| From: | mike@php.net | Date: | Mon, 02 Jun 2014 08:31:52 +0000 |
| Subject: | Bug #67371 [Opn->Nab]: fread does not return error (false) while reading out of file | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186005@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67371&edit=1
ID: 67371
Updated by: mike@php.net
Reported by: roman4e at gmail dot com
Summary: fread does not return error (false) while reading
out of file
-Status: Open
+Status: Not a bug
Type: Bug
Package: Filesystem function related
Operating System: linux mint 15
PHP Version: 5.5.13
Block user comment: N
Private report: N
New Comment:
This is not a bug, reading past EOF is not an error case; read(2) states:
"If the current file offset is at or past the end of file, no bytes are read, and read()
returns zero."
Previous Comments:
------------------------------------------------------------------------
[2014-06-02 07:47:40] roman4e at gmail dot com
Description:
------------
php v.5.5.5 (cli) (built: Mar 17 2014 12:31:03) (DEBUG)
fread() does not return error (false) on read out of file, returns "" (empty string)
Test script:
---------------
$f = fopen("file","r"); // file must be several KBytes size
$page = 0;
while ( !fseek($f,$page,SEEK_SET) )
{
$page += 1024;
$str = fread($f,1024);
if ( $str === false )
die("error reading block");
}
echo "ok"
Expected result:
----------------
fread should return false
Actual result:
--------------
file size of 76800
result of reading out of file. last parametr is type of data returned by fread
Pageoff = 75776 fseek=0 ftell=75776 read=1024 string
Pageoff = 76800 fseek=0 ftell=76800 read=0 string
Pageoff = 77824 fseek=0 ftell=77824 read=0 string
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67371&edit=1