Use std::io::Error::last_os_error() for errno

This commit is contained in:
Victor Song 2023-03-08 01:30:48 -05:00 committed by ridiculousfish
parent ca494778e4
commit 3dfc9082e6

View file

@ -1,6 +1,9 @@
//! Implementation of the realpath builtin. //! Implementation of the realpath builtin.
use std::io::Error;
use libc::c_int; use libc::c_int;
use nix::errno::errno;
use crate::{ use crate::{
ffi::parser_t, ffi::parser_t,
@ -95,12 +98,22 @@ pub fn realpath(
if let Some(real_path) = wrealpath(arg) { if let Some(real_path) = wrealpath(arg) {
streams.out.append(real_path); streams.out.append(real_path);
} else { } else {
// TODO: get error from errno if errno() != 0 {
// Report the error and make it clear this is an error // realpath() just couldn't do it. Report the error and make it clear
// from our builtin, not the system's realpath. // this is an error from our builtin, not the system's realpath.
streams.err.append(wgettext_fmt!(
"builtin %ls: %ls: %s\n",
cmd,
arg,
Error::last_os_error().to_string()
));
} else {
// Who knows. Probably a bug in our wrealpath() implementation.
streams streams
.err .err
.append(wgettext_fmt!("builtin %ls: %ls\n", cmd, arg)); .append(wgettext_fmt!("builtin %ls: Invalid arg: %ls\n", cmd, arg));
}
return STATUS_CMD_ERROR; return STATUS_CMD_ERROR;
} }
} else { } else {
@ -115,10 +128,11 @@ pub fn realpath(
}; };
streams.out.append(normalize_path(&absolute_arg, false)); streams.out.append(normalize_path(&absolute_arg, false));
} else { } else {
// TODO: get error from errno streams.err.append(wgettext_fmt!(
streams "builtin %ls: realpath failed: %s\n",
.err cmd,
.append(wgettext_fmt!("builtin %ls: realpath failed\n", cmd)); std::io::Error::last_os_error().to_string()
));
return STATUS_CMD_ERROR; return STATUS_CMD_ERROR;
} }
} }