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

Merge pull request #4238 from Joining7943/fix-cargo-clippy-doc-warnings

cargo: Fix cargo clippy doc warnings
This commit is contained in:
Sylvestre Ledru 2022-12-17 16:51:30 +01:00 committed by GitHub
commit 4f90c680c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 199 additions and 62 deletions

View file

@ -27,7 +27,7 @@ const fn generate_crc_table() -> [u32; CRC_TABLE_LEN] {
let mut i = 0; let mut i = 0;
while i < CRC_TABLE_LEN { while i < CRC_TABLE_LEN {
table[i] = crc_entry(i as u8) as u32; table[i] = crc_entry(i as u8);
i += 1; i += 1;
} }

View file

@ -228,7 +228,7 @@ impl<'a> SplitWriter<'a> {
/// The creation of the split file may fail with some [`io::Error`]. /// The creation of the split file may fail with some [`io::Error`].
fn new_writer(&mut self) -> io::Result<()> { fn new_writer(&mut self) -> io::Result<()> {
let file_name = self.options.split_name.get(self.counter); let file_name = self.options.split_name.get(self.counter);
let file = File::create(&file_name)?; let file = File::create(file_name)?;
self.current_writer = Some(BufWriter::new(file)); self.current_writer = Some(BufWriter::new(file));
self.counter += 1; self.counter += 1;
self.size = 0; self.size = 0;

View file

@ -715,7 +715,7 @@ fn calc_loop_bsize(
Some(Num::Bytes(bmax)) => { Some(Num::Bytes(bmax)) => {
let bmax: u128 = (*bmax).try_into().unwrap(); let bmax: u128 = (*bmax).try_into().unwrap();
let bremain: u128 = bmax - wstat.bytes_total; let bremain: u128 = bmax - wstat.bytes_total;
cmp::min(ideal_bsize as u128, bremain as u128) as usize cmp::min(ideal_bsize as u128, bremain) as usize
} }
None => ideal_bsize, None => ideal_bsize,
} }

View file

@ -67,7 +67,7 @@ pub fn guess_syntax() -> OutputFmt {
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore(); let args = args.collect_ignore();
let matches = uu_app().try_get_matches_from(&args)?; let matches = uu_app().try_get_matches_from(args)?;
let files = matches let files = matches
.get_many::<String>(options::FILE) .get_many::<String>(options::FILE)

View file

@ -143,7 +143,7 @@ impl Stat {
path, path,
is_dir: metadata.is_dir(), is_dir: metadata.is_dir(),
size: metadata.len(), size: metadata.len(),
blocks: metadata.blocks() as u64, blocks: metadata.blocks(),
inodes: 1, inodes: 1,
inode: Some(file_info), inode: Some(file_info),
created: birth_u64(&metadata), created: birth_u64(&metadata),
@ -188,7 +188,7 @@ fn birth_u64(meta: &Metadata) -> Option<u64> {
meta.created() meta.created()
.ok() .ok()
.and_then(|t| t.duration_since(UNIX_EPOCH).ok()) .and_then(|t| t.duration_since(UNIX_EPOCH).ok())
.map(|e| e.as_secs() as u64) .map(|e| e.as_secs())
} }
#[cfg(windows)] #[cfg(windows)]
@ -807,7 +807,7 @@ pub fn uu_app() -> Command {
// .short('P') // .short('P')
// .long("no-dereference") // .long("no-dereference")
// .help("don't follow any symbolic links (this is the default)") // .help("don't follow any symbolic links (this is the default)")
// .action(ArgAction::SetTrue), // .action(ArgAction::SetTrue),
// ) // )
.arg( .arg(
Arg::new(options::BLOCK_SIZE_1M) Arg::new(options::BLOCK_SIZE_1M)

View file

@ -37,7 +37,7 @@ mod sieve;
#[cfg_attr(test, allow(dead_code))] #[cfg_attr(test, allow(dead_code))]
fn main() { fn main() {
let out_dir = env::var("OUT_DIR").unwrap(); let out_dir = env::var("OUT_DIR").unwrap();
let mut file = File::create(&Path::new(&out_dir).join("prime_table.rs")).unwrap(); let mut file = File::create(Path::new(&out_dir).join("prime_table.rs")).unwrap();
// By default, we print the multiplicative inverses mod 2^64 of the first 1k primes // By default, we print the multiplicative inverses mod 2^64 of the first 1k primes
const DEFAULT_SIZE: usize = 320; const DEFAULT_SIZE: usize = 320;

View file

@ -274,9 +274,7 @@ fn fold_file<T: Read>(mut file: BufReader<T>, spaces: bool, width: usize) -> URe
last_space = if spaces { Some(output.len()) } else { None }; last_space = if spaces { Some(output.len()) } else { None };
} }
'\x08' => { '\x08' => {
if col_count > 0 { col_count = col_count.saturating_sub(1);
col_count -= 1;
}
} }
_ if spaces && ch.is_whitespace() => { _ if spaces && ch.is_whitespace() => {
last_space = Some(output.len()); last_space = Some(output.len());

View file

@ -438,7 +438,7 @@ fn link(src: &Path, dst: &Path, settings: &Settings) -> UResult<()> {
} else { } else {
source.to_path_buf() source.to_path_buf()
}; };
fs::hard_link(&p, dst).map_err_context(|| { fs::hard_link(p, dst).map_err_context(|| {
format!( format!(
"failed to create hard link {} => {}", "failed to create hard link {} => {}",
source.quote(), source.quote(),

View file

@ -2702,7 +2702,8 @@ fn file_is_executable(md: &Metadata) -> bool {
// S_IXUSR -> user has execute permission // S_IXUSR -> user has execute permission
// S_IXGRP -> group has execute permission // S_IXGRP -> group has execute permission
// S_IXOTH -> other users have execute permission // S_IXOTH -> other users have execute permission
md.mode() & ((S_IXUSR | S_IXGRP | S_IXOTH) as u32) != 0 #[allow(clippy::unnecessary_cast)]
return md.mode() & ((S_IXUSR | S_IXGRP | S_IXOTH) as u32) != 0;
} }
fn classify_file(path: &PathData, out: &mut BufWriter<Stdout>) -> Option<char> { fn classify_file(path: &PathData, out: &mut BufWriter<Stdout>) -> Option<char> {

View file

@ -564,7 +564,7 @@ fn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> {
let path_symlink_points_to = fs::read_link(from)?; let path_symlink_points_to = fs::read_link(from)?;
#[cfg(unix)] #[cfg(unix)]
{ {
unix::fs::symlink(&path_symlink_points_to, to).and_then(|_| fs::remove_file(from))?; unix::fs::symlink(path_symlink_points_to, to).and_then(|_| fs::remove_file(from))?;
} }
#[cfg(windows)] #[cfg(windows)]
{ {

View file

@ -277,9 +277,11 @@ impl Pinky {
let mesg; let mesg;
let last_change; let last_change;
match pts_path.metadata() { match pts_path.metadata() {
#[allow(clippy::unnecessary_cast)]
Ok(meta) => { Ok(meta) => {
mesg = if meta.mode() & (S_IWGRP as u32) != 0 { mesg = if meta.mode() & S_IWGRP as u32 != 0 {
' ' ' '
} else { } else {
'*' '*'

View file

@ -439,7 +439,7 @@ fn get_output_chunks(
) -> (String, String, String, String) { ) -> (String, String, String, String) {
// Chunk size logics are mostly copied from the GNU ptx source. // Chunk size logics are mostly copied from the GNU ptx source.
// https://github.com/MaiZure/coreutils-8.3/blob/master/src/ptx.c#L1234 // https://github.com/MaiZure/coreutils-8.3/blob/master/src/ptx.c#L1234
let half_line_size = (config.line_width / 2) as usize; let half_line_size = config.line_width / 2;
let max_before_size = cmp::max(half_line_size as isize - config.gap_size as isize, 0) as usize; let max_before_size = cmp::max(half_line_size as isize - config.gap_size as isize, 0) as usize;
let max_after_size = cmp::max( let max_after_size = cmp::max(
half_line_size as isize half_line_size as isize
@ -500,7 +500,7 @@ fn get_output_chunks(
let (tail_beg, _) = trim_idx(all_after, after_end, all_after.len()); let (tail_beg, _) = trim_idx(all_after, after_end, all_after.len());
// end = begin + max length // end = begin + max length
let tail_end = cmp::min(all_after.len(), tail_beg + max_tail_size) as usize; let tail_end = cmp::min(all_after.len(), tail_beg + max_tail_size);
// in case that falls in the middle of a word, trim away the word. // in case that falls in the middle of a word, trim away the word.
let tail_end = trim_broken_word_right(all_after, tail_beg, tail_end); let tail_end = trim_broken_word_right(all_after, tail_beg, tail_end);

View file

@ -147,7 +147,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.map(Into::into) .map(Into::into)
.unwrap_or(cwd); .unwrap_or(cwd);
println_verbatim(&cwd).map_err_context(|| "failed to print current directory".to_owned())?; println_verbatim(cwd).map_err_context(|| "failed to print current directory".to_owned())?;
Ok(()) Ok(())
} }

View file

@ -259,7 +259,7 @@ fn resolve_path(
let abs = process_relative(abs, relative_base, relative_to); let abs = process_relative(abs, relative_base, relative_to);
print_verbatim(&abs)?; print_verbatim(abs)?;
stdout().write_all(&[line_ending])?; stdout().write_all(&[line_ending])?;
Ok(()) Ok(())
} }

View file

@ -520,6 +520,7 @@ fn handle_writable_directory(path: &Path, options: &Options, metadata: &Metadata
let mode = metadata.permissions().mode(); let mode = metadata.permissions().mode();
// Check if directory has user write permissions // Check if directory has user write permissions
// Why is S_IWUSR showing up as a u16 on macos? // Why is S_IWUSR showing up as a u16 on macos?
#[allow(clippy::unnecessary_cast)]
let user_writable = (mode & (libc::S_IWUSR as u32)) != 0; let user_writable = (mode & (libc::S_IWUSR as u32)) != 0;
if !user_writable { if !user_writable {
prompt_yes!("remove write-protected directory {}?", path.quote()) prompt_yes!("remove write-protected directory {}?", path.quote())

View file

@ -1115,7 +1115,7 @@ where
// of bytes per chunk. // of bytes per chunk.
let metadata = metadata(&settings.input).unwrap(); let metadata = metadata(&settings.input).unwrap();
let num_bytes = metadata.len(); let num_bytes = metadata.len();
let chunk_size = (num_bytes / (num_chunks as u64)) as usize; let chunk_size = (num_bytes / num_chunks) as usize;
// This object is responsible for creating the filename for each chunk. // This object is responsible for creating the filename for each chunk.
let mut filename_iterator = FilenameIterator::new( let mut filename_iterator = FilenameIterator::new(
@ -1188,7 +1188,7 @@ where
// of bytes per chunk. // of bytes per chunk.
let metadata = metadata(&settings.input).unwrap(); let metadata = metadata(&settings.input).unwrap();
let num_bytes = metadata.len(); let num_bytes = metadata.len();
let chunk_size = (num_bytes / (num_chunks as u64)) as usize; let chunk_size = (num_bytes / num_chunks) as usize;
// Write to stdout instead of to a file. // Write to stdout instead of to a file.
let stdout = std::io::stdout(); let stdout = std::io::stdout();

View file

@ -52,7 +52,7 @@ mod platform {
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]
pub unsafe fn do_syncfs(files: Vec<String>) -> isize { pub unsafe fn do_syncfs(files: Vec<String>) -> isize {
for path in files { for path in files {
let f = File::open(&path).unwrap(); let f = File::open(path).unwrap();
let fd = f.as_raw_fd(); let fd = f.as_raw_fd();
libc::syscall(libc::SYS_syncfs, fd); libc::syscall(libc::SYS_syncfs, fd);
} }
@ -62,7 +62,7 @@ mod platform {
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]
pub unsafe fn do_fdatasync(files: Vec<String>) -> isize { pub unsafe fn do_fdatasync(files: Vec<String>) -> isize {
for path in files { for path in files {
let f = File::open(&path).unwrap(); let f = File::open(path).unwrap();
let fd = f.as_raw_fd(); let fd = f.as_raw_fd();
libc::syscall(libc::SYS_fdatasync, fd); libc::syscall(libc::SYS_fdatasync, fd);
} }

View file

@ -160,7 +160,10 @@ fn get_uptime(boot_time: Option<time_t>) -> i64 {
proc_uptime.unwrap_or_else(|| match boot_time { proc_uptime.unwrap_or_else(|| match boot_time {
Some(t) => { Some(t) => {
let now = Local::now().timestamp(); let now = Local::now().timestamp();
let boottime = t as i64; #[cfg(target_pointer_width = "64")]
let boottime: i64 = t;
#[cfg(not(target_pointer_width = "64"))]
let boottime: i64 = t.into();
now - boottime now - boottime
} }
None => -1, None => -1,

View file

@ -474,11 +474,15 @@ impl Who {
let last_change; let last_change;
match p.metadata() { match p.metadata() {
Ok(meta) => { Ok(meta) => {
mesg = if meta.mode() & (S_IWGRP as u32) != 0 { #[cfg(all(
'+' not(target_os = "android"),
} else { not(target_os = "freebsd"),
'-' not(target_vendor = "apple")
}; ))]
let iwgrp = S_IWGRP;
#[cfg(any(target_os = "android", target_os = "freebsd", target_vendor = "apple"))]
let iwgrp = S_IWGRP as u32;
mesg = if meta.mode() & iwgrp != 0 { '+' } else { '-' };
last_change = meta.atime(); last_change = meta.atime();
} }
_ => { _ => {

View file

@ -20,7 +20,7 @@ static ABOUT: &str = "Print the current username.";
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
uu_app().try_get_matches_from(args)?; uu_app().try_get_matches_from(args)?;
let username = platform::get_username().map_err_context(|| "failed to get username".into())?; let username = platform::get_username().map_err_context(|| "failed to get username".into())?;
println_verbatim(&username).map_err_context(|| "failed to print username".into())?; println_verbatim(username).map_err_context(|| "failed to print username".into())?;
Ok(()) Ok(())
} }

View file

@ -109,15 +109,36 @@ impl FileInformation {
} }
pub fn number_of_links(&self) -> u64 { pub fn number_of_links(&self) -> u64 {
#[cfg(unix)] #[cfg(all(
return self.0.st_nlink as u64; unix,
not(target_vendor = "apple"),
not(target_os = "android"),
not(target_os = "freebsd"),
not(target_arch = "aarch64"),
target_pointer_width = "64"
))]
return self.0.st_nlink;
#[cfg(all(
unix,
any(
target_vendor = "apple",
target_os = "android",
target_os = "freebsd",
target_arch = "aarch64",
not(target_pointer_width = "64")
)
))]
return self.0.st_nlink.into();
#[cfg(windows)] #[cfg(windows)]
return self.0.number_of_links() as u64; return self.0.number_of_links();
} }
#[cfg(unix)] #[cfg(unix)]
pub fn inode(&self) -> u64 { pub fn inode(&self) -> u64 {
self.0.st_ino as u64 #[cfg(all(not(target_os = "freebsd"), target_pointer_width = "64"))]
return self.0.st_ino;
#[cfg(any(target_os = "freebsd", not(target_pointer_width = "64")))]
return self.0.st_ino.into();
} }
} }

View file

@ -499,15 +499,39 @@ impl FsUsage {
#[cfg(unix)] #[cfg(unix)]
pub fn new(statvfs: StatFs) -> Self { pub fn new(statvfs: StatFs) -> Self {
{ {
Self { #[cfg(all(not(target_os = "freebsd"), target_pointer_width = "64"))]
return Self {
blocksize: statvfs.f_bsize as u64, // or `statvfs.f_frsize` ? blocksize: statvfs.f_bsize as u64, // or `statvfs.f_frsize` ?
blocks: statvfs.f_blocks as u64, blocks: statvfs.f_blocks,
bfree: statvfs.f_bfree as u64, bfree: statvfs.f_bfree,
bavail: statvfs.f_bavail as u64, bavail: statvfs.f_bavail,
bavail_top_bit_set: ((statvfs.f_bavail) & (1u64.rotate_right(1))) != 0,
files: statvfs.f_files,
ffree: statvfs.f_ffree,
};
#[cfg(all(not(target_os = "freebsd"), not(target_pointer_width = "64")))]
return Self {
blocksize: statvfs.f_bsize as u64, // or `statvfs.f_frsize` ?
blocks: statvfs.f_blocks.into(),
bfree: statvfs.f_bfree.into(),
bavail: statvfs.f_bavail.into(),
bavail_top_bit_set: ((statvfs.f_bavail as u64) & (1u64.rotate_right(1))) != 0, bavail_top_bit_set: ((statvfs.f_bavail as u64) & (1u64.rotate_right(1))) != 0,
files: statvfs.f_files as u64, files: statvfs.f_files.into(),
ffree: statvfs.f_ffree as u64, ffree: statvfs.f_ffree.into(),
} };
#[cfg(target_os = "freebsd")]
return Self {
blocksize: statvfs.f_bsize, // or `statvfs.f_frsize` ?
blocks: statvfs.f_blocks,
bfree: statvfs.f_bfree,
bavail: statvfs.f_bavail.try_into().unwrap(),
bavail_top_bit_set: ((std::convert::TryInto::<u64>::try_into(statvfs.f_bavail)
.unwrap())
& (1u64.rotate_right(1)))
!= 0,
files: statvfs.f_files,
ffree: statvfs.f_ffree.try_into().unwrap(),
};
} }
} }
#[cfg(not(unix))] #[cfg(not(unix))]
@ -556,7 +580,7 @@ impl FsUsage {
let bytes_per_cluster = sectors_per_cluster as u64 * bytes_per_sector as u64; let bytes_per_cluster = sectors_per_cluster as u64 * bytes_per_sector as u64;
Self { Self {
// f_bsize File system block size. // f_bsize File system block size.
blocksize: bytes_per_cluster as u64, blocksize: bytes_per_cluster,
// f_blocks - Total number of blocks on the file system, in units of f_frsize. // f_blocks - Total number of blocks on the file system, in units of f_frsize.
// frsize = Fundamental file system block size (fragment size). // frsize = Fundamental file system block size (fragment size).
blocks: total_number_of_clusters as u64, blocks: total_number_of_clusters as u64,
@ -590,22 +614,60 @@ pub trait FsMeta {
#[cfg(unix)] #[cfg(unix)]
impl FsMeta for StatFs { impl FsMeta for StatFs {
fn block_size(&self) -> i64 { fn block_size(&self) -> i64 {
self.f_bsize as i64 #[cfg(all(
not(target_env = "musl"),
not(target_vendor = "apple"),
not(target_os = "android"),
not(target_os = "freebsd"),
target_pointer_width = "64"
))]
return self.f_bsize;
#[cfg(all(
not(target_env = "musl"),
not(target_os = "freebsd"),
any(
target_vendor = "apple",
target_os = "android",
not(target_pointer_width = "64")
)
))]
return self.f_bsize.into();
#[cfg(any(target_env = "musl", target_os = "freebsd"))]
return self.f_bsize.try_into().unwrap();
} }
fn total_blocks(&self) -> u64 { fn total_blocks(&self) -> u64 {
self.f_blocks as u64 #[cfg(target_pointer_width = "64")]
return self.f_blocks;
#[cfg(not(target_pointer_width = "64"))]
return self.f_blocks.into();
} }
fn free_blocks(&self) -> u64 { fn free_blocks(&self) -> u64 {
self.f_bfree as u64 #[cfg(target_pointer_width = "64")]
return self.f_bfree;
#[cfg(not(target_pointer_width = "64"))]
return self.f_bfree.into();
} }
fn avail_blocks(&self) -> u64 { fn avail_blocks(&self) -> u64 {
self.f_bavail as u64 #[cfg(all(not(target_os = "freebsd"), target_pointer_width = "64"))]
return self.f_bavail;
#[cfg(all(not(target_os = "freebsd"), not(target_pointer_width = "64")))]
return self.f_bavail.into();
#[cfg(target_os = "freebsd")]
return self.f_bavail.try_into().unwrap();
} }
fn total_file_nodes(&self) -> u64 { fn total_file_nodes(&self) -> u64 {
self.f_files as u64 #[cfg(target_pointer_width = "64")]
return self.f_files;
#[cfg(not(target_pointer_width = "64"))]
return self.f_files.into();
} }
fn free_file_nodes(&self) -> u64 { fn free_file_nodes(&self) -> u64 {
self.f_ffree as u64 #[cfg(all(not(target_os = "freebsd"), target_pointer_width = "64"))]
return self.f_ffree;
#[cfg(all(not(target_os = "freebsd"), not(target_pointer_width = "64")))]
return self.f_ffree.into();
#[cfg(target_os = "freebsd")]
return self.f_ffree.try_into().unwrap();
} }
#[cfg(any( #[cfg(any(
target_os = "linux", target_os = "linux",
@ -614,7 +676,26 @@ impl FsMeta for StatFs {
target_os = "freebsd" target_os = "freebsd"
))] ))]
fn fs_type(&self) -> i64 { fn fs_type(&self) -> i64 {
self.f_type as i64 #[cfg(all(
not(target_env = "musl"),
not(target_vendor = "apple"),
not(target_os = "android"),
not(target_os = "freebsd"),
target_pointer_width = "64"
))]
return self.f_type;
#[cfg(all(
not(target_env = "musl"),
any(
target_vendor = "apple",
target_os = "android",
target_os = "freebsd",
not(target_pointer_width = "64")
)
))]
return self.f_type.into();
#[cfg(target_env = "musl")]
return self.f_type.try_into().unwrap();
} }
#[cfg(not(any( #[cfg(not(any(
target_os = "linux", target_os = "linux",
@ -633,7 +714,10 @@ impl FsMeta for StatFs {
} }
#[cfg(any(target_vendor = "apple", target_os = "freebsd", target_os = "netbsd"))] #[cfg(any(target_vendor = "apple", target_os = "freebsd", target_os = "netbsd"))]
fn io_size(&self) -> u64 { fn io_size(&self) -> u64 {
self.f_iosize as u64 #[cfg(target_os = "freebsd")]
return self.f_iosize;
#[cfg(not(target_os = "freebsd"))]
return self.f_iosize as u64;
} }
// XXX: dunno if this is right // XXX: dunno if this is right
#[cfg(not(any( #[cfg(not(any(

View file

@ -51,7 +51,7 @@ pub fn parse_symbolic(
mode = &mode[pos..]; mode = &mode[pos..];
let (mut srwx, pos) = parse_change(mode, fperm, considering_dir); let (mut srwx, pos) = parse_change(mode, fperm, considering_dir);
if respect_umask { if respect_umask {
srwx &= !(umask as u32); srwx &= !umask;
} }
mode = &mode[pos..]; mode = &mode[pos..];
match op { match op {
@ -132,12 +132,20 @@ fn parse_change(mode: &str, fperm: u32, considering_dir: bool) -> (u32, usize) {
} }
pub fn parse_mode(mode: &str) -> Result<mode_t, String> { pub fn parse_mode(mode: &str) -> Result<mode_t, String> {
#[cfg(all(
not(target_os = "freebsd"),
not(target_vendor = "apple"),
not(target_os = "android")
))]
let fperm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; let fperm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
#[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "android"))]
let fperm = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32;
let arr: &[char] = &['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; let arr: &[char] = &['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
let result = if mode.contains(arr) { let result = if mode.contains(arr) {
parse_numeric(fperm as u32, mode, true) parse_numeric(fperm, mode, true)
} else { } else {
parse_symbolic(fperm as u32, mode, get_umask(), true) parse_symbolic(fperm, mode, get_umask(), true)
}; };
result.map(|mode| mode as mode_t) result.map(|mode| mode as mode_t)
} }
@ -152,7 +160,14 @@ pub fn get_umask() -> u32 {
// possible but it can't violate Rust's guarantees. // possible but it can't violate Rust's guarantees.
let mask = unsafe { umask(0) }; let mask = unsafe { umask(0) };
unsafe { umask(mask) }; unsafe { umask(mask) };
mask as u32 #[cfg(all(
not(target_os = "freebsd"),
not(target_vendor = "apple"),
not(target_os = "android")
))]
return mask;
#[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "android"))]
return mask.into();
} }
// Iterate 'args' and delete the first occurrence // Iterate 'args' and delete the first occurrence

View file

@ -61,11 +61,11 @@ fn get_provided(str_in_opt: Option<&String>) -> Option<u8> {
if !ignored.is_empty() { if !ignored.is_empty() {
warn_char_constant_ign(&ignored); warn_char_constant_ign(&ignored);
} }
second_byte as u8 second_byte
} }
// no byte after quote // no byte after quote
None => { None => {
let so_far = (ch as u8 as char).to_string(); let so_far = (ch as char).to_string();
warn_expected_numeric(&so_far); warn_expected_numeric(&so_far);
0_u8 0_u8
} }

View file

@ -195,7 +195,7 @@ impl SubParser {
// into min_width, second_field, field_char // into min_width, second_field, field_char
for ch in it { for ch in it {
self.text_so_far.push(ch); self.text_so_far.push(ch);
match ch as char { match ch {
'-' | '*' | '0'..='9' => { '-' | '*' | '0'..='9' => {
if !self.past_decimal { if !self.past_decimal {
if self.min_width_is_asterisk || self.specifiers_found { if self.min_width_is_asterisk || self.specifiers_found {
@ -421,7 +421,7 @@ impl Sub {
"{}", "{}",
match field.min_width { match field.min_width {
Some(min_width) => { Some(min_width) => {
let diff: isize = min_width.abs() as isize - pre_min_width.len() as isize; let diff: isize = min_width.abs() - pre_min_width.len() as isize;
if diff > 0 { if diff > 0 {
let mut final_str = String::new(); let mut final_str = String::new();
// definitely more efficient ways // definitely more efficient ways

View file

@ -217,7 +217,7 @@ impl UnescapedText {
if !addchar { if !addchar {
addchar = true; addchar = true;
} }
match ch as char { match ch {
x if x != '\\' && x != '%' => { x if x != '\\' && x != '%' => {
// lazy branch eval // lazy branch eval
// remember this fn could be called // remember this fn could be called

View file

@ -51,6 +51,9 @@ pub use libc::getutxent;
pub use libc::setutxent; pub use libc::setutxent;
#[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "netbsd"))] #[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "netbsd"))]
pub use libc::utmpxname; pub use libc::utmpxname;
/// # Safety
/// Just fixed the clippy warning. Please add description here.
#[cfg(target_os = "freebsd")] #[cfg(target_os = "freebsd")]
pub unsafe extern "C" fn utmpxname(_file: *const libc::c_char) -> libc::c_int { pub unsafe extern "C" fn utmpxname(_file: *const libc::c_char) -> libc::c_int {
0 0
@ -165,11 +168,11 @@ pub struct Utmpx {
impl Utmpx { impl Utmpx {
/// A.K.A. ut.ut_type /// A.K.A. ut.ut_type
pub fn record_type(&self) -> i16 { pub fn record_type(&self) -> i16 {
self.inner.ut_type as i16 self.inner.ut_type
} }
/// A.K.A. ut.ut_pid /// A.K.A. ut.ut_pid
pub fn pid(&self) -> i32 { pub fn pid(&self) -> i32 {
self.inner.ut_pid as i32 self.inner.ut_pid
} }
/// A.K.A. ut.ut_id /// A.K.A. ut.ut_id
pub fn terminal_suffix(&self) -> String { pub fn terminal_suffix(&self) -> String {
@ -189,9 +192,14 @@ impl Utmpx {
} }
/// A.K.A. ut.ut_tv /// A.K.A. ut.ut_tv
pub fn login_time(&self) -> time::OffsetDateTime { pub fn login_time(&self) -> time::OffsetDateTime {
#[cfg(all(not(target_os = "freebsd"), not(target_vendor = "apple")))]
let ts_nanos: i128 = (self.inner.ut_tv.tv_sec as i64 * 1_000_000_000_i64 let ts_nanos: i128 = (self.inner.ut_tv.tv_sec as i64 * 1_000_000_000_i64
+ self.inner.ut_tv.tv_usec as i64 * 1_000_i64) + self.inner.ut_tv.tv_usec as i64 * 1_000_i64)
.into(); .into();
#[cfg(any(target_os = "freebsd", target_vendor = "apple"))]
let ts_nanos: i128 = (self.inner.ut_tv.tv_sec * 1_000_000_000_i64
+ self.inner.ut_tv.tv_usec as i64 * 1_000_i64)
.into();
let local_offset = time::OffsetDateTime::now_local().unwrap().offset(); let local_offset = time::OffsetDateTime::now_local().unwrap().offset();
time::OffsetDateTime::from_unix_timestamp_nanos(ts_nanos) time::OffsetDateTime::from_unix_timestamp_nanos(ts_nanos)
.unwrap() .unwrap()

View file

@ -41,7 +41,7 @@ use std::sync::atomic::AtomicBool;
// For the full copyright and license information, please view the LICENSE // For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code. // file that was distributed with this source code.
/// Whether we were called as a multicall binary ("coreutils <utility>") /// Whether we were called as a multicall binary (`coreutils <utility>`)
pub static UTILITY_IS_SECOND_ARG: AtomicBool = AtomicBool::new(false); pub static UTILITY_IS_SECOND_ARG: AtomicBool = AtomicBool::new(false);
//==== //====