Closed
Description
Rust stdlib hangs instead of reporting EOF when stdin is pipe.
Testing with script:
echo aaa | ./program
C program, does not hang, exits properly:
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
int main() {
for (;;) {
char buf[1];
ssize_t r = read(STDIN_FILENO, buf, 1);
if (r == 0) {
break;
} else if (r < 0) {
perror("read");
exit(1);
} else {
printf("%d\n", (int) buf[0]);
}
}
return 0;
}
Rust program hangs on Linux, exits properly on OSX:
use std::rt::io::stdin;
use std::rt::io::Reader;
fn main() {
let mut r = stdin();
loop {
let b = r.read_byte();
if b.is_none() {
break;
}
println!("{}", b.unwrap());
}
}
Metadata
Metadata
Assignees
Labels
No labels