|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-05-12 12:48 UTC] wez@php.net
[2004-05-13 00:29 UTC] zoltan at frombach dot com
[2004-05-13 02:25 UTC] wez@php.net
[2004-05-13 04:17 UTC] zoltan at frombach dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 09 00:00:02 2025 UTC |
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