1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
use crate::*; cfg_if::cfg_if! { if #[cfg(target_os = "linux")] { mod linux; pub use linux::*; } } #[man("fcntl(2) with cmd = `F_GETFD`")] pub fn fcntl_getfd(fd: c::c_int) -> Result<c::c_int> { let res = unsafe { c::fcntl(fd, c::F_GETFD) }; map_err!(res) } #[man("fcntl(2) with cmd = `F_SETFD`")] pub fn fcntl_setfd(fd: c::c_int, flags: c::c_int) -> Result<()> { let res = unsafe { c::fcntl(fd, c::F_SETFD, flags) }; map_err!(res).map(drop) } #[man("fcntl(2) with cmd = `F_GETFL`")] pub fn fcntl_getfl(fd: c::c_int) -> Result<c::c_int> { let res = unsafe { c::fcntl(fd, c::F_GETFL) }; map_err!(res) } #[man("fcntl(2) with cmd = `F_SETFL`")] pub fn fcntl_setfl(fd: c::c_int, flags: c::c_int) -> Result<()> { let res = unsafe { c::fcntl(fd, c::F_SETFL, flags) }; map_err!(res).map(drop) } #[man("fcntl(2) with cmd = `F_DUPFD`")] pub fn fcntl_dupfd(fd: c::c_int, lower_bound: c::c_int) -> Result<OwnedFd> { let res = unsafe { c::fcntl(fd, c::F_DUPFD, lower_bound) }; map_err!(res).map(OwnedFd::new) } #[man("fcntl(2) with cmd = `F_DUPFD_CLOEXEC`")] pub fn fcntl_dupfd_cloexec(fd: c::c_int, lower_bound: c::c_int) -> Result<OwnedFd> { let res = unsafe { c::fcntl(fd, c::F_DUPFD_CLOEXEC, lower_bound) }; map_err!(res).map(OwnedFd::new) } #[man("fcntl(2) with cmd = `F_SETLK`")] pub fn fcntl_setlk(fd: c::c_int, lock: &c::flock) -> Result<()> { let res = unsafe { c::fcntl(fd, c::F_SETLK, lock) }; map_err!(res).map(drop) } #[man("fcntl(2) with cmd = `F_SETLKW`")] pub fn fcntl_setlkw(fd: c::c_int, lock: &c::flock) -> Result<()> { let res = unsafe { c::fcntl(fd, c::F_SETLKW, lock) }; map_err!(res).map(drop) } #[man("fcntl(2) with cmd = `F_GETLK`")] pub fn fcntl_getlk(fd: c::c_int, lock: &mut c::flock) -> Result<()> { let res = unsafe { c::fcntl(fd, c::F_GETLK, lock) }; map_err!(res).map(drop) } #[man("fcntl(2) with cmd = `F_SETPIPE_SZ`")] #[cfg(not(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd")))] pub fn fcntl_setpipe_sz(fd: c::c_int, size: c::c_int) -> Result<c::c_int> { let res = unsafe { c::fcntl(fd, c::F_SETPIPE_SZ, size) }; map_err!(res) } #[man("fcntl(2) with cmd = `F_GETPIPE_SZ`")] #[cfg(not(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd")))] pub fn fcntl_getpipe_sz(fd: c::c_int) -> Result<c::c_int> { let res = unsafe { c::fcntl(fd, c::F_GETPIPE_SZ) }; map_err!(res) }