File tree 2 files changed +48
-0
lines changed
2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 19
19
) ]
20
20
#![ cfg_attr( libc_deny_warnings, deny( warnings) ) ]
21
21
// Attributes needed when building as part of the standard library
22
+ #![ allow( internal_features) ]
22
23
#![ cfg_attr( feature = "rustc-dep-of-std" , feature( link_cfg, no_core) ) ]
23
24
// Enable extra lints:
24
25
#![ cfg_attr( feature = "extra_traits" , deny( missing_debug_implementations) ) ]
Original file line number Diff line number Diff line change @@ -412,6 +412,15 @@ s! {
412
412
pub mq_flags: :: c_long,
413
413
pub mq_curmsgs: :: c_long,
414
414
}
415
+
416
+ pub struct FLock {
417
+ l_type: :: c_short,
418
+ l_whence: :: c_short,
419
+ l_start: :: c_long,
420
+ l_len: :: c_long,
421
+ l_pid: :: c_short,
422
+ l_xxx: :: c_short,
423
+ }
415
424
}
416
425
417
426
s_no_extra_traits ! {
@@ -2013,6 +2022,44 @@ pub unsafe fn posix_memalign(
2013
2022
}
2014
2023
}
2015
2024
2025
+ pub const LOCK_SH : :: c_int = 1 ;
2026
+ pub const LOCK_EX : :: c_int = 2 ;
2027
+ pub const LOCK_NB : :: c_int = 4 ;
2028
+ pub const LOCK_UN : :: c_int = 8 ;
2029
+
2030
+ pub const F_RDLCK : :: c_int = 1 ;
2031
+ pub const F_WRLCK : :: c_int = 2 ;
2032
+ pub const F_UNLCK : :: c_int = 3 ;
2033
+
2034
+ pub unsafe fn flock ( fd : :: c_int , operation : :: c_int ) -> :: c_int {
2035
+ let lock_type = match operation & !LOCK_NB {
2036
+ LOCK_SH => F_RDLCK ,
2037
+ LOCK_EX => F_WRLCK ,
2038
+ LOCK_UN => F_UNLCK ,
2039
+ _ => {
2040
+ errnoSet ( EINVAL ) ;
2041
+ return ERROR ;
2042
+ }
2043
+ } ;
2044
+
2045
+ let request = if operation & LOCK_NB != 0 {
2046
+ F_SETLK
2047
+ } else {
2048
+ F_SETLKW
2049
+ } ;
2050
+
2051
+ let mut argument = FLock {
2052
+ l_type : lock_type as i16 ,
2053
+ l_whence : SEEK_SET as i16 ,
2054
+ l_start : 0 ,
2055
+ l_len : 0 ,
2056
+ l_pid : 0 ,
2057
+ l_xxx : 0 ,
2058
+ } ;
2059
+
2060
+ return ioctl ( fd, request, core:: ptr:: addr_of_mut!( argument) ) ;
2061
+ }
2062
+
2016
2063
pub use ffi:: c_void;
2017
2064
2018
2065
cfg_if ! {
You can’t perform that action at this time.
0 commit comments