Bug #67370 [Com]: Fseek does not return error (-1) on read out of file
| From: | roman4e at gmail dot com | Date: | Mon, 02 Jun 2014 10:36:58 +0000 |
| Subject: | Bug #67370 [Com]: Fseek does not return error (-1) on read out of file | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186011@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67370&edit=1
ID: 67370
Comment by: roman4e at gmail dot com
Reported by: roman4e at gmail dot com
Summary: Fseek does not return error (-1) on read out of file
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:
Thank you much!
Previous Comments:
------------------------------------------------------------------------
[2014-06-02 09:11:02] mike@php.net
Because fseek clears the EOF condition, reverse your conditions.
------------------------------------------------------------------------
[2014-06-02 08:58:27] roman4e at gmail dot com
change code:
while ( !fseek($f,$page,SEEK_SET) && !feof($f))
So why in that case !feof($f) does not return true when go out end of file?
------------------------------------------------------------------------
[2014-06-02 08:23:12] mike@php.net
One can set the file pointer beyond EOF, this is not a bug.
------------------------------------------------------------------------
[2014-06-02 07:47:01] roman4e at gmail dot com
Description:
------------
php v.5.5.5 (cli) (built: Mar 17 2014 12:31:03) (DEBUG)
fseek() does not return error (-1) on read out of file, returns 0
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:
----------------
fseek should return -1;
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=67370&edit=1