mod.rs 1.4 KB

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