Add method to know when buffer will be refilled (#524)

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
This commit is contained in:
Alex Saveau
2023-01-30 05:30:08 -08:00
committed by Dan Gohman
parent 5f3a7598d6
commit dfbdf3c300
+7 -1
View File
@@ -172,7 +172,7 @@ impl<'buf, Fd: AsFd> RawDir<'buf, Fd> {
/// GAT support once one becomes available.
#[allow(unsafe_code)]
pub fn next(&mut self) -> Option<io::Result<RawDirEntry>> {
if self.offset >= self.initialized {
if self.is_buffer_empty() {
match getdents_uninit(self.fd.as_fd(), self.buf) {
Ok(bytes_read) if bytes_read == 0 => return None,
Ok(bytes_read) => {
@@ -201,4 +201,10 @@ impl<'buf, Fd: AsFd> RawDir<'buf, Fd> {
file_name: unsafe { CStr::from_ptr(dirent.d_name.as_ptr().cast()) },
}))
}
/// Returns true if the internal buffer is empty and will be refilled when calling
/// [`next`][Self::next].
pub fn is_buffer_empty(&self) -> bool {
self.offset >= self.initialized
}
}