Skip to content

Commit

Permalink
Fix build on Redox, and add stat to Redox feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Nov 6, 2023
1 parent 692e829 commit 398ca50
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -240,6 +240,7 @@ feat_os_unix_redox = [
"feat_common_core",
#
"chmod",
"stat",
"uname",
]
# "feat_os_windows_legacy" == slightly restricted set of utilities which can be built/run on early windows platforms (eg, "WinXP")
Expand Down
6 changes: 4 additions & 2 deletions src/uu/cp/src/cp.rs
Expand Up @@ -1883,6 +1883,7 @@ fn copy_file(
Ok(())
}

#[allow(clippy::unnecessary_cast)]
#[cfg(unix)]
fn handle_no_preserve_mode(options: &Options, org_mode: u32) -> u32 {
let (is_preserve_mode, is_explicit_no_preserve_mode) = options.preserve_mode();
Expand All @@ -1898,8 +1899,9 @@ fn handle_no_preserve_mode(options: &Options, org_mode: u32) -> u32 {
target_os = "freebsd",
)))]
{
const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO;
const MODE_RW_UGO: u32 =
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32;
const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32;
match is_explicit_no_preserve_mode {
true => return MODE_RW_UGO,
false => return org_mode & S_IRWXUGO,
Expand Down
1 change: 1 addition & 0 deletions src/uu/date/src/date.rs
Expand Up @@ -242,6 +242,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
}
DateSource::File(ref path) => {
use uucore::error::FromIo;
if path.is_dir() {
return Err(USimpleError::new(
2,
Expand Down
2 changes: 1 addition & 1 deletion src/uu/df/src/df.rs
Expand Up @@ -336,7 +336,7 @@ fn filter_mount_list(vmi: Vec<MountInfo>, opt: &Options) -> Vec<MountInfo> {
fn get_all_filesystems(opt: &Options) -> Result<Vec<Filesystem>, std::io::Error> {
// Run a sync call before any operation if so instructed.
if opt.sync {
#[cfg(not(windows))]
#[cfg(not(any(windows, target_os = "redox")))]
unsafe {
#[cfg(not(target_os = "android"))]
uucore::libc::sync();
Expand Down
6 changes: 3 additions & 3 deletions src/uu/shred/src/shred.rs
Expand Up @@ -369,12 +369,12 @@ fn wipe_file(
let metadata = fs::metadata(path).map_err_context(String::new)?;
let mut perms = metadata.permissions();
#[cfg(unix)]
#[allow(clippy::useless_conversion)]
#[allow(clippy::useless_conversion, clippy::unnecessary_cast)]
{
// NOTE: set_readonly(false) makes the file world-writable on Unix.
// NOTE: S_IWUSR type is u16 on macOS.
if (perms.mode() & u32::from(S_IWUSR)) == 0 {
perms.set_mode(u32::from(S_IWUSR));
if (perms.mode() & u32::from(S_IWUSR as u32)) == 0 {
perms.set_mode(u32::from(S_IWUSR as u32));
}
}
#[cfg(not(unix))]
Expand Down
5 changes: 0 additions & 5 deletions src/uucore/src/lib/features/entries.rs
Expand Up @@ -35,7 +35,6 @@
#[cfg(any(target_os = "freebsd", target_vendor = "apple"))]
use libc::time_t;
use libc::{c_char, c_int, gid_t, uid_t};
#[cfg(not(target_os = "redox"))]
use libc::{getgrgid, getgrnam, getgroups};
use libc::{getpwnam, getpwuid, group, passwd};

Expand Down Expand Up @@ -67,7 +66,6 @@ extern "C" {
/// > supplementary group IDs for the process is returned. This allows
/// > the caller to determine the size of a dynamically allocated list
/// > to be used in a further call to getgroups().
#[cfg(not(target_os = "redox"))]
pub fn get_groups() -> IOResult<Vec<gid_t>> {
let mut groups = Vec::new();
loop {
Expand Down Expand Up @@ -337,15 +335,13 @@ macro_rules! f {
}

f!(getpwnam, getpwuid, uid_t, Passwd);
#[cfg(not(target_os = "redox"))]
f!(getgrnam, getgrgid, gid_t, Group);

#[inline]
pub fn uid2usr(id: uid_t) -> IOResult<String> {
Passwd::locate(id).map(|p| p.name)
}

#[cfg(not(target_os = "redox"))]
#[inline]
pub fn gid2grp(id: gid_t) -> IOResult<String> {
Group::locate(id).map(|p| p.name)
Expand All @@ -356,7 +352,6 @@ pub fn usr2uid(name: &str) -> IOResult<uid_t> {
Passwd::locate(name).map(|p| p.uid)
}

#[cfg(not(target_os = "redox"))]
#[inline]
pub fn grp2gid(name: &str) -> IOResult<gid_t> {
Group::locate(name).map(|p| p.gid)
Expand Down
11 changes: 8 additions & 3 deletions src/uucore/src/lib/features/fsext.rs
Expand Up @@ -71,6 +71,7 @@ use std::convert::{AsRef, From};
target_os = "android",
target_os = "illumos",
target_os = "solaris",
target_os = "redox",
))]
use std::ffi::CStr;
#[cfg(not(windows))]
Expand Down Expand Up @@ -106,15 +107,15 @@ pub use libc::statvfs as StatFs;
target_vendor = "apple",
target_os = "freebsd",
target_os = "openbsd",
target_os = "redox"
))]
pub use libc::statfs as statfs_fn;
#[cfg(any(
target_os = "netbsd",
target_os = "bitrig",
target_os = "illumos",
target_os = "solaris",
target_os = "dragonfly"
target_os = "dragonfly",
target_os = "redox"
))]
pub use libc::statvfs as statfs_fn;

Expand Down Expand Up @@ -619,13 +620,15 @@ impl FsMeta for StatFs {
not(target_os = "freebsd"),
not(target_os = "illumos"),
not(target_os = "solaris"),
not(target_os = "redox"),
not(target_arch = "s390x"),
target_pointer_width = "64"
))]
return self.f_bsize;
#[cfg(all(
not(target_env = "musl"),
not(target_os = "freebsd"),
not(target_os = "redox"),
any(
target_arch = "s390x",
target_vendor = "apple",
Expand All @@ -638,7 +641,8 @@ impl FsMeta for StatFs {
target_env = "musl",
target_os = "freebsd",
target_os = "illumos",
target_os = "solaris"
target_os = "solaris",
target_os = "redox"
))]
return self.f_bsize.try_into().unwrap();
}
Expand Down Expand Up @@ -846,6 +850,7 @@ pub fn pretty_time(sec: i64, nsec: i64) -> String {
// the date was set
let local_offset = match UtcOffset::local_offset_at(tm) {
Ok(lo) => lo,
Err(_) if cfg!(target_os = "redox") => UtcOffset::UTC,
Err(e) => {
panic!("error: {e}");
}
Expand Down
17 changes: 12 additions & 5 deletions src/uucore/src/lib/features/mode.rs
Expand Up @@ -137,6 +137,7 @@ fn parse_change(mode: &str, fperm: u32, considering_dir: bool) -> (u32, usize) {
(srwx, pos)
}

#[allow(clippy::unnecessary_cast)]
pub fn parse_mode(mode: &str) -> Result<mode_t, String> {
#[cfg(all(
not(target_os = "freebsd"),
Expand All @@ -148,9 +149,9 @@ pub fn parse_mode(mode: &str) -> Result<mode_t, String> {
let fperm = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32;

let result = if mode.chars().any(|c| c.is_ascii_digit()) {
parse_numeric(fperm, mode, true)
parse_numeric(fperm as _, mode, true)
} else {
parse_symbolic(fperm, mode, get_umask(), true)
parse_symbolic(fperm as _, mode, get_umask(), true)
};
result.map(|mode| mode as mode_t)
}
Expand All @@ -168,11 +169,17 @@ pub fn get_umask() -> u32 {
#[cfg(all(
not(target_os = "freebsd"),
not(target_vendor = "apple"),
not(target_os = "android")
not(target_os = "android"),
not(target_os = "redox")
))]
return mask;
#[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "android"))]
return mask.into();
#[cfg(any(
target_os = "freebsd",
target_vendor = "apple",
target_os = "android",
target_os = "redox"
))]
return mask as u32;
}

// Iterate 'args' and delete the first occurrence
Expand Down
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/signals.rs
Expand Up @@ -27,7 +27,7 @@ Linux Programmer's Manual
*/

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "redox"))]
pub static ALL_SIGNALS: [&str; 32] = [
"EXIT", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "BUS", "FPE", "KILL", "USR1", "SEGV",
"USR2", "PIPE", "ALRM", "TERM", "STKFLT", "CHLD", "CONT", "STOP", "TSTP", "TTIN", "TTOU",
Expand Down

0 comments on commit 398ca50

Please sign in to comment.