Skip to content

Commit 8644e4c

Browse files
committed
cleanup/format only
1 parent 131d376 commit 8644e4c

4 files changed

Lines changed: 22 additions & 21 deletions

File tree

build.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ fn test_macos_syscall() {
4444
// Negative values indicate errors
4545
if result < 0 {
4646
panic!(
47-
"getdirentries64 syscall test failed with result: {}\n This indicates the syscall number has changed!",
48-
result
47+
"getdirentries64 syscall test failed with result: {result}\n This indicates the syscall number has changed!",
4948
);
5049
}
5150
}
@@ -60,10 +59,10 @@ fn main() {
6059
println!("cargo:rustc-env=THREAD_COUNT={num_threads}");
6160

6261
let page_size = unsafe { libc::sysconf(libc::_SC_PAGESIZE) };
63-
println!("cargo:rustc-env=FDF_PAGE_SIZE={}", page_size);
62+
println!("cargo:rustc-env=FDF_PAGE_SIZE={page_size}");
6463

6564
let max_filename_len = unsafe { libc::pathconf(c"/".as_ptr(), libc::_PC_NAME_MAX) };
66-
println!("cargo:rustc-env=NAME_MAX={}", max_filename_len);
65+
println!("cargo:rustc-env=NAME_MAX={max_filename_len}");
6766
assert!(
6867
max_filename_len >= 255,
6968
"NAME_MAX is not appropriately set!"

src/lib.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,9 @@ pub use iter::GetDirEntries;
167167
#[cfg(not(any(target_os = "linux", target_os = "android")))]
168168
pub(crate) use libc::{dirent as dirent64, readdir as readdir64};
169169

170-
171170
#[cfg(any(target_os = "linux", target_os = "android"))]
172171
pub(crate) use libc::{dirent64, readdir64};
173172

174-
175-
176173
mod printer;
177174
pub(crate) use printer::write_paths_coloured;
178175

@@ -445,6 +442,18 @@ impl Finder {
445442
}
446443
}
447444

445+
#[inline]
446+
#[expect(clippy::print_stderr, reason = "only enabled if explicitly requested")]
447+
fn send_files_if_not_empty(&self, files: Vec<DirEntry>, sender: &Sender<Vec<DirEntry>>) {
448+
if !files.is_empty() {
449+
if let Err(e) = sender.send(files) {
450+
if self.search_config.show_errors {
451+
eprintln!("Error sending files: {e}");
452+
}
453+
}
454+
}
455+
}
456+
448457
#[expect(
449458
clippy::redundant_clone,
450459
reason = "we have to clone when sending dirs because it's being used to keep the iterator going.
@@ -501,11 +510,11 @@ impl Finder {
501510

502511
// We do batch sending to minimise contention of sending
503512
// as opposed to sending one at a time, which will cause tremendous locks
504-
send_files_if_not_empty!(self, files, sender); // a convenience macro to simplify the code
513+
self.send_files_if_not_empty(files, sender)
505514
}
506515
Err(err) => {
507516
if self.search_config.show_errors {
508-
eprintln!("Error accessing {}: {}", dir.to_string_lossy(), err);
517+
eprintln!("Error accessing {}: {err}", dir.to_string_lossy());
509518
//TODO! replace with logging eventually
510519
}
511520
}

src/macros.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -416,18 +416,6 @@ macro_rules! handle_depth_limit {
416416
};
417417
}
418418

419-
macro_rules! send_files_if_not_empty {
420-
($self:expr, $files:expr, $sender:expr) => {
421-
if !$files.is_empty() {
422-
if let Err(e) = $sender.send($files) {
423-
if $self.search_config.show_errors {
424-
eprintln!("Error sending files: {e}");
425-
}
426-
}
427-
}
428-
};
429-
}
430-
431419
/// Extremely simple macro for getting rid of boiler blates
432420
macro_rules! return_os_error {
433421
() => {{

src/utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ where
6464
{
6565
const SYS_GETDIRENTRIES64: libc::c_int = 344; // Reverse engineered syscall number
6666
//https://phrack.org/issues/66/16
67+
// We verify this works via build script, we check if `getdirentries` returns >0 for tmp directory, if not, syscall is broken.
6768
// SAFETY: Syscall has no other implicit safety requirements beyond pointer validity
6869
unsafe { libc::syscall(SYS_GETDIRENTRIES64, fd, buffer_ptr, nbytes, basep) }
6970
}
@@ -270,6 +271,10 @@ pub const unsafe fn dirent_const_time_strlen(drnt: *const dirent64) -> usize {
270271
*/
271272
let candidate_pos: u64 = last_word | mask;
272273

274+
debug_assert!(
275+
candidate_pos.wrapping_sub(LO_U64) & !candidate_pos & HI_U64 != 0,
276+
"Due to the final 8 bytes always containing a null terminator, this should never be 0"
277+
);
273278
/*
274279
Locate the first null byte in constant time using SWAR.
275280
Subtract the position of the index of the 0 then add 1 to compute its position relative to the start of d_name.

0 commit comments

Comments
 (0)