diff --git a/src/common.rs b/src/common.rs index 433508ed4..9b4c55d4c 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1468,7 +1468,7 @@ fn can_be_encoded(wc: char) -> bool { } /// Call read, blocking and repeating on EINTR. Exits on EAGAIN. -/// \return the number of bytes read, or 0 on EOF. On EAGAIN, returns -1 if nothing was read. +/// \return the number of bytes read, or 0 on EOF, or an error. pub fn read_blocked(fd: RawFd, buf: &mut [u8]) -> nix::Result { loop { let res = nix::unistd::read(fd, buf); diff --git a/src/fork_exec/flog_safe.rs b/src/fork_exec/flog_safe.rs index 164db4f16..d1c0a922b 100644 --- a/src/fork_exec/flog_safe.rs +++ b/src/fork_exec/flog_safe.rs @@ -84,7 +84,9 @@ pub fn flog_impl_async_safe(fd: i32, s: impl FloggableDisplayAsyncSafe) { let bytes: &[u8] = s.to_flog_str_async_safe(&mut storage); // Note we deliberately do not retry on signals, etc. // This is used to report error messages after fork() in the child process. - let _ = nix::unistd::write(fd, bytes); + unsafe { + let _ = libc::write(fd, bytes.as_ptr() as *const libc::c_void, bytes.len()); + } } /// Variant of FLOG which is async-safe to use after fork(). diff --git a/src/history/file.rs b/src/history/file.rs index 887ea92ea..6abbf6ff2 100644 --- a/src/history/file.rs +++ b/src/history/file.rs @@ -228,7 +228,6 @@ fn should_mmap() -> bool { } /// Read from `fd` to fill `dest`, zeroing any unused space. -// Return true on success, false on failure. fn read_from_fd(fd: RawFd, mut dest: &mut [u8]) -> nix::Result<()> { while !dest.is_empty() { match nix::unistd::read(fd, dest) { diff --git a/src/reader.rs b/src/reader.rs index ad3a46d38..85bf99d17 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -684,7 +684,7 @@ fn read_ni(parser: &Parser, fd: RawFd, io: &IoChain) -> i32 { return 1; } - // Read all data into a std::string. + // Read all data into a vec. let mut fd_contents = Vec::with_capacity(usize::try_from(buf.st_size).unwrap()); loop { let mut buff = [0_u8; 4096];