mirror of
https://github.com/openharmony/third_party_rust_rustix.git
synced 2026-07-19 23:03:36 -04:00
Add method to know when buffer will be refilled (#524)
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
This commit is contained in:
+7
-1
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user