When trying to make sense of issue 15845 [1], I've found Windows behaving outright broken. I don't have a clue about Windows programming, though, so it's very possible that I'm just missing something. I'd hope so.

Code:
----
import std.stdio;
import std.exception: enforce;
import core.sys.windows.windows;

void main()
{
    SetConsoleCP(65001);
    SetConsoleOutputCP(65001);

    uint readBytes;
    ubyte c;
ReadFile(GetStdHandle(STD_INPUT_HANDLE), &c, 1, &readBytes, null).enforce();
    writeln(readBytes, " ", c);
}
----

This works for ASCII characters. It does not work for non-ASCII characters, e.g. 'ü'. ReadFile does not indicate an error, but it also doesn't read anything.

I can't find any explanation for this in the documentation for Readfile [2] or via Google. The same happens with -m32, -m64, fgetc, fgets. It also happens with equivalent C programs compiled with Visual Studio 2015.

I did find out that this apparently only happens when stdin is considered a TTY. According to _isatty [3], stdin is not a TTY when I use a pipe for input, e.g. `echo ä | test`, and then it works.

Does this make sense to anyone?


[1] https://issues.dlang.org/show_bug.cgi?id=15845
[2] https://msdn.microsoft.com/en-us/library/aa365467.aspx (ReadFile)
[3] https://msdn.microsoft.com/en-us/library/f4s0ddew.aspx (_isatty)

Reply via email to