#[deprecated(since="0.0.0", note="Prefer the use of OpenFileDescriptionAdvisoryFileRecordLocking")]
pub trait AdvisoryWholeFileLocking: AsRawFd + Seek + FileExt
{
#[deprecated(since="0.0.0", note="Prefer the use of acquire_advisory_open_file_description_record_lock_on_portion_of_a_file_non_blocking")]
#[inline(always)]
#[allow(deprecated)]
fn acquire_advisory_whole_file_lock_non_blocking(&self, advisory_whole_file_lock: AdvisoryWholeFileLock) -> Result<bool, ()>
{
let result = unsafe { libc::flock(self.as_raw_fd(), (advisory_whole_file_lock as i32) | LOCK_NB) };
if likely!(result == 0)
{
Ok(true)
}
else if likely!(result == -1)
{
match errno().0
{
ENOLCK => Err(()),
EWOULDBLOCK => Ok(false),
EINTR => panic!("Should not be possible to interrupt with a signal as non-blocking"),
EBADF => panic!("fd is not an open file descriptor"),
EINVAL => panic!("operation is invalid"),
unexpected @ _ => panic!("Unexpected error {} from flock()", unexpected)
}
}
else
{
unreachable_code(format_args!("Unexpected result {} from flock()", result))
}
}
#[deprecated(since="0.0.0", note="Prefer the use of acquire_advisory_open_file_description_record_lock_on_portion_of_a_file_blocking")]
#[inline(always)]
#[allow(deprecated)]
fn acquire_advisory_whole_file_lock_blocking(&self, advisory_whole_file_lock: AdvisoryWholeFileLock) -> Result<bool, ()>
{
let result = unsafe { libc::flock(self.as_raw_fd(), advisory_whole_file_lock as i32) };
if likely!(result == 0)
{
Ok(true)
}
else if likely!(result == -1)
{
match errno().0
{
EINTR => Ok(false),
ENOLCK => Err(()),
EWOULDBLOCK => panic!("The file is locked and the LOCK_NB flag was selected"),
EINVAL => panic!("operation is invalid"),
EBADF => panic!("fd is not an open file descriptor"),
unexpected @ _ => panic!("Unexpected error {} from flock()", unexpected)
}
}
else
{
unreachable_code(format_args!("Unexpected result {} from flock()", result))
}
}
#[deprecated(since="0.0.0", note="Prefer the use of release_advisory_open_file_description_record_lock_on_portion_of_a_file_non_blocking")]
#[inline(always)]
fn release_advisory_whole_file_lock_non_blocking(&self) -> bool
{
let result = unsafe { libc::flock(self.as_raw_fd(), LOCK_UN | LOCK_NB) };
if likely!(result == 0)
{
true
}
else if likely!(result == -1)
{
match errno().0
{
EWOULDBLOCK => false,
EINTR => panic!("Should not be possible to interrupt with a signal as non-blocking"),
ENOLCK => panic!("the kernel ran out of memory for allocating lock records."),
EBADF => panic!("fd is not an open file descriptor"),
EINVAL => panic!("operation is invalid"),
unexpected @ _ => panic!("Unexpected error {} from flock()", unexpected)
}
}
else
{
unreachable_code(format_args!("Unexpected result {} from flock()", result))
}
}
#[deprecated(since="0.0.0", note="Prefer the use of release_advisory_open_file_description_record_lock_on_portion_of_a_file_blocking")]
#[inline(always)]
fn release_advisory_whole_file_lock_blocking(&self) -> bool
{
let result = unsafe { libc::flock(self.as_raw_fd(), LOCK_UN) };
if likely!(result == 0)
{
true
}
else if likely!(result == -1)
{
match errno().0
{
EINTR => false,
EWOULDBLOCK => panic!("The file is locked and the LOCK_NB flag was selected"),
ENOLCK => panic!("the kernel ran out of memory for allocating lock records."),
EBADF => panic!("fd is not an open file descriptor"),
EINVAL => panic!("operation is invalid"),
unexpected @ _ => panic!("Unexpected error {} from flock()", unexpected)
}
}
else
{
unreachable_code(format_args!("Unexpected result {} from flock()", result))
}
}
}