pub fn read_loop(fd: i32, buf: &mut [u8]) -> Result<usize>Expand description
Port of ssize_t read_loop(int fd, char *buf, size_t len) from
Src/utils.c:2923.
C body (c:2923-2945):
while (1) {
ssize_t ret = read(fd, buf, len);
if (ret == len) break;
if (ret <= 0) {
if (ret < 0) {
if (errno == EINTR) continue; // c:2933
if (fd != SHTTY) // c:2935
zwarn("read failed: %e", errno); // c:2936
}
return ret;
}
buf += ret; len -= ret;
}The previous Rust port omitted the zwarn("read failed: %e", errno)
emission at c:2935-2936. That’s a real diagnostic divergence:
any non-SHTTY read failure in zsh emits a stderr message; the
Rust port silently propagated the io::Error to the caller, which
in most call sites was discarded (let _ = read_loop(...)).
Users debugging an interrupted file read (e.g. < /broken/fd)
would see no error message at all.
WARNING: param names don’t match C — Rust=(fd, buf) vs C=(fd, buf, len)