Use nix Errno

This commit is contained in:
topjohnwu
2026-10-02 17:17:48 -07:00
parent 5b06d817d4
commit 93708e5e73
3 changed files with 5 additions and 9 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
use crate::cxx_extern::readlinkat;
use crate::{
FsPathBuilder, LibcReturn, LoggedResult, OsError, OsResult, Utf8CStr, Utf8CStrBuf, cstr, errno,
FsPathBuilder, LibcReturn, LoggedResult, OsError, OsResult, Utf8CStr, Utf8CStrBuf, cstr,
fd_path, fd_set_attr,
};
use libc::{dirent, mode_t};
@@ -159,10 +159,10 @@ impl Directory {
}
pub fn read(&mut self) -> OsResult<'static, Option<DirEntry<'_>>> {
*errno() = 0;
Errno::set_raw(0);
let e = unsafe { libc::readdir(self.inner.as_ptr()) };
if e.is_null() {
return if *errno() != 0 {
return if Errno::last_raw() != 0 {
Err(OsError::last_os_error("readdir", None, None))
} else {
Ok(None)
+2 -2
View File
@@ -1,6 +1,6 @@
use crate::{
Directory, FsPathFollow, LibcReturn, LoggedResult, OsError, OsResult, Utf8CStr, Utf8CStrBuf,
cstr, errno, error,
cstr, error,
};
use bytemuck::{Pod, bytes_of, bytes_of_mut};
use libc::{c_uint, makedev, mode_t};
@@ -433,7 +433,7 @@ impl Utf8CStr {
path.mkdir(mode)?;
}
*errno() = 0;
Errno::set_raw(0);
Ok(())
}
-4
View File
@@ -9,10 +9,6 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicPtr, Ordering};
use std::{fmt, slice, str};
pub fn errno() -> &'static mut i32 {
unsafe { &mut *libc::__errno() }
}
// When len is 0, don't care whether buf is null or not
#[inline]
pub unsafe fn slice_from_ptr<'a, T>(buf: *const T, len: usize) -> &'a [T] {