File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1919) ]
2020#![ cfg_attr( libc_deny_warnings, deny( warnings) ) ]
2121// Attributes needed when building as part of the standard library
22+ #![ allow( internal_features) ]
2223#![ cfg_attr( feature = "rustc-dep-of-std" , feature( link_cfg, no_core) ) ]
2324// Enable extra lints:
2425#![ cfg_attr( feature = "extra_traits" , deny( missing_debug_implementations) ) ]
Original file line number Diff line number Diff line change @@ -412,6 +412,15 @@ s! {
412412 pub mq_flags: :: c_long,
413413 pub mq_curmsgs: :: c_long,
414414 }
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+ }
415424}
416425
417426s_no_extra_traits ! {
@@ -2013,6 +2022,44 @@ pub unsafe fn posix_memalign(
20132022 }
20142023}
20152024
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+
20162063pub use ffi:: c_void;
20172064
20182065cfg_if ! {
You can’t perform that action at this time.
0 commit comments