#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FileOpenKind<'a>
{
FailIfDoesNotExist
{
path: &'a CStr,
access: Access,
fail_if_path_name_is_a_block_device_and_is_in_use: bool,
no_follow: bool,
},
CreateIfDoesNotExist
{
path: &'a CStr,
access: Access,
exclusive: bool,
no_follow: bool,
access_permissions: AccessPermissions,
},
MakeATemporaryFile
{
access: TemporaryFileAccess,
exclusive: bool,
access_permissions: AccessPermissions,
}
}
impl<'a> FileOpenKind<'a>
{
#[inline(always)]
fn o_flags_mode_and_path(&self) -> (i32, mode_t, *const c_char)
{
use self::FileOpenKind::*;
match self
{
&FailIfDoesNotExist { path, access, fail_if_path_name_is_a_block_device_and_is_in_use, no_follow } =>
{
let o_flags = if fail_if_path_name_is_a_block_device_and_is_in_use
{
access.to_oflag() | O_NOCTTY | O_EXCL
}
else
{
access.to_oflag() | O_NOCTTY
};
let o_flags = if no_follow
{
o_flags | O_NOFOLLOW
}
else
{
o_flags
};
(o_flags, 0, path.as_ptr())
}
&CreateIfDoesNotExist { path, access, exclusive, no_follow, access_permissions } =>
{
let o_flags = if exclusive
{
access.to_oflag() | O_NOCTTY | O_CREAT | O_EXCL
}
else
{
access.to_oflag() | O_NOCTTY | O_CREAT
};
let o_flags = if no_follow
{
o_flags | O_NOFOLLOW
}
else
{
o_flags
};
(o_flags, DirectoryFileDescriptor::mask_mode(access_permissions), path.as_ptr())
}
&MakeATemporaryFile { access, exclusive, access_permissions } =>
{
let o_flags = if exclusive
{
access.to_oflag() | O_TMPFILE | O_EXCL
}
else
{
access.to_oflag() | O_TMPFILE
};
(o_flags, DirectoryFileDescriptor::mask_mode(access_permissions), null())
}
}
}
}