lx 0.4.0

A no_std crate to use Linux system calls
Documentation
use super::abi::*;
use crate::{
    result_from_value,
    AsRawFd,
};

pub const F_GETFD: u32 = 1;
pub const F_SETFD: u32 = 2;

#[inline]
#[allow(clippy::missing_safety_doc)]
pub unsafe fn fcntl(fd: &impl AsRawFd, cmd: u32, arg: usize) -> crate::Result<isize> {
    let ret = syscall_3(72, fd.as_raw_fd() as usize, cmd as usize, arg) as isize;
    result_from_value(ret)
}

#[inline]
pub fn fcntl_getfd(fd: &impl AsRawFd) -> crate::Result<i32> {
    // SAFETY: There isn't any pointer that `F_GETFD` could dereference, and the worst thing that
    // could happen is that the `fd` is invalid and the kernel returns an error.
    Ok(unsafe { fcntl(fd, F_GETFD, 0)? as i32 })
}

#[inline]
pub fn fcntl_setfd(fd: &impl AsRawFd, flags: i32) -> crate::Result<i32> {
    // SAFETY: There isn't any pointer that `F_GETFD` could dereference, and the worst thing that
    // could happen is that the `fd` or `flags` are invalid and the kernel returns an error.
    Ok(unsafe { fcntl(fd, F_SETFD, flags as usize)? as i32 })
}