Skip to content

Commit

Permalink
Stop using deprecated function of errno
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Jan 7, 2024
1 parent d7b7c09 commit 5ed85fe
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ mod posix_fadvise {
if res == 0 {
Ok(())
} else {
Err(Errno::from_i32(res))
Err(Errno::from_raw(res))
}
}
}
Expand All @@ -1131,7 +1131,7 @@ pub fn posix_fallocate(
match Errno::result(res) {
Err(err) => Err(err),
Ok(0) => Ok(()),
Ok(errno) => Err(Errno::from_i32(errno)),
Ok(errno) => Err(Errno::from_raw(errno)),
}
}
}
2 changes: 1 addition & 1 deletion src/sys/aio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl AioCb {
let r = unsafe { libc::aio_error(&self.aiocb().0) };
match r {
0 => Ok(()),
num if num > 0 => Err(Errno::from_i32(num)),
num if num > 0 => Err(Errno::from_raw(num)),
-1 => Err(Errno::last()),
num => panic!("unknown aio_error return value {num:?}"),
}
Expand Down
2 changes: 1 addition & 1 deletion src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,6 @@ pub fn clock_getcpuclockid(pid: Pid) -> Result<ClockId> {
let res = unsafe { clk_id.assume_init() };
Ok(ClockId::from(res))
} else {
Err(Errno::from_i32(ret))
Err(Errno::from_raw(ret))
}
}
10 changes: 5 additions & 5 deletions src/unistd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Safe wrappers around functions found in libc "unistd.h" header

use crate::errno::{self, Errno};
use crate::errno::Errno;

#[cfg(any(
all(feature = "fs", not(target_os = "redox")),
Expand Down Expand Up @@ -2146,7 +2146,7 @@ pub fn fpathconf<F: AsFd>(fd: F, var: PathconfVar) -> Result<Option<c_long>> {
libc::fpathconf(fd.as_fd().as_raw_fd(), var as c_int)
};
if raw == -1 {
if errno::errno() == 0 {
if Errno::last_raw() == 0 {
Ok(None)
} else {
Err(Errno::last())
Expand Down Expand Up @@ -2186,7 +2186,7 @@ pub fn pathconf<P: ?Sized + NixPath>(
libc::pathconf(cstr.as_ptr(), var as c_int)
})?;
if raw == -1 {
if errno::errno() == 0 {
if Errno::last_raw() == 0 {
Ok(None)
} else {
Err(Errno::last())
Expand Down Expand Up @@ -2785,7 +2785,7 @@ pub fn sysconf(var: SysconfVar) -> Result<Option<c_long>> {
libc::sysconf(var as c_int)
};
if raw == -1 {
if errno::errno() == 0 {
if Errno::last_raw() == 0 {
Ok(None)
} else {
Err(Errno::last())
Expand Down Expand Up @@ -3541,7 +3541,7 @@ pub fn ttyname<F: AsFd>(fd: F) -> Result<PathBuf> {

let ret = unsafe { libc::ttyname_r(fd.as_fd().as_raw_fd(), c_buf, buf.len()) };
if ret != 0 {
return Err(Errno::from_i32(ret));
return Err(Errno::from_raw(ret));
}

CStr::from_bytes_until_nul(&buf[..])
Expand Down
4 changes: 2 additions & 2 deletions test/test_errno.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use nix::errno::{set_errno, Errno};
use nix::errno::Errno;

#[test]
fn errno_set_and_read() {
Errno::clear();
set_errno(Errno::ENFILE);
Errno::set(Errno::ENFILE);
assert_eq!(Errno::last(), Errno::ENFILE);
}
2 changes: 1 addition & 1 deletion test/test_mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exit 23";
.mode((Mode::S_IRWXU | Mode::S_IRWXG | Mode::S_IRWXO).bits())
.open(&test_path)
.or_else(|e| {
if Errno::from_i32(e.raw_os_error().unwrap())
if Errno::from_raw(e.raw_os_error().unwrap())
== Errno::EOVERFLOW
{
// Skip tests on certain Linux kernels which have a bug
Expand Down

0 comments on commit 5ed85fe

Please sign in to comment.