use crate::system::file_system::{OfdAccess, OpenFlag};
use std::ffi::c_int;
impl OfdAccess {
#[must_use]
pub(super) fn to_real_flag(self) -> Option<c_int> {
match self {
Self::ReadOnly => Some(libc::O_RDONLY),
Self::WriteOnly => Some(libc::O_WRONLY),
Self::ReadWrite => Some(libc::O_RDWR),
Self::Exec | Self::Search => None,
}
}
#[must_use]
pub(super) fn from_real_flag(flags: c_int) -> Self {
match flags & libc::O_ACCMODE {
libc::O_RDONLY => Self::ReadOnly,
libc::O_WRONLY => Self::WriteOnly,
libc::O_RDWR => Self::ReadWrite,
_ => Self::Exec, }
}
}
impl OpenFlag {
#[must_use]
pub(super) fn to_real_flag(self) -> Option<c_int> {
match self {
Self::Append => Some(libc::O_APPEND),
Self::CloseOnExec => Some(libc::O_CLOEXEC),
Self::Create => Some(libc::O_CREAT),
Self::Directory => Some(libc::O_DIRECTORY),
Self::Exclusive => Some(libc::O_EXCL),
#[cfg(not(any(target_env = "newlib", target_os = "redox")))]
Self::NoCtty => Some(libc::O_NOCTTY),
#[cfg(any(target_env = "newlib", target_os = "redox"))]
Self::NoCtty => None,
Self::NoFollow => Some(libc::O_NOFOLLOW),
Self::NonBlock => Some(libc::O_NONBLOCK),
#[cfg(not(target_os = "redox"))]
Self::Sync => Some(libc::O_SYNC),
#[cfg(target_os = "redox")]
Self::Sync => None,
Self::Truncate => Some(libc::O_TRUNC),
}
}
}