mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 14:52:41 +00:00
Fix build on Redox, and add stat
to Redox feature
This commit is contained in:
parent
673093f842
commit
db91e12a1d
9 changed files with 29 additions and 20 deletions
|
@ -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")
|
||||
|
|
|
@ -1896,6 +1896,7 @@ fn handle_no_preserve_mode(options: &Options, org_mode: u32) -> u32 {
|
|||
target_os = "macos",
|
||||
target_os = "macos-12",
|
||||
target_os = "freebsd",
|
||||
target_os = "redox",
|
||||
)))]
|
||||
{
|
||||
const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
|
||||
|
@ -1911,6 +1912,7 @@ fn handle_no_preserve_mode(options: &Options, org_mode: u32) -> u32 {
|
|||
target_os = "macos",
|
||||
target_os = "macos-12",
|
||||
target_os = "freebsd",
|
||||
target_os = "redox",
|
||||
))]
|
||||
{
|
||||
const MODE_RW_UGO: u32 =
|
||||
|
|
|
@ -16,7 +16,6 @@ use std::fs::File;
|
|||
use std::io::{BufRead, BufReader};
|
||||
use std::path::PathBuf;
|
||||
use uucore::display::Quotable;
|
||||
#[cfg(not(any(target_os = "redox")))]
|
||||
use uucore::error::FromIo;
|
||||
use uucore::error::{UResult, USimpleError};
|
||||
use uucore::{format_usage, help_about, help_usage, show};
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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));
|
||||
// NOTE: S_IWUSR type is u16 on macOS, i32 on Redox.
|
||||
if (perms.mode() & (S_IWUSR as u32)) == 0 {
|
||||
perms.set_mode(S_IWUSR as u32);
|
||||
}
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -337,7 +335,6 @@ macro_rules! f {
|
|||
}
|
||||
|
||||
f!(getpwnam, getpwuid, uid_t, Passwd);
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
f!(getgrnam, getgrgid, gid_t, Group);
|
||||
|
||||
#[inline]
|
||||
|
@ -345,7 +342,6 @@ 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)
|
||||
|
@ -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)
|
||||
|
|
|
@ -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))]
|
||||
|
@ -106,7 +107,6 @@ 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(
|
||||
|
@ -114,7 +114,8 @@ pub use libc::statfs as statfs_fn;
|
|||
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;
|
||||
|
||||
|
@ -639,6 +640,7 @@ impl FsMeta for StatFs {
|
|||
not(target_os = "openbsd"),
|
||||
not(target_os = "illumos"),
|
||||
not(target_os = "solaris"),
|
||||
not(target_os = "redox"),
|
||||
not(target_arch = "s390x"),
|
||||
target_pointer_width = "64"
|
||||
))]
|
||||
|
@ -646,6 +648,7 @@ impl FsMeta for StatFs {
|
|||
#[cfg(all(
|
||||
not(target_env = "musl"),
|
||||
not(target_os = "freebsd"),
|
||||
not(target_os = "redox"),
|
||||
any(
|
||||
target_arch = "s390x",
|
||||
target_vendor = "apple",
|
||||
|
@ -659,7 +662,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();
|
||||
}
|
||||
|
@ -875,6 +879,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}");
|
||||
}
|
||||
|
|
|
@ -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"),
|
||||
|
@ -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 u32, mode, true)
|
||||
} else {
|
||||
parse_symbolic(fperm, mode, get_umask(), true)
|
||||
parse_symbolic(fperm as u32, mode, get_umask(), true)
|
||||
};
|
||||
result.map(|mode| mode as mode_t)
|
||||
}
|
||||
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue