Skip to content

Commit a393299

Browse files
author
Jesse Hoogervorst
committed
Implemented flock for vxworks using ioctl
1 parent 3a0b044 commit a393299

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
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))]

src/vxworks/mod.rs

+47
Original file line numberDiff line numberDiff 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

417426
s_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+
20162063
pub use ffi::c_void;
20172064

20182065
cfg_if! {

0 commit comments

Comments
 (0)