Fabian Cenedese
2014-09-24 14:30:45 UTC
Hi
I have a question about writing native text files. I simply want to write
text files that have native line endings on Windows or Linux. Trying
several wx classes (wxFile, wxTextFile with Write("\n") or
wxFFileOutputStream, wxTextOutputStream with << endl)
all lead to the same error. The written file on disk has 0x0D 0x0D 0x0A
instead of 0x0D 0x0A for Windows.
I traced it down into the crt of MSVC 2010. In crt/src/write.c
there's this code/comment:
} else if ( _osfile(fh) & FTEXT ) {
/* text mode, translate LF's to CR/LF's on output */
So the c library itself translates 0x0A to 0x0D 0x0A.
Together with e.g. this code:
void wxTextOutputStream::WriteString(const wxString& string)
...
if ( c == wxT('\n') )
{
switch ( m_mode )
{
case wxEOL_DOS:
out << wxT("\r\n");
continue;
we end up with double-D's :) I'm wondering now if nobody else has
this problem. Does that mean that we have to use binary mode even
for text files? What's the best way to write native line endings on big
text files? wxTextFile should only be used for smaller files.
Thanks
bye Fabi
I have a question about writing native text files. I simply want to write
text files that have native line endings on Windows or Linux. Trying
several wx classes (wxFile, wxTextFile with Write("\n") or
wxFFileOutputStream, wxTextOutputStream with << endl)
all lead to the same error. The written file on disk has 0x0D 0x0D 0x0A
instead of 0x0D 0x0A for Windows.
I traced it down into the crt of MSVC 2010. In crt/src/write.c
there's this code/comment:
} else if ( _osfile(fh) & FTEXT ) {
/* text mode, translate LF's to CR/LF's on output */
So the c library itself translates 0x0A to 0x0D 0x0A.
Together with e.g. this code:
void wxTextOutputStream::WriteString(const wxString& string)
...
if ( c == wxT('\n') )
{
switch ( m_mode )
{
case wxEOL_DOS:
out << wxT("\r\n");
continue;
we end up with double-D's :) I'm wondering now if nobody else has
this problem. Does that mean that we have to use binary mode even
for text files? What's the best way to write native line endings on big
text files? wxTextFile should only be used for smaller files.
Thanks
bye Fabi
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users