#31540 [NEW]: fwrite baboonacy

From: Date: Thu, 13 Jan 2005 15:43:43 +0000
Subject: #31540 [NEW]: fwrite baboonacy
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-72064@lists.php.net to get a copy of this message
From: mike at cocoweb dot co dot uk Operating system: Windows XP PHP version: 5.0.2 PHP Bug Type: Strings related Bug description: fwrite baboonacy Description: ------------ fwrite() seems to behave incorrectly when using fopen with the "wt" flag on windows... If you open a file using fopen and "w" the supplied code works as expected, by placing \0x0A characters for \n. Which is correct. However the fopen documentation clearly says to use "wt" on windows for text files... If you do, then fwrite() attempts to write all the characters, but because it counts the '\n' characters once, it gets to the end of the string early (zero terminator)... i.e. before it has finished writing all the bytes that it should have. Reproduce code: --------------- $fp = fopen("bob.txt", "wt") // This is the line I'd expect to work for files // opened in "wt" mode: fwrite($fp, "hello\n\n\n", 11) (11 is intentional, as in "wt" mode, the \n's are two bytes, and hence the fwrite() should be outputting two bytes for each '\n'), which it does. It just counts the string incorrectly in "wt" mode. Expected result: ---------------- Binary output: 'h' 'e' 'l' 'l' 'o' \0x0d \0x0a \0x0d \0x0a \0x0d \0x0a Actual result: -------------- Binary output: 'h' 'e' 'l' 'l' 'o' \0x0d \0x0a \0x0d The Dialogue: Mr. fwrite: "I've finished cos I found a \0x00 on the input string..." Developer: "err... no you haven't finished, wasn't your file opened in 'wt' mode, and therefore you need to count \n as two bytes?" Mr. fwrite: "Oh I forgot about that". Developer: "Doh!". I am expecting a reply such as: Mr. PHP.net: "You have forgotten something obvious Mr. Developer" ;o)))) -- Edit bug report at http://bugs.php.net/?id=31540&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31540&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31540&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31540&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=31540&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=31540&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=31540&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=31540&r=needscript Try newer version: http://bugs.php.net/fix.php?id=31540&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=31540&r=support Expected behavior: http://bugs.php.net/fix.php?id=31540&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=31540&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=31540&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=31540&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31540&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=31540&r=dst IIS Stability: http://bugs.php.net/fix.php?id=31540&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=31540&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=31540&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=31540&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=31540&r=mysqlcfg

« previous php.bugs (#72064) next »