pub mod io;
#[inline]
pub fn gnu_name(binary_name: &str) -> &str {
binary_name.strip_prefix('f').unwrap_or(binary_name)
}
#[inline]
pub fn reset_sigpipe() {
#[cfg(unix)]
unsafe {
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
}
}
#[cfg(target_os = "linux")]
pub fn enlarge_stdout_pipe() {
let mut stat: libc::stat = unsafe { std::mem::zeroed() };
if unsafe { libc::fstat(1, &mut stat) } != 0 {
return;
}
if (stat.st_mode & libc::S_IFMT) != libc::S_IFIFO {
return;
}
for &size in &[8 * 1024 * 1024i32, 1024 * 1024, 256 * 1024] {
if unsafe { libc::fcntl(1, libc::F_SETPIPE_SZ, size) } > 0 {
break;
}
}
}
#[cfg(not(target_os = "linux"))]
pub fn enlarge_stdout_pipe() {}
#[cold]
#[inline(never)]
pub fn io_error_msg(e: &std::io::Error) -> String {
if let Some(raw) = e.raw_os_error() {
let os_err = std::io::Error::from_raw_os_error(raw);
let msg = format!("{}", os_err);
msg.replace(&format!(" (os error {})", raw), "")
} else {
format!("{}", e)
}
}