`std::freadall` puts 0's at the end if reading from stdin pipe for some reason.
On windows
@ske2004 How can I reproduce it?
import"std.um"
fn main() {
printf("%v", std::freadall(std::stdin()).item0)
}
W:\umka-extras>cat freadall.um | umka freadall.um
['i' 'm' 'p' 'o' 'r' 't' '"' 's' 't' 'd' '.' 'u' 'm' '"' 0x0A 0x0A 'f' 'n' ' ' 'm' 'a' 'i' 'n' '(' ')' ' ' '{' 0x0A ' ' ' ' 'p' 'r' 'i' 'n' 't' 'f' '(' '"' '%' 'v' '"' ',' ' ' 's' 't' 'd' ':' ':' 'f' 'r' 'e' 'a' 'd' 'a' 'l' 'l' '(' 's' 't' 'd' ':' ':' 's' 't' 'd' 'i' 'n' '(' ')' ')' '.' 'i' 't' 'e' 'm' '0' ')' 0x0A '}' 0x0A 0x00 0x00 0x00 0x00 0x00]
I think I see why, std::stdin() is opened with r instead of rb
@ske2004 Yes, you'll get as many 0's as there were 0x0D's removed when converting line endings. Then it will return the EOF error.
If it's a practical concern, I perhaps need to add std::freopen().
@ske2004 Yes, you'll get as many 0's as there were 0x0D's removed when converting line endings. Then it will return the EOF error.
If it's a practical concern, I perhaps need to add
std::freopen().
Is the default stdin pipe open with "r" on Windows? It would be pretty bad because CR could be part of binary stream instead.
@ske2004 It is:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/text-and-binary-mode-file-i-o?view=msvc-170
https://www.quora.com/How-do-you-read-from-a-binary-stream-from-stdin-in-C
@vtereshkov huh weird, i feel like we discussed this before. If it can be re-opened without ruining the host program, maybe it should be default
@ske2004 I remember we discussed the codepage, but not the opening mode.
I doubt how scanf() will work if we open stdin as "rb".