On Friday, 11 December 2020 at 15:57:37 UTC, frame wrote:
On Friday, 11 December 2020 at 12:34:19 UTC, kdevel wrote:
My code cannot do that because the function byChunk has
control over the
file descriptor.
What do you mean by control?
The error happens while the cpu executes code of the D runtime
(or the C library).
After looking into std/stdio.d I found that byChunk uses fread
(not read). Thus I think I ran into [1] which seems to affect
quite a lot of programs [2] [3].
~~~bychunk.d
void main ()
{
import std.stdio;
foreach (buf; stdin.byChunk (4096)) {
auto s = cast (string) buf;
writeln ("buf = <", s, ">");
}
}
~~~
STR:
1. ./bychunk
2. A, [RETURN]
3. CTRL+D
expected: program ends
found: program still reading
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=1190
Bug 1190 Summary: fgetc()/fread() behaviour is not POSIX
compliant
[2]
https://unix.stackexchange.com/questions/517064/why-does-hexdump-try-to-read-through-eof
[3]
https://stackoverflow.com/questions/52674057/why-does-an-fread-loop-require-an-extra-ctrld-to-signal-eof-with-glibc