Rename fstatat/readdir wrapper to match Linux equivalents

This commit is contained in:
Johannes Altmanninger 2024-08-07 09:37:47 +02:00
parent d19e5508d7
commit 338579b78c
3 changed files with 11 additions and 11 deletions

View File

@ -185,7 +185,7 @@ int C_RLIMIT_NTHR() {
#endif
}
bool C_portable_readdir(DIR* dirp, const char** d_name, size_t* d_name_len, uint64_t* d_ino, unsigned char* d_type) {
bool C_readdir64(DIR* dirp, const char** d_name, size_t* d_name_len, uint64_t* d_ino, unsigned char* d_type) {
struct dirent *dent = readdir(dirp);
if (!dent) {
return false;
@ -201,7 +201,7 @@ bool C_portable_readdir(DIR* dirp, const char** d_name, size_t* d_name_len, uint
return true;
}
bool C_portable_fstatat(int dirfd, const char* file, int flag, uint64_t* st_dev, uint64_t* st_ino, mode_t* st_mode) {
bool C_fstatat64(int dirfd, const char* file, int flag, uint64_t* st_dev, uint64_t* st_ino, mode_t* st_mode) {
struct stat buf;
if (fstatat(dirfd, file, &buf, flag) == -1) {
return false;

View File

@ -60,18 +60,18 @@ CVAR!(C_RLIMIT_KQUEUES, RLIMIT_KQUEUES, i32);
CVAR!(C_RLIMIT_NPTS, RLIMIT_NPTS, i32);
CVAR!(C_RLIMIT_NTHR, RLIMIT_NTHR, i32);
pub(crate) fn portable_readdir(dirp: *mut libc::DIR) -> Option<(*const c_char, usize, u64, u8)> {
pub(crate) fn readdir64(dirp: *mut libc::DIR) -> Option<(*const c_char, usize, u64, u8)> {
let mut d_name = unsafe { std::mem::zeroed() };
let mut d_name_len = unsafe { std::mem::zeroed() };
let mut d_ino = unsafe { std::mem::zeroed() };
let mut d_type = unsafe { std::mem::zeroed() };
if !unsafe { C_portable_readdir(dirp, &mut d_name, &mut d_name_len, &mut d_ino, &mut d_type) } {
if !unsafe { C_readdir64(dirp, &mut d_name, &mut d_name_len, &mut d_ino, &mut d_type) } {
return None;
}
Some((d_name, d_name_len, d_ino, d_type))
}
extern "C" {
fn C_portable_readdir(
fn C_readdir64(
dirp: *mut libc::DIR,
d_name: *mut *const c_char,
d_name_len: *mut usize,
@ -80,7 +80,7 @@ extern "C" {
) -> bool;
}
pub(crate) fn portable_fstatat(
pub(crate) fn fstatat64(
dirfd: c_int,
file: &CStr,
flag: c_int,
@ -89,7 +89,7 @@ pub(crate) fn portable_fstatat(
let mut st_ino = unsafe { std::mem::zeroed() };
let mut st_mode = unsafe { std::mem::zeroed() };
if !unsafe {
C_portable_fstatat(
C_fstatat64(
dirfd,
file.as_ptr(),
flag,
@ -103,7 +103,7 @@ pub(crate) fn portable_fstatat(
Some((st_dev, st_ino, st_mode))
}
extern "C" {
fn C_portable_fstatat(
fn C_fstatat64(
dirfd: c_int,
file: *const c_char,
flag: c_int,

View File

@ -1,6 +1,6 @@
use super::wopendir;
use crate::common::{cstr2wcstring, wcs2zstring};
use crate::libc::{portable_fstatat, portable_readdir};
use crate::libc::{fstatat64, readdir64};
use crate::wchar::{wstr, WString};
use crate::wutil::DevInode;
use libc::{
@ -104,7 +104,7 @@ impl DirEntry {
return;
}
let narrow = wcs2zstring(&self.name);
if let Some((st_dev, st_ino, st_mode)) = portable_fstatat(fd, &narrow, 0) {
if let Some((st_dev, st_ino, st_mode)) = fstatat64(fd, &narrow, 0) {
let dev_inode = DevInode {
device: st_dev,
inode: st_ino,
@ -252,7 +252,7 @@ impl DirIter {
#[allow(clippy::should_implement_trait)]
pub fn next(&mut self) -> Option<io::Result<&DirEntry>> {
errno::set_errno(errno::Errno(0));
let Some((d_name, d_name_len, d_ino, d_type)) = portable_readdir(self.dir.dir()) else {
let Some((d_name, d_name_len, d_ino, d_type)) = readdir64(self.dir.dir()) else {
// readdir distinguishes between EOF and error via errno.
let err = errno::errno().0;
if err == 0 {