Bug #77081 [Opn]: fopen() c mode positions file pointer at the end

From: Date: Mon, 29 Oct 2018 22:31:41 +0000
Subject: Bug #77081 [Opn]: fopen() c mode positions file pointer at the end
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217741@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: cmb@php.net Reported by: cmb@php.net Summary: fopen() c mode positions file pointer at the end Status: Open Type: Bug Package: Filesystem function related Operating System: Windows PHP Version: 7.3Git-2018-10-29 (Git) -Assigned To: +Assigned To: ab Block user comment: N Private report: N New Comment: 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> Previous Comments: ------------------------------------------------------------------------ [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 ------------------------------------------------------------------------ [2018-10-29 15:21:46] cmb@php.net Description: ------------ The documentation of fopen() mode c[1] states: | The file pointer is positioned on the beginning of the file. However, this does not happen with PHP 7.3 on Windows; instead the file pointer is positioned at the end of the file, even though ftell() claims otherwise. It works as expected on Linux and with PHP 7.2 on Windows. [1] <http://php.net/manual/en/function.fopen.php> Test script: --------------- <?php $filename = __DIR__ . '/fopen-c.txt'; file_put_contents($filename, 'foo'); $stream = fopen($filename, 'c'); ftruncate($stream, 0); // fseek($stream, 0); var_dump(ftell($stream)); fwrite($stream, 'bar'); fclose($stream); var_dump(file_get_contents($filename)); Expected result: ---------------- int(0) string(3) "bar" Actual result: -------------- int(0) string(6) " bar" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77081&edit=1

« previous php.bugs (#217741) next »