lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] MinGW-w64 binary standard streams


From: Greg Chicares
Subject: [lmi] MinGW-w64 binary standard streams
Date: Mon, 22 Aug 2016 21:32:14 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.8.0

This code, just removed from 'test_coding_rules.cpp', opened standard
streams in binary mode before main() was called:
    int _CRT_fmode = _O_BINARY;
It worked with MinGW, but did nothing with MinGW-w64.

This message:
  https://sourceforge.net/p/mingw-w64/discussion/723797/thread/2ee20d6e/
suggests this workaround:
    #undef _fmode
    int _fmode = _O_BINARY;
but that also doesn't work with MinGW-w64. I build 'test_coding_rules.exe'
with it, and observed (in an msw VM):

$test_coding_rules * |od -t a
0000000  sp  sp  sp  sp  sp  sp   5   6   1  sp   s   o   u   r   c   e
0000020  sp   f   i   l   e   s  cr  nl  sp  sp  sp   1   7   1   3   7
0000040   1  sp   s   o   u   r   c   e  sp   l   i   n   e   s  cr  nl
0000060  sp  sp  sp  sp  sp  sp   4   2   7  sp   m   a   r   k   e   d
0000100  sp   d   e   f   e   c   t   s  cr  nl

(Because of that, 'test_coding_rules_test.sh' failed with 'wine'. That's
not a 'wine' defect because CRs are seen in the msw session above. I
suppose the reason why 'test_coding_rules_test.sh' worked with cygwin is
that cygwin's 'diff' probably discards CRs silently.)

In this thread:
  https://sourceforge.net/p/mingw-w64/mailman/message/31444592/
it is reported that linking 'binmode.o' also does not work; but the
error report is dismissed. As previously noted:

http://lists.nongnu.org/archive/html/lmi/2016-07/msg00037.html
| For completeness, I'd also like to mention that the decision to not go
| with TDM-GCC seems more and more regrettable retroactively

Here's the workaround I just added:

#if defined LMI_MSW
    // Force standard output streams to binary mode.
    setmode(fileno(stdout), O_BINARY);
    setmode(fileno(stderr), O_BINARY);
#endif // defined LMI_MSW

which does get rid of the CR-NL above. It's not as robust as a built-in
solution, because the streams might be used before main(), but it seems
to be the least bad solution that works with MinGW-w64. I figure it does
no harm to leave stdin in text mode. I'm guessing it works with msvc too.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]