Skip to main content

write_loop

Function write_loop 

Source
pub fn write_loop(fd: i32, buf: &[u8]) -> Result<usize>
Expand description

Port of ssize_t write_loop(int fd, const char *buf, size_t len) from Src/utils.c:2949.

C body (c:2949-2970):

while (1) {
    ssize_t ret = write(fd, buf, len);
    if (ret == len) break;
    if (ret < 0) {
        if (errno == EINTR) continue;
        if (fd != SHTTY)                            // c:2960
            zwarn("write failed: %e", errno);       // c:2961
        return -1;
    }
    buf += ret; len -= ret;
}

Same divergence as read_loop: previous Rust port omitted the zwarn("write failed: %e", errno) emission for non-SHTTY fds. WARNING: param names don’t match C — Rust=(fd, buf) vs C=(fd, buf, len)