Skip to content

Commit

Permalink
Early return success when writing 0
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Nov 18, 2024
1 parent b1b841f commit 2b350fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/syscalls/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,9 @@ pub fn read(fd: u64, buffer: &mut [u8]) -> Result<usize, SysError> {
/// Note: available after ckb 2nd hardfork.
pub fn write(fd: u64, buffer: &[u8]) -> Result<usize, SysError> {
let mut l: u64 = buffer.len() as u64;
if l == 0 {
return Ok(0);
}
let ret = unsafe {
syscall(
fd,
Expand Down
3 changes: 3 additions & 0 deletions src/syscalls/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ pub fn read(fd: u64, buffer: &mut [u8]) -> Result<usize, SysError> {

pub fn write(fd: u64, buffer: &[u8]) -> Result<usize, SysError> {
let mut l = buffer.len();
if l == 0 {
return Ok(0);
}
let ret = sim::ckb_write(fd, buffer.as_ptr() as *mut c_void, &mut l as *mut usize) as u64;
match ret {
0 => Ok(l as usize),
Expand Down

0 comments on commit 2b350fb

Please sign in to comment.