Skip to content

Commit aa7bae0

Browse files
committed
[library/std pal::safaos::fs]: bug fixes
1 parent 9de061c commit aa7bae0

File tree

1 file changed

+24
-7
lines changed
  • library/std/src/sys/pal/safaos

1 file changed

+24
-7
lines changed

library/std/src/sys/pal/safaos/fs.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ impl DirIterResource {
6868
}
6969

7070
fn next(&mut self) -> Option<raw::DirEntry> {
71-
let raw = syscalls::diriter_next(self.0).unwrap();
71+
// should never error expect if there is no more entries it returns ErrorStatus::Generic
72+
let raw = syscalls::diriter_next(self.0).ok()?;
7273
if raw == unsafe { core::mem::zeroed() } { None } else { Some(raw) }
7374
}
7475
}
@@ -364,8 +365,16 @@ impl File {
364365
}
365366

366367
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
367-
let at = unsafe { *self.seek_at.get() };
368-
Ok(self.fd.read(at, buf)?)
368+
let at = unsafe { &mut *self.seek_at.get() };
369+
370+
let read = match self.fd.read(*at, buf) {
371+
Ok(amount) => amount,
372+
Err(ErrorStatus::InvaildOffset) => return Ok(0),
373+
Err(other) => return Err(other.into()),
374+
};
375+
*at += read as isize;
376+
377+
Ok(read)
369378
}
370379

371380
pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
@@ -376,13 +385,21 @@ impl File {
376385
false
377386
}
378387

379-
pub fn read_buf(&self, _cursor: BorrowedCursor<'_>) -> io::Result<()> {
380-
todo!()
388+
pub fn read_buf(&self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
389+
crate::io::default_read_buf(|buf| self.read(buf), cursor)
381390
}
382391

383392
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
384-
let at = unsafe { *self.seek_at.get() };
385-
Ok(self.fd.write(at, buf)?)
393+
let at = unsafe { &mut *self.seek_at.get() };
394+
395+
let wrote = match self.fd.write(*at, buf) {
396+
Ok(amount) => amount,
397+
Err(ErrorStatus::InvaildOffset) => return Ok(0),
398+
Err(other) => return Err(other.into()),
399+
};
400+
*at += wrote as isize;
401+
402+
Ok(wrote)
386403
}
387404

388405
pub fn write_vectored(&self, _bufs: &[IoSlice<'_>]) -> io::Result<usize> {

0 commit comments

Comments
 (0)