1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 03:57:44 +00:00

ls: fix mac build

This commit is contained in:
Terts Diepraam 2021-04-21 20:04:52 +02:00
parent 3fc8d2e422
commit 1d7e206d72

View file

@ -35,7 +35,7 @@ use std::{cmp::Reverse, process::exit};
use term_grid::{Cell, Direction, Filling, Grid, GridOptions}; use term_grid::{Cell, Direction, Filling, Grid, GridOptions};
use time::{strftime, Timespec}; use time::{strftime, Timespec};
#[cfg(unix)] #[cfg(unix)]
use uucore::libc::{mode_t, S_IXGRP, S_IXOTH, S_IXUSR}; use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR};
static VERSION: &str = env!("CARGO_PKG_VERSION"); static VERSION: &str = env!("CARGO_PKG_VERSION");
static ABOUT: &str = " static ABOUT: &str = "
@ -1444,10 +1444,13 @@ fn get_file_name(name: &Path, strip: Option<&Path>) -> String {
} }
#[cfg(unix)] #[cfg(unix)]
macro_rules! has { fn file_is_executable(md: &Metadata) -> bool {
($mode:expr, $perm:expr) => { // Mode always returns u32, but the flags might not be, based on the platform
$mode & ($perm as mode_t) != 0 // e.g. linux has u32, mac has u16.
}; // S_IXUSR -> user has execute permission
// S_IXGRP -> group has execute persmission
// S_IXOTH -> other users have execute permission
md.mode() & ((S_IXUSR | S_IXGRP | S_IXOTH) as u32) != 0
} }
#[allow(clippy::clippy::collapsible_else_if)] #[allow(clippy::clippy::collapsible_else_if)]
@ -1465,7 +1468,7 @@ fn classify_file(md: &Metadata) -> Option<char> {
Some('=') Some('=')
} else if file_type.is_fifo() { } else if file_type.is_fifo() {
Some('|') Some('|')
} else if file_type.is_file() || has!(md.mode(), S_IXUSR | S_IXGRP | S_IXOTH) { } else if file_type.is_file() && file_is_executable(&md) {
Some('*') Some('*')
} else { } else {
None None