Rustify Sys::open and some fs:: error handling.

This commit is contained in:
4lDO2
2024-09-07 13:06:23 +02:00
parent b9653e689b
commit 198caa3bc5
13 changed files with 75 additions and 55 deletions
+3 -2
View File
@@ -3,6 +3,7 @@ use core::{mem, ptr};
use crate::{
c_str::CString,
error::ResultExt,
header::{
arpa_inet::inet_aton, fcntl::O_RDONLY, netinet_in::in_addr, sys_socket::constants::AF_INET,
unistd::SEEK_SET,
@@ -45,7 +46,7 @@ pub unsafe extern "C" fn endhostent() {
pub unsafe extern "C" fn sethostent(stayopen: c_int) {
HOST_STAYOPEN = stayopen;
if HOSTDB < 0 {
HOSTDB = Sys::open(c_str!("/etc/hosts"), O_RDONLY, 0)
HOSTDB = Sys::open(c_str!("/etc/hosts"), O_RDONLY, 0).or_minus_one_errno()
} else {
Sys::lseek(HOSTDB, 0, SEEK_SET);
}
@@ -55,7 +56,7 @@ pub unsafe extern "C" fn sethostent(stayopen: c_int) {
#[no_mangle]
pub unsafe extern "C" fn gethostent() -> *mut hostent {
if HOSTDB < 0 {
HOSTDB = Sys::open(c_str!("/etc/hosts"), O_RDONLY, 0);
HOSTDB = Sys::open(c_str!("/etc/hosts"), O_RDONLY, 0).or_minus_one_errno();
}
let mut rlb = RawLineBuffer::new(HOSTDB);
rlb.seek(H_POS);