use core::ffi::CStr;
use super::abi::*;
use crate::{
result_from_value,
OwnedFd,
RawFd,
};
pub const O_RDONLY: u32 = 0x0;
pub const O_WRONLY: u32 = 0x1;
pub const O_RDWR: u32 = 0x2;
pub const O_ACCMODE: u32 = O_RDONLY | O_WRONLY | O_RDWR;
pub const O_CREAT: u32 = 0x40;
pub const O_EXCL: u32 = 0x80;
pub const O_NOCTTY: u32 = 0x100;
pub const O_TRUNC: u32 = 0x200;
pub const O_APPEND: u32 = 0x400;
pub const O_NONBLOCK: u32 = 0x800;
pub const O_DSYNC: u32 = 0x1000;
pub const O_ASYNC: u32 = 0x2000;
pub const O_DIRECT: u32 = 0x4000;
pub const O_LARGEFILE: u32 = 0x8000;
pub const O_DIRECTORY: u32 = 0x10000;
pub const O_NOFOLLOW: u32 = 0x20000;
pub const O_NOATIME: u32 = 0x40000;
pub const O_CLOEXEC: u32 = 0x80000;
pub const O_PATH: u32 = 0x200000;
pub const O_TMPFILE: u32 = 0x400000 | O_DIRECTORY;
pub const AT_FDCWD: RawFd = -100i32 as RawFd;
#[inline]
pub fn open(filename: &CStr, flags: u32, mode: u32) -> crate::Result<OwnedFd> {
let ret =
unsafe { syscall_3(2, filename.as_ptr() as usize, flags as usize, mode as usize) as i32 };
result_from_value(ret).map(OwnedFd::new)
}
#[inline]
pub fn openat(dir: RawFd, filename: &CStr, flags: u32, mode: u32) -> crate::Result<OwnedFd> {
let ret = unsafe {
syscall_4(
257,
dir as usize,
filename.as_ptr() as usize,
flags as usize,
mode as usize,
) as i32
};
result_from_value(ret).map(OwnedFd::new)
}