From dd3b48ade0bc2a48188da2d32f0b7b09c0a68932 Mon Sep 17 00:00:00 2001 From: Johan Engelen <jbc.engelen@gmail.com> Date: Wed, 13 Jan 2016 00:59:03 +0100 Subject: [PATCH] Fix EOL output on Windows. Stdout has to be set to binary mode. --- src/dfmt/main.d | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/dfmt/main.d b/src/dfmt/main.d index c6f7275..58f3453 100644 --- a/src/dfmt/main.d +++ b/src/dfmt/main.d @@ -110,6 +110,22 @@ else return 1; File output = stdout; + version(Windows) + { + // On Windows, set stdout to binary mode (needed for correct EOL writing) + // See Phobos' stdio.File.rawWrite + { + import std.stdio; + immutable fd = fileno(output.getFP()); + setmode(fd, _O_BINARY); + version(CRuntime_DigitalMars) + { + import core.atomic : atomicOp; + atomicOp!"&="(__fhnd_info[fd], ~FHND_TEXT); + } + } + } + ubyte[] buffer; if (readFromStdin)