1
1
use { Error , Result , NixPath } ;
2
2
use errno:: Errno ;
3
- use libc:: mode_t;
3
+ use libc:: { mode_t, c_int } ;
4
4
use sys:: stat:: Mode ;
5
5
use std:: os:: unix:: io:: RawFd ;
6
6
@@ -17,7 +17,7 @@ mod ffi {
17
17
use libc:: { c_int, c_short, off_t, pid_t} ;
18
18
19
19
#[ repr( C ) ]
20
- #[ derive( Clone , Copy ) ]
20
+ #[ derive( Clone , Copy , Default , Debug ) ]
21
21
pub struct flock {
22
22
pub l_type : c_short ,
23
23
pub l_whence : c_short ,
@@ -45,7 +45,7 @@ mod ffi {
45
45
use libc:: { c_int, c_short, off_t, pid_t} ;
46
46
47
47
#[ repr( C ) ]
48
- #[ derive( Clone , Copy ) ]
48
+ #[ derive( Clone , Copy , Default , Debug ) ]
49
49
pub struct flock {
50
50
pub l_start : off_t ,
51
51
pub l_len : off_t ,
@@ -102,13 +102,21 @@ pub enum FcntlArg<'a> {
102
102
}
103
103
104
104
// TODO: Figure out how to handle value fcntl returns
105
- pub fn fcntl ( fd : RawFd , arg : FcntlArg ) -> Result < ( ) > {
105
+ pub fn fcntl ( fd : RawFd , arg : FcntlArg ) -> Result < c_int > {
106
106
use self :: FcntlArg :: * ;
107
107
108
108
let res = unsafe {
109
109
match arg {
110
+ F_DUPFD ( rawfd) => ffi:: fcntl ( fd, ffi:: F_DUPFD , rawfd) ,
111
+ F_DUPFD_CLOEXEC ( rawfd) => ffi:: fcntl ( fd, ffi:: F_DUPFD_CLOEXEC , rawfd) ,
112
+ F_GETFD => ffi:: fcntl ( fd, ffi:: F_GETFD ) ,
110
113
F_SETFD ( flag) => ffi:: fcntl ( fd, ffi:: F_SETFD , flag. bits ( ) ) ,
114
+ F_GETFL => ffi:: fcntl ( fd, ffi:: F_GETFL ) ,
111
115
F_SETFL ( flag) => ffi:: fcntl ( fd, ffi:: F_SETFL , flag. bits ( ) ) ,
116
+ F_SETLK ( flock) => ffi:: fcntl ( fd, ffi:: F_SETLK , flock) ,
117
+ F_SETLKW ( flock) => ffi:: fcntl ( fd, ffi:: F_SETLKW , flock) ,
118
+ F_GETLK ( flock) => ffi:: fcntl ( fd, ffi:: F_GETLK , flock) ,
119
+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
112
120
_ => unimplemented ! ( )
113
121
}
114
122
} ;
@@ -117,7 +125,7 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<()> {
117
125
return Err ( Error :: Sys ( Errno :: last ( ) ) ) ;
118
126
}
119
127
120
- Ok ( ( ) )
128
+ Ok ( res )
121
129
}
122
130
123
131
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
0 commit comments