#32889 [Csd]: ftruncate doesn't move the file pointer

From: Date: Sun, 02 Sep 2007 21:43:35 +0000
Subject: #32889 [Csd]: ftruncate doesn't move the file pointer
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969377990@lists.php.net to get a copy of this message
ID: 32889 Updated by: bjori@php.net Reported By: techtonik@php.net Status: Closed Bug Type: Documentation problem PHP Version: Irrelevant New Comment: The previous fix was wrong. The docs have been updated to "The file pointer is <emphasis>not</emphasis> changed." Previous Comments: ------------------------------------------------------------------------ [2005-04-30 10:51:04] techtonik@php.net Tnx. Now everything is clear. ------------------------------------------------------------------------ [2005-04-29 18:31:46] wez@php.net The file pointer is not changed at all by PHP when you truncate. This is consistent with ANSI ftruncate (man ftruncate). You are responsible for seeking explicitly if you require it. ------------------------------------------------------------------------ [2005-04-29 16:18:32] vrana@php.net This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. "The file pointer is changed only in append mode. In write mode, additional fseek() call is needed." ------------------------------------------------------------------------ [2005-04-29 13:04:11] techtonik@php.net Something like "Warning: Truncate doesn't change position of the file pointer. Adjust the pointer with fseek to write to the end of the file after truncate operation in modes other than "a" and "a+"." ? Examples: <?php $fh = fopen("file.txt","w+"); fwrite($fh, "newfile"); // file contains string 'newfile' ftruncate($fh, 3); fseek($fh, 0, SEEK_END); fwrite($fh, "contents"); // file contains 'newcontents' fclose($fh); ?> <?php $fh = fopen("file.txt","w+"); fwrite($fh, "newfile"); // file contains string 'newfile' ftruncate($fh, 3); fwrite($fh, "contents"); // file contains 'new contents' fclose($fh); ?> ------------------------------------------------------------------------ [2005-04-29 12:22:17] tony2001@php.net "The file pointer is not changed." (c) man ftruncate ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/32889 -- Edit this bug report at http://bugs.php.net/?id=32889&edit=1

« previous php.doc (#969377990) next »