Bug #77081 [Asn->Csd]: ftruncate() changes seek pointer in c mode

From: Date: Tue, 30 Oct 2018 19:51:07 +0000
Subject: Bug #77081 [Asn->Csd]: ftruncate() changes seek pointer in c mode
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217758@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77081&edit=1 ID: 77081 Updated by: ab@php.net Reported by: cmb@php.net Summary: ftruncate() changes seek pointer in c mode -Status: Assigned +Status: Closed Type: Bug Package: Filesystem function related Operating System: Windows PHP Version: 7.3Git-2018-10-29 (Git) Assigned To: ab Block user comment: N Private report: N New Comment: Automatic comment on behalf of ab Revision: http://git.php.net/?p=php-src.git;a=commit;h=8827cc34cf8c77828330182ee1e6d0b9438d489c Log: Fixed bug #77081 ftruncate() changes seek pointer in c mode Previous Comments: ------------------------------------------------------------------------ [2018-10-30 19:18:05] ab@php.net I see. As fopen() with 'c' doesn't truncate, the file pointer suddenly jumps to the end of file after ftruncate(). This is obviously wrong leftover from the linked patch for bug #76803. I'm going to fix it using your solution and revamp some more. Thanks. ------------------------------------------------------------------------ [2018-10-30 18:16:49] cmb@php.net > […] if there's something wrong with fopen […] Sorry, my mistake. Actually, the problem is not with fopen() per se, but rather with ftruncate() on a file freshly opened in c mode. If I comment out the ftruncate() call in the given reproduce script, I get the expected: int(0) string(3) "bar" Also, writing only the single character 'b' instead of 'bar' gives the expected: int(0) string(3) "boo" The problem is that the ftruncate() call changes the seek pointer, which it is not supposed to. ------------------------------------------------------------------------ [2018-10-30 18:05:53] ab@php.net Thanks for the ping, Christoph. Perhaps, if there's something wrong with fopen, it should be fixed in first place. I'm going to check it first. Thanks. ------------------------------------------------------------------------ [2018-10-29 22:31:41] cmb@php.net This regression has been introduced with commit 7728160[1]. Anatol, what do you think about something like the attached restore-old-position patch? [1] <http://git.php.net/?p=php-src.git;a=commit;h=7728160784785771d1933f5f0a8c4d7a735470b0> ------------------------------------------------------------------------ [2018-10-29 22:31:30] cmb@php.net The following patch has been added/updated: Patch Name: restore-old-position Revision: 1540852290 URL: https://bugs.php.net/patch-display.php?bug=77081&patch=restore-old-position&revision=1540852290 ------------------------------------------------------------------------ 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 https://bugs.php.net/bug.php?id=77081 -- Edit this bug report at https://bugs.php.net/bug.php?id=77081&edit=1

« previous php.bugs (#217758) next »