Can we get rid of non-raw write?

armando sano via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 15 07:47:45 PDT 2015


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)


More information about the Digitalmars-d mailing list