Windows vs UTF-8 (issue 15845)

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Sun Apr 3 15:48:21 PDT 2016


On Sunday, 3 April 2016 at 21:55:39 UTC, ag0aep6g wrote:
>     ReadFile(GetStdHandle(STD_INPUT_HANDLE), &c, 1, &readBytes, 
> null).enforce();

I'm not sure if this is it or not, but you are asking for only 
one byte here, but giving it a multibyte sequence.

What happens if you give it a 4 char buffer? I imagine it would 
work fine then in all cases. It seems to for me.


The docs say it returns when "A write operation completes on the 
write end of the pipe." That's probably what is happening here, 
and then it doesn't have enough room in your buffer to put the 
message, so it reads zero. I'm not sure why it wouldn't return an 
error though... and it seems to remove the whole message from the 
buffer anyway... but still, it kinda makes sense that it wouldn't 
give you the partial input since it needs to be translated as a 
whole unit.

Regardless though, giving it a bigger buffer should work in all 
cases and has other benefits too, so that's probably what you 
should do.


More information about the Digitalmars-d mailing list