use libc::{self, c_char, c_int, c_uint};
use std::os::fd::*;
use crate::types::{ErrorKind, PosixError};
pub(crate) fn get_errno() -> i32 {
unsafe { *libc::__error() }
}
pub(super) fn set_errno(errno: i32) {
unsafe { *libc::__error() = errno };
}
pub(super) unsafe fn renameat2(
olddirfd: c_int,
oldpath: *const c_char,
newdirfd: c_int,
newpath: *const c_char,
_flags: c_uint,
) -> c_int {
unsafe { libc::renameat(olddirfd, oldpath, newdirfd, newpath) }
}
pub(super) unsafe fn fdatasync(fd: c_int) -> c_int {
unsafe { libc::fsync(fd) }
}
pub(crate) unsafe fn ftruncate(fd: c_int, length: i64) -> c_int {
unsafe { libc::ftruncate(fd, length as libc::off_t) }
}
pub(crate) unsafe fn lseek(fd: c_int, offset: i64, whence: c_int) -> i64 {
unsafe { libc::lseek(fd, offset as libc::off_t, whence) as i64 }
}
pub(crate) unsafe fn pread(fd: c_int, buf: *mut libc::c_void, count: libc::size_t, offset: i64) -> libc::ssize_t {
unsafe { libc::pread(fd, buf, count, offset as libc::off_t) }
}
pub(crate) unsafe fn pwrite(fd: c_int, buf: *const libc::c_void, count: libc::size_t, offset: i64) -> libc::ssize_t {
unsafe { libc::pwrite(fd, buf, count, offset as libc::off_t) }
}
pub fn copy_file_range(
_fd_in: BorrowedFd,
_offset_in: i64,
_fd_out: BorrowedFd,
_offset_out: i64,
_len: u64,
) -> Result<u32, PosixError> {
Err(PosixError::new(
ErrorKind::FunctionNotImplemented,
"copy_file_range is not implemented on this platform" as &str,
)
.into())
}