Hi all,
To fix EOL writing with "dfmt ---> stdout" on Windows, stdout has to be set to binary mode [1]. The code for this is non-trivial, and some DMD internal magic is needed:

version(Windows)
{
    // See Phobos' stdio.File.rawWrite
    {
        import std.stdio;
        immutable fd = fileno(stdout.getFP());
        setmode(fd, _O_BINARY);
        version(CRuntime_DigitalMars)
        {
            import core.atomic : atomicOp;
            atomicOp!"&="(__fhnd_info[fd], ~FHND_TEXT);
        }
    }
}

I think it'd be very nice to have stdio.File.setBinaryMode() and stdio.File.setTextMode(). In dfmt's case, rawWrite is not available because stdout.lockingTextWriter() is used, which only has put().

Should I work on a PR for setBinaryMode+setTextMode ?

thanks,
  Johan

Reply via email to