#28363 [NEW]: fwrite fails when fopen ASCII file under Windows with 'wt' flags

From: Date: Wed, 12 May 2004 00:55:12 +0000
Subject: #28363 [NEW]: fwrite fails when fopen ASCII file under Windows with 'wt' flags
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-59517@lists.php.net to get a copy of this message
From: zoltan at frombach dot com Operating system: Windows XP PHP version: 4.3.6 PHP Bug Type: Filesystem function related Bug description: fwrite fails when fopen ASCII file under Windows with 'wt' flags Description: ------------ In ASCII mode, fwrite under Windows (when the file is opened with the 'wt' flags) will fail. This is a reproducable bug. See my demonstration program. When "\n" (new line) characters written out to the file, those characters are automatically replaced with "\r\n" which is the expected behaviour in ASCII mode on Windows (when the file is opened with the 't' flag). However, the next fwrite will overwrite the last few characters that were previously written to the file!! Exactly that many characters get lost as many "\r" characters were inserted to the file on the previous fwrite. Seems to me that after the "\n" to "\r\n" translation, the current file position pointer does not get updated, so the next fwrite will overwrite the last few characters previously written to the file. If there is only one fwrite (if you comment out the second fwrite from my code) then no characters get lost!! Because if there is no further writing to the file, no character overwriting occures. That's why I guess it is a file pointer problem. In other words, it's not the first fwrite that forgets to write out those few last characters, IMHO it just forgets to properly update the actual file pointer and that's why the next fwrite overwrites those last few characters in the file. Reproduce code: --------------- <? $fp=fopen('testfile.txt', 'wt'); fwrite($fp, "This\ntest\nwill\nfail\n"); fwrite($fp, "Under\nWindows\nmost\ndefinitely\n"); fclose($fp); ?> Expected result: ---------------- This test will fail Under Windows most definitely Actual result: -------------- This test will faUnder Windows most definitely -- Edit bug report at http://bugs.php.net/?id=28363&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28363&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28363&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=28363&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=28363&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=28363&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=28363&r=needscript Try newer version: http://bugs.php.net/fix.php?id=28363&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=28363&r=support Expected behavior: http://bugs.php.net/fix.php?id=28363&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=28363&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=28363&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=28363&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28363&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=28363&r=dst IIS Stability: http://bugs.php.net/fix.php?id=28363&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=28363&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=28363&r=float

« previous php.bugs (#59517) next »