digitalmars.D - Add "setBinaryMode" and "setTextMode" to stdio?
- Johan Engelen (25/25) Jan 12 2016 Hi all,
- Jakob Ovrum (6/7) Jan 12 2016 std.stdio is intended as a wrapper around stdio.h, which I don't
- Johan Engelen (5/10) Jan 14 2016 I decided to implement a setRawMode, that basically makes
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
Jan 12 2016
On Wednesday, 13 January 2016 at 00:13:13 UTC, Johan Engelen wrote:Should I work on a PR for setBinaryMode+setTextMode ?std.stdio is intended as a wrapper around stdio.h, which I don't think supports setting the mode post-fopen, but if we can support those operations for all practical targets then I think they would be nice additions nevertheless.
Jan 12 2016
On Wednesday, 13 January 2016 at 01:48:13 UTC, Jakob Ovrum wrote:On Wednesday, 13 January 2016 at 00:13:13 UTC, Johan Engelen wrote:I decided to implement a setRawMode, that basically makes permanent the temporary changes that rawWrite/rawRead do. https://github.com/D-Programming-Language/phobos/pull/3929Should I work on a PR for setBinaryMode+setTextMode ?std.stdio is intended as a wrapper around stdio.h, which I don't think supports setting the mode post-fopen
Jan 14 2016








Johan Engelen <j j.nl>