About File.rawWrite
Ali Çehreli
acehreli at yahoo.com
Tue Nov 29 13:57:40 PST 2011
On 11/29/2011 01:20 PM, torhu wrote:
> On 29.11.2011 16:00, Denis Shelomovskij wrote:
>>
>> Your OS is Windows, right? On Windows, rawWrite and rawRead always
>> flushes stream, sets binary mode, reads/writes, flushes stream again,
>> sets previous mode. This is definitely unnecessary slow - at least it
>> should change mode only if needed (the file is opened in a text mode).
>> The better solution is to change all other functions so the file mode
>> will be changed lazily (for a text file, raw* functions will change file
>> mode and leave file in this mode until a call of a function, that really
>> needs a file to be in a text mode).
>>
>> By the way, why this changing mode behaviour is Windows only? Yes, it is
>> clearly documented that this is the case, but it isn't documented _why_
>> this is the case.
>
> Text mode means that \n in strings is translated to \r\n when writing,
> and the other way when reading. That way you can use only LF (\n) to get
> linefeeds on all platforms, even if Windows uses CRLF.
The "has no effect" part in the following paragraph has been news to me.
From 'man fopen' on my Lubuntu 11 based system:
<quote>
The mode string can also include the letter 'b' either as a last char‐
acter or as a character between the characters in any of the two-char‐
acter strings described above. This is strictly for compatibility with
C89 and has no effect; the 'b' is ignored on all POSIX conforming sys‐
tems, including Linux. (Other systems may treat text files and binary
files differently, and adding the 'b' may be a good idea if you do I/O
to a binary file and expect that your program may be ported to non-Unix
environments.)
</quote>
Ali
More information about the Digitalmars-d-learn
mailing list