mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
address libc weirdness on 32 bit android
This commit is contained in:
parent
2a0d58d060
commit
1f025c19af
5 changed files with 12 additions and 6 deletions
|
@ -54,7 +54,7 @@ pub fn stdin_is_pipe_or_fifo() -> bool {
|
|||
fd >= 0 // GNU tail checks fd >= 0
|
||||
&& match fstat(fd) {
|
||||
Ok(stat) => {
|
||||
let mode = stat.st_mode;
|
||||
let mode = stat.st_mode as libc::mode_t;
|
||||
// NOTE: This is probably not the most correct way to check this
|
||||
(mode & S_IFIFO != 0) || (mode & S_IFSOCK != 0)
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ fn count_bytes_using_splice(fd: &impl AsRawFd) -> Result<usize, usize> {
|
|||
.map_err(|_| 0_usize)?;
|
||||
let null_rdev = stat::fstat(null_file.as_raw_fd())
|
||||
.map_err(|_| 0_usize)?
|
||||
.st_rdev;
|
||||
.st_rdev as libc::dev_t;
|
||||
if unsafe { (libc::major(null_rdev), libc::minor(null_rdev)) } != (1, 3) {
|
||||
// This is not a proper /dev/null, writing to it is probably bad
|
||||
// Bit of an edge case, but it has been known to happen
|
||||
|
@ -86,14 +86,14 @@ pub(crate) fn count_bytes_fast<T: WordCountable>(handle: &mut T) -> (usize, Opti
|
|||
// The second case happens for files in pseudo-filesystems. For
|
||||
// example with /proc/version and /sys/kernel/profiling. So,
|
||||
// if it is 0 we don't report that and instead do a full read.
|
||||
if (stat.st_mode & S_IFREG) != 0 && stat.st_size > 0 {
|
||||
if (stat.st_mode as libc::mode_t & S_IFREG) != 0 && stat.st_size > 0 {
|
||||
return (stat.st_size as usize, None);
|
||||
}
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
// Else, if we're on Linux and our file is a FIFO pipe
|
||||
// (or stdin), we use splice to count the number of bytes.
|
||||
if (stat.st_mode & S_IFIFO) != 0 {
|
||||
if (stat.st_mode as libc::mode_t & S_IFIFO) != 0 {
|
||||
match count_bytes_using_splice(handle) {
|
||||
Ok(n) => return (n, None),
|
||||
Err(n) => byte_count = n,
|
||||
|
|
|
@ -23,7 +23,7 @@ use nix::{errno::Errno, libc::S_IFIFO, sys::stat::fstat};
|
|||
use uucore::pipes::{pipe, splice_exact, vmsplice};
|
||||
|
||||
pub(crate) fn splice_data(bytes: &[u8], out: &impl AsRawFd) -> Result<()> {
|
||||
let is_pipe = fstat(out.as_raw_fd())?.st_mode & S_IFIFO != 0;
|
||||
let is_pipe = fstat(out.as_raw_fd())?.st_mode as nix::libc::mode_t & S_IFIFO != 0;
|
||||
|
||||
if is_pipe {
|
||||
loop {
|
||||
|
|
|
@ -183,7 +183,13 @@ impl Passwd {
|
|||
name: cstr2string(raw.pw_name).expect("passwd without name"),
|
||||
uid: raw.pw_uid,
|
||||
gid: raw.pw_gid,
|
||||
#[cfg(not(all(
|
||||
target_os = "android",
|
||||
any(target_arch = "x86", target_arch = "arm")
|
||||
)))]
|
||||
user_info: cstr2string(raw.pw_gecos),
|
||||
#[cfg(all(target_os = "android", any(target_arch = "x86", target_arch = "arm")))]
|
||||
user_info: None,
|
||||
user_shell: cstr2string(raw.pw_shell),
|
||||
user_dir: cstr2string(raw.pw_dir),
|
||||
user_passwd: cstr2string(raw.pw_passwd),
|
||||
|
|
|
@ -670,7 +670,7 @@ impl AtPath {
|
|||
let name = CString::new(self.plus_as_string(fifo)).unwrap();
|
||||
let mut stat: libc::stat = std::mem::zeroed();
|
||||
if libc::stat(name.as_ptr(), &mut stat) >= 0 {
|
||||
libc::S_IFIFO & stat.st_mode != 0
|
||||
libc::S_IFIFO & stat.st_mode as libc::mode_t != 0
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue