Skip to content

Commit

Permalink
Change dup syscall return type
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc committed Nov 3, 2024
1 parent acb2463 commit 920836f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/api/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,10 @@ pub fn reopen(path: &str, handle: usize, append: bool) -> Result<usize, ()> {
create_file(path)
};
if let Some(old_handle) = res {
syscall::dup(old_handle, handle);
syscall::close(old_handle);
return Ok(handle);
if syscall::dup(old_handle, handle).is_ok() {
syscall::close(old_handle);
return Ok(handle);
}
}
Err(())
}
Expand Down
6 changes: 3 additions & 3 deletions src/api/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ pub fn open(path: &str, flags: u8) -> Option<usize> {
}
}

pub fn dup(old_handle: usize, new_handle: usize) -> Option<usize> {
pub fn dup(old_handle: usize, new_handle: usize) -> Result<(), ()> {
let res = unsafe { syscall!(DUP, old_handle, new_handle) } as isize;
if res >= 0 {
Some(res as usize)
Ok(())
} else {
None
Err(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sys/syscall/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn open(path: &str, flags: u8) -> isize {
pub fn dup(old_handle: usize, new_handle: usize) -> isize {
if let Some(file) = sys::process::handle(old_handle) {
sys::process::update_handle(new_handle, *file);
return new_handle as isize;
return 0;
}
-1
}
Expand Down

0 comments on commit 920836f

Please sign in to comment.