From 920836fd0d23e6bb2861398dbbcd3f9a0c9bf441 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sun, 3 Nov 2024 21:14:52 +0100 Subject: [PATCH] Change dup syscall return type --- src/api/fs.rs | 7 ++++--- src/api/syscall.rs | 6 +++--- src/sys/syscall/service.rs | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/api/fs.rs b/src/api/fs.rs index 985b613e..a7bb5b58 100644 --- a/src/api/fs.rs +++ b/src/api/fs.rs @@ -248,9 +248,10 @@ pub fn reopen(path: &str, handle: usize, append: bool) -> Result { 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(()) } diff --git a/src/api/syscall.rs b/src/api/syscall.rs index 45d0ec09..d626699b 100644 --- a/src/api/syscall.rs +++ b/src/api/syscall.rs @@ -60,12 +60,12 @@ pub fn open(path: &str, flags: u8) -> Option { } } -pub fn dup(old_handle: usize, new_handle: usize) -> Option { +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(()) } } diff --git a/src/sys/syscall/service.rs b/src/sys/syscall/service.rs index a4e1d5e6..cb099516 100644 --- a/src/sys/syscall/service.rs +++ b/src/sys/syscall/service.rs @@ -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 }