On Wednesday, 15 April 2015 at 14:47:46 UTC, armando sano wrote:
Reviving old topic... It is possible to force stdout to write in binary mode on Windows, see https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx

In C, the solution is:

-----------------------------
#include <stdio.h>
#include <fcntl.h>
#include <io.h>

/*...*/

int result = _setmode( _fileno( stdout ), _O_BINARY );
if ( result == -1 )
        perror ("Cannot set stdout to binary mode");
else
        perror ("stdout set to binary mode");
------------------------------


In Python, the solution is:

------------------------------
import platform
if platform.system() == "Windows":
    import os, msvcrt
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
------------------------------

Since D can interface C, it must be possible to do the same in D? (how, I am not sure)

my humble solution:

void setFileModeBinary(File f)
{
        import std.c.stdlib;
        version(Windows) {
                immutable fd = _fileno(f.getFP);
                f.flush();
                _setmode(fd, _O_BINARY);
                version(DigitalMars) {
                        // @@@BUG@@@ 4243
                        immutable info = __fhnd_info[fd];
                        __fhnd_info[fd] &= ~FHND_TEXT;
                }
        }
}

Reply via email to