mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
Merge pull request #5502 from ids1024/redox
Fix build on Redox, and add `stat` to Redox feature
This commit is contained in:
commit
62afd786f6
9 changed files with 29 additions and 20 deletions
|
@ -240,6 +240,7 @@ feat_os_unix_redox = [
|
||||||
"feat_common_core",
|
"feat_common_core",
|
||||||
#
|
#
|
||||||
"chmod",
|
"chmod",
|
||||||
|
"stat",
|
||||||
"uname",
|
"uname",
|
||||||
]
|
]
|
||||||
# "feat_os_windows_legacy" == slightly restricted set of utilities which can be built/run on early windows platforms (eg, "WinXP")
|
# "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",
|
||||||
target_os = "macos-12",
|
target_os = "macos-12",
|
||||||
target_os = "freebsd",
|
target_os = "freebsd",
|
||||||
|
target_os = "redox",
|
||||||
)))]
|
)))]
|
||||||
{
|
{
|
||||||
const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
|
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",
|
||||||
target_os = "macos-12",
|
target_os = "macos-12",
|
||||||
target_os = "freebsd",
|
target_os = "freebsd",
|
||||||
|
target_os = "redox",
|
||||||
))]
|
))]
|
||||||
{
|
{
|
||||||
const MODE_RW_UGO: u32 =
|
const MODE_RW_UGO: u32 =
|
||||||
|
|
|
@ -16,7 +16,6 @@ use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader};
|
use std::io::{BufRead, BufReader};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
#[cfg(not(any(target_os = "redox")))]
|
|
||||||
use uucore::error::FromIo;
|
use uucore::error::FromIo;
|
||||||
use uucore::error::{UResult, USimpleError};
|
use uucore::error::{UResult, USimpleError};
|
||||||
use uucore::{format_usage, help_about, help_usage, show};
|
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> {
|
fn get_all_filesystems(opt: &Options) -> Result<Vec<Filesystem>, std::io::Error> {
|
||||||
// Run a sync call before any operation if so instructed.
|
// Run a sync call before any operation if so instructed.
|
||||||
if opt.sync {
|
if opt.sync {
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(any(windows, target_os = "redox")))]
|
||||||
unsafe {
|
unsafe {
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
uucore::libc::sync();
|
uucore::libc::sync();
|
||||||
|
|
|
@ -369,12 +369,12 @@ fn wipe_file(
|
||||||
let metadata = fs::metadata(path).map_err_context(String::new)?;
|
let metadata = fs::metadata(path).map_err_context(String::new)?;
|
||||||
let mut perms = metadata.permissions();
|
let mut perms = metadata.permissions();
|
||||||
#[cfg(unix)]
|
#[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: set_readonly(false) makes the file world-writable on Unix.
|
||||||
// NOTE: S_IWUSR type is u16 on macOS.
|
// NOTE: S_IWUSR type is u16 on macOS, i32 on Redox.
|
||||||
if (perms.mode() & u32::from(S_IWUSR)) == 0 {
|
if (perms.mode() & (S_IWUSR as u32)) == 0 {
|
||||||
perms.set_mode(u32::from(S_IWUSR));
|
perms.set_mode(S_IWUSR as u32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
#[cfg(any(target_os = "freebsd", target_vendor = "apple"))]
|
#[cfg(any(target_os = "freebsd", target_vendor = "apple"))]
|
||||||
use libc::time_t;
|
use libc::time_t;
|
||||||
use libc::{c_char, c_int, gid_t, uid_t};
|
use libc::{c_char, c_int, gid_t, uid_t};
|
||||||
#[cfg(not(target_os = "redox"))]
|
|
||||||
use libc::{getgrgid, getgrnam, getgroups};
|
use libc::{getgrgid, getgrnam, getgroups};
|
||||||
use libc::{getpwnam, getpwuid, group, passwd};
|
use libc::{getpwnam, getpwuid, group, passwd};
|
||||||
|
|
||||||
|
@ -67,7 +66,6 @@ extern "C" {
|
||||||
/// > supplementary group IDs for the process is returned. This allows
|
/// > supplementary group IDs for the process is returned. This allows
|
||||||
/// > the caller to determine the size of a dynamically allocated list
|
/// > the caller to determine the size of a dynamically allocated list
|
||||||
/// > to be used in a further call to getgroups().
|
/// > to be used in a further call to getgroups().
|
||||||
#[cfg(not(target_os = "redox"))]
|
|
||||||
pub fn get_groups() -> IOResult<Vec<gid_t>> {
|
pub fn get_groups() -> IOResult<Vec<gid_t>> {
|
||||||
let mut groups = Vec::new();
|
let mut groups = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
|
@ -337,7 +335,6 @@ macro_rules! f {
|
||||||
}
|
}
|
||||||
|
|
||||||
f!(getpwnam, getpwuid, uid_t, Passwd);
|
f!(getpwnam, getpwuid, uid_t, Passwd);
|
||||||
#[cfg(not(target_os = "redox"))]
|
|
||||||
f!(getgrnam, getgrgid, gid_t, Group);
|
f!(getgrnam, getgrgid, gid_t, Group);
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -345,7 +342,6 @@ pub fn uid2usr(id: uid_t) -> IOResult<String> {
|
||||||
Passwd::locate(id).map(|p| p.name)
|
Passwd::locate(id).map(|p| p.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "redox"))]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn gid2grp(id: gid_t) -> IOResult<String> {
|
pub fn gid2grp(id: gid_t) -> IOResult<String> {
|
||||||
Group::locate(id).map(|p| p.name)
|
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)
|
Passwd::locate(name).map(|p| p.uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "redox"))]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn grp2gid(name: &str) -> IOResult<gid_t> {
|
pub fn grp2gid(name: &str) -> IOResult<gid_t> {
|
||||||
Group::locate(name).map(|p| p.gid)
|
Group::locate(name).map(|p| p.gid)
|
||||||
|
|
|
@ -71,6 +71,7 @@ use std::convert::{AsRef, From};
|
||||||
target_os = "android",
|
target_os = "android",
|
||||||
target_os = "illumos",
|
target_os = "illumos",
|
||||||
target_os = "solaris",
|
target_os = "solaris",
|
||||||
|
target_os = "redox",
|
||||||
))]
|
))]
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
|
@ -106,7 +107,6 @@ pub use libc::statvfs as StatFs;
|
||||||
target_vendor = "apple",
|
target_vendor = "apple",
|
||||||
target_os = "freebsd",
|
target_os = "freebsd",
|
||||||
target_os = "openbsd",
|
target_os = "openbsd",
|
||||||
target_os = "redox"
|
|
||||||
))]
|
))]
|
||||||
pub use libc::statfs as statfs_fn;
|
pub use libc::statfs as statfs_fn;
|
||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
|
@ -114,7 +114,8 @@ pub use libc::statfs as statfs_fn;
|
||||||
target_os = "bitrig",
|
target_os = "bitrig",
|
||||||
target_os = "illumos",
|
target_os = "illumos",
|
||||||
target_os = "solaris",
|
target_os = "solaris",
|
||||||
target_os = "dragonfly"
|
target_os = "dragonfly",
|
||||||
|
target_os = "redox"
|
||||||
))]
|
))]
|
||||||
pub use libc::statvfs as statfs_fn;
|
pub use libc::statvfs as statfs_fn;
|
||||||
|
|
||||||
|
@ -639,6 +640,7 @@ impl FsMeta for StatFs {
|
||||||
not(target_os = "openbsd"),
|
not(target_os = "openbsd"),
|
||||||
not(target_os = "illumos"),
|
not(target_os = "illumos"),
|
||||||
not(target_os = "solaris"),
|
not(target_os = "solaris"),
|
||||||
|
not(target_os = "redox"),
|
||||||
not(target_arch = "s390x"),
|
not(target_arch = "s390x"),
|
||||||
target_pointer_width = "64"
|
target_pointer_width = "64"
|
||||||
))]
|
))]
|
||||||
|
@ -646,6 +648,7 @@ impl FsMeta for StatFs {
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
not(target_env = "musl"),
|
not(target_env = "musl"),
|
||||||
not(target_os = "freebsd"),
|
not(target_os = "freebsd"),
|
||||||
|
not(target_os = "redox"),
|
||||||
any(
|
any(
|
||||||
target_arch = "s390x",
|
target_arch = "s390x",
|
||||||
target_vendor = "apple",
|
target_vendor = "apple",
|
||||||
|
@ -659,7 +662,8 @@ impl FsMeta for StatFs {
|
||||||
target_env = "musl",
|
target_env = "musl",
|
||||||
target_os = "freebsd",
|
target_os = "freebsd",
|
||||||
target_os = "illumos",
|
target_os = "illumos",
|
||||||
target_os = "solaris"
|
target_os = "solaris",
|
||||||
|
target_os = "redox"
|
||||||
))]
|
))]
|
||||||
return self.f_bsize.try_into().unwrap();
|
return self.f_bsize.try_into().unwrap();
|
||||||
}
|
}
|
||||||
|
@ -875,6 +879,7 @@ pub fn pretty_time(sec: i64, nsec: i64) -> String {
|
||||||
// the date was set
|
// the date was set
|
||||||
let local_offset = match UtcOffset::local_offset_at(tm) {
|
let local_offset = match UtcOffset::local_offset_at(tm) {
|
||||||
Ok(lo) => lo,
|
Ok(lo) => lo,
|
||||||
|
Err(_) if cfg!(target_os = "redox") => UtcOffset::UTC,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
panic!("error: {e}");
|
panic!("error: {e}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,6 +137,7 @@ fn parse_change(mode: &str, fperm: u32, considering_dir: bool) -> (u32, usize) {
|
||||||
(srwx, pos)
|
(srwx, pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::unnecessary_cast)]
|
||||||
pub fn parse_mode(mode: &str) -> Result<mode_t, String> {
|
pub fn parse_mode(mode: &str) -> Result<mode_t, String> {
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
not(target_os = "freebsd"),
|
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 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()) {
|
let result = if mode.chars().any(|c| c.is_ascii_digit()) {
|
||||||
parse_numeric(fperm, mode, true)
|
parse_numeric(fperm as u32, mode, true)
|
||||||
} else {
|
} else {
|
||||||
parse_symbolic(fperm, mode, get_umask(), true)
|
parse_symbolic(fperm as u32, mode, get_umask(), true)
|
||||||
};
|
};
|
||||||
result.map(|mode| mode as mode_t)
|
result.map(|mode| mode as mode_t)
|
||||||
}
|
}
|
||||||
|
@ -168,11 +169,17 @@ pub fn get_umask() -> u32 {
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
not(target_os = "freebsd"),
|
not(target_os = "freebsd"),
|
||||||
not(target_vendor = "apple"),
|
not(target_vendor = "apple"),
|
||||||
not(target_os = "android")
|
not(target_os = "android"),
|
||||||
|
not(target_os = "redox")
|
||||||
))]
|
))]
|
||||||
return mask;
|
return mask;
|
||||||
#[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "android"))]
|
#[cfg(any(
|
||||||
return mask.into();
|
target_os = "freebsd",
|
||||||
|
target_vendor = "apple",
|
||||||
|
target_os = "android",
|
||||||
|
target_os = "redox"
|
||||||
|
))]
|
||||||
|
return mask as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate 'args' and delete the first occurrence
|
// 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] = [
|
pub static ALL_SIGNALS: [&str; 32] = [
|
||||||
"EXIT", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "BUS", "FPE", "KILL", "USR1", "SEGV",
|
"EXIT", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "BUS", "FPE", "KILL", "USR1", "SEGV",
|
||||||
"USR2", "PIPE", "ALRM", "TERM", "STKFLT", "CHLD", "CONT", "STOP", "TSTP", "TTIN", "TTOU",
|
"USR2", "PIPE", "ALRM", "TERM", "STKFLT", "CHLD", "CONT", "STOP", "TSTP", "TTIN", "TTOU",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue