#27575 [Opn->Bgs]: ftell reports the size of appended bytes instead of the file pointer position
| From: | wez@php.net | Date: | Thu, 11 Mar 2004 20:33:53 +0000 |
| Subject: | #27575 [Opn->Bgs]: ftell reports the size of appended bytes instead of the file pointer position | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969359494@lists.php.net to get a copy of this message | ||
ID: 27575
Updated by: wez@php.net
Reported By: fbernardi at bbros dot it
-Status: Open
+Status: Bogus
-Bug Type: Filesystem function related
+Bug Type: Documentation problem
Operating System: Red Hat Linux
PHP Version: 4.3.4
New Comment:
Duplicate of Bug #24071.
You cannot rely on ftell() or fseek() when working with an append-only
stream.
Previous Comments:
------------------------------------------------------------------------
[2004-03-11 14:33:10] fbernardi at bbros dot it
Description:
------------
ftell() reports the size of bytes added to a file instead of the
position of the file pointer in the file.
I guess this behavior is reproduceable only on appending data to a
file, since on new files the file pointer position is at the same place
of the number of bytes added.
Reproduce code:
---------------
<?php
# Adding something to the test-file to see the behavior
$fp = fopen("test", w);
fwrite($fp, "Ciao");
fflush($fp);
fclose($fp);
# test-file saved and closed
# Opening a file with non-zero size (just added some bytes)
$fp = fopen("test", a);
fwrite($fp, "Ciao");
fflush($fp);
$s = filesize("test");
$t = ftell($fp);
print("The pointer should be at the position $s, but ftell reports
$t");
fclose($fp);
?>
Expected result:
----------------
The pointer should be at the position 8, but ftell reports 8
Actual result:
--------------
The pointer should be at the position 8, but ftell reports 4
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27575&edit=1