xref: /relibc/src/header/fcntl/mod.rs (revision 6fd98d550c9d0636b12b0cece86bf1442dac7378)
1 //! fcntl implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.h.html
2 
3 use crate::{
4     c_str::CStr,
5     platform::{types::*, Pal, Sys},
6 };
7 
8 pub use self::sys::*;
9 
10 #[cfg(target_os = "linux")]
11 #[path = "linux.rs"]
12 pub mod sys;
13 
14 #[cfg(target_os = "dragonos")]
15 #[path = "dragonos.rs"]
16 pub mod sys;
17 
18 #[cfg(target_os = "redox")]
19 #[path = "redox.rs"]
20 pub mod sys;
21 
22 pub const F_DUPFD: c_int = 0;
23 pub const F_GETFD: c_int = 1;
24 pub const F_SETFD: c_int = 2;
25 pub const F_GETFL: c_int = 3;
26 pub const F_SETFL: c_int = 4;
27 pub const F_GETLK: c_int = 5;
28 pub const F_SETLK: c_int = 6;
29 pub const F_SETLKW: c_int = 7;
30 
31 pub const F_RDLCK: c_int = 0;
32 pub const F_WRLCK: c_int = 1;
33 pub const F_UNLCK: c_int = 2;
34 
35 #[no_mangle]
36 pub unsafe extern "C" fn creat(path: *const c_char, mode: mode_t) -> c_int {
37     sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode)
38 }
39 #[repr(C)]
40 pub struct flock {
41     pub l_type: c_short,
42     pub l_whence: c_short,
43     pub l_start: off_t,
44     pub l_len: off_t,
45     pub l_pid: pid_t,
46 }
47 #[no_mangle]
48 pub extern "C" fn sys_fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int {
49     Sys::fcntl(fildes, cmd, arg)
50 }
51 
52 #[no_mangle]
53 pub unsafe extern "C" fn sys_open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
54     let path = CStr::from_ptr(path);
55     Sys::open(path, oflag, mode)
56 }
57 
58 #[no_mangle]
59 pub unsafe extern "C" fn cbindgen_stupid_struct_user_for_fcntl(a: flock) {}
60