summaryrefslogtreecommitdiff
path: root/src/fcntl.rs
diff options
context:
space:
mode:
authorAndy Grover <agrover@redhat.com>2015-06-23 17:32:39 -0700
committerCarl Lerche <me@carllerche.com>2015-06-24 10:56:29 -0700
commite462c57289fde6bdab12213b8854dc9b08b6e7d4 (patch)
tree159c3d928c72ab5c34c82869fe9f3adff9d800bb /src/fcntl.rs
parentaa0863b0b9b31630159b5a36db694b43b3500bdc (diff)
downloadnix-e462c57289fde6bdab12213b8854dc9b08b6e7d4.zip
Implement more fcntl operations
Derive some more traits on flock to make life easier Change fcntl to return Result<c_int> so we can get results of F_GET* ops. Change pipe2_setflags to match.
Diffstat (limited to 'src/fcntl.rs')
-rw-r--r--src/fcntl.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/fcntl.rs b/src/fcntl.rs
index 2c2eb408..7893addb 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -1,6 +1,6 @@
use {Error, Result, NixPath};
use errno::Errno;
-use libc::mode_t;
+use libc::{mode_t, c_int};
use sys::stat::Mode;
use std::os::unix::io::RawFd;
@@ -17,7 +17,7 @@ mod ffi {
use libc::{c_int, c_short, off_t, pid_t};
#[repr(C)]
- #[derive(Clone, Copy)]
+ #[derive(Clone, Copy, Default, Debug)]
pub struct flock {
pub l_type: c_short,
pub l_whence: c_short,
@@ -45,7 +45,7 @@ mod ffi {
use libc::{c_int, c_short, off_t, pid_t};
#[repr(C)]
- #[derive(Clone, Copy)]
+ #[derive(Clone, Copy, Default, Debug)]
pub struct flock {
pub l_start: off_t,
pub l_len: off_t,
@@ -102,13 +102,21 @@ pub enum FcntlArg<'a> {
}
// TODO: Figure out how to handle value fcntl returns
-pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<()> {
+pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
use self::FcntlArg::*;
let res = unsafe {
match arg {
+ F_DUPFD(rawfd) => ffi::fcntl(fd, ffi::F_DUPFD, rawfd),
+ F_DUPFD_CLOEXEC(rawfd) => ffi::fcntl(fd, ffi::F_DUPFD_CLOEXEC, rawfd),
+ F_GETFD => ffi::fcntl(fd, ffi::F_GETFD),
F_SETFD(flag) => ffi::fcntl(fd, ffi::F_SETFD, flag.bits()),
+ F_GETFL => ffi::fcntl(fd, ffi::F_GETFL),
F_SETFL(flag) => ffi::fcntl(fd, ffi::F_SETFL, flag.bits()),
+ F_SETLK(flock) => ffi::fcntl(fd, ffi::F_SETLK, flock),
+ F_SETLKW(flock) => ffi::fcntl(fd, ffi::F_SETLKW, flock),
+ F_GETLK(flock) => ffi::fcntl(fd, ffi::F_GETLK, flock),
+ #[cfg(any(target_os = "linux", target_os = "android"))]
_ => unimplemented!()
}
};
@@ -117,7 +125,7 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<()> {
return Err(Error::Sys(Errno::last()));
}
- Ok(())
+ Ok(res)
}
#[cfg(any(target_os = "linux", target_os = "android"))]