Menu

#693 binmode.o is broken

v1.0 (example)
open
nobody
None
7
2018-02-19
2017-12-05
No

binmode.c doesn't work as expected. It should be changed to similar pattern as textmode. Also it would be great to create a lib file with it as well (it is already done in cygwin) which will make enabling this options with just -l command. As in binmode.o case i have to specify exact path to file location

Discussion

  • NightStrike

    NightStrike - 2018-02-18
    • summary: bitmode.o is broken --> binmode.o is broken
     
  • NightStrike

    NightStrike - 2018-02-18

    Do you have a test case to demonstrte the problem, or a proposed patch to fix?

     
  • Demyan Kimitsa

    Demyan Kimitsa - 2018-02-19

    Sure, background info from http://www.cygwin.com/cygwin-ug-net/using-textbinary.html
    On a UNIX system, when an application reads from a file it gets exactly what's in the file on disk and the converse is true for writing. The situation is different in the DOS/Windows world where a file can be opened in one of two modes, binary or text. In the binary mode the system behaves exactly as in UNIX. However on writing in text mode, a NL (\n, ^J) is transformed into the sequence CR (\r, ^M) NL.

    In other words on Windows it opens file detault in text mode and when writing bytes it will auto replace \n with \n\r which breaks everything . When porting unix stuff this is sensitive. For this there was binmode.o file introduced and once it is linked it is intended to switch default mode to bin mode. Check link above.

    Existing binmode.c is broken as did nothing. I workarounded this by just adding following to my code (same that has to be in binmode):

    if (defined _WIN32 || defined WIN32) && ! defined CYGWIN

    include <fcntl.h>
    int _fmode = _O_BINARY;</fcntl.h>

    endif

    Beside fixing binmode.o it would also be GREAT to add libbinmode.a (which includes only this file) as it would be then easy to enable this mode by just likning with this lib. As linking with .o file is tricky as it is not on library path

     

Log in to post a comment.