#42066 [Opn->Csd]: file pointer not changed when file truncated with append mode
| From: | bjori@php.net | Date: | Sun, 02 Sep 2007 21:42:24 +0000 |
| Subject: | #42066 [Opn->Csd]: file pointer not changed when file truncated with append mode | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969377989@lists.php.net to get a copy of this message | ||
ID: 42066
Updated by: bjori@php.net
Reported By: kraghuba at in dot ibm dot com
-Status: Open
+Status: Closed
-Bug Type: Filesystem function related
+Bug Type: Documentation problem
Operating System: *
PHP Version: 5CVS-2007-07-22 (snap)
-Assigned To:
+Assigned To: bjori
New Comment:
From man ftruncate(2): "The file offset is not changed."
I've fixed the docs.
Previous Comments:
------------------------------------------------------------------------
[2007-07-22 12:04:27] kraghuba at in dot ibm dot com
Description:
------------
The file pointer position is not changed when a file opened in append
mode is truncated using ftruncate() function. As per the documentation
of ftruncate() function, the file pointer should be changed.
http://in2.php.net/manual/en/function.ftruncate.php
from doumentation:
...
Note: The file pointer is changed only in append mode. In write mode,
additional fseek() call is needed.
...
This is applicable to php5 as well as php6.
checked it on WinXP and RHEL 5.
Reproduce code:
---------------
<?php
$fp = fopen("test.txt", "w");
fwrite($fp, "testing ftrucate function with append mode");
fclose($fp);
var_dump( filesize("test.txt") );
$fp = fopen ("test.txt", "a");
var_dump( ftell($fp) );
var_dump( ftruncate($fp, 10) );
var_dump( ftell($fp) );
fclose($fp);
clearstatcache();
var_dump( filesize("test.txt") );
?>
Expected result:
----------------
int(42)
int(0)
bool(true)
int(10)
int(10)
Actual result:
--------------
int(42)
int(0)
bool(true)
int(0)
int(10)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42066&edit=1