Skip to content

Commit d78fac6

Browse files
authored
Add method to know when buffer will be refilled (#524)
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
1 parent 89a485e commit d78fac6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/fs/raw_dir.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'buf, Fd: AsFd> RawDir<'buf, Fd> {
172172
/// GAT support once one becomes available.
173173
#[allow(unsafe_code)]
174174
pub fn next(&mut self) -> Option<io::Result<RawDirEntry>> {
175-
if self.offset >= self.initialized {
175+
if self.is_buffer_empty() {
176176
match getdents_uninit(self.fd.as_fd(), self.buf) {
177177
Ok(bytes_read) if bytes_read == 0 => return None,
178178
Ok(bytes_read) => {
@@ -201,4 +201,10 @@ impl<'buf, Fd: AsFd> RawDir<'buf, Fd> {
201201
file_name: unsafe { CStr::from_ptr(dirent.d_name.as_ptr().cast()) },
202202
}))
203203
}
204+
205+
/// Returns true if the internal buffer is empty and will be refilled when calling
206+
/// [`next`][Self::next].
207+
pub fn is_buffer_empty(&self) -> bool {
208+
self.offset >= self.initialized
209+
}
204210
}

0 commit comments

Comments
 (0)