diff --git a/rtl/wasi/sysfile.inc b/rtl/wasi/sysfile.inc index 19f0eed266..8cb5fea437 100644 --- a/rtl/wasi/sysfile.inc +++ b/rtl/wasi/sysfile.inc @@ -37,22 +37,46 @@ function Do_Write(Handle:thandle;Addr:Pointer;Len:Longint):longint; var our_iov: __wasi_ciovec_t; our_nwritten: longint; + res: __wasi_errno_t; begin - our_iov.buf := Addr; - our_iov.buf_len := Len; - fd_write(Handle, @our_iov, 1, @our_nwritten); - Do_Write:=our_nwritten; + repeat + our_iov.buf := Addr; + our_iov.buf_len := Len; + res:=fd_write(Handle, @our_iov, 1, @our_nwritten); + until (res=__WASI_ERRNO_SUCCESS) or ((res<>__WASI_ERRNO_INTR) and (res<>__WASI_ERRNO_AGAIN)); + if res=__WASI_ERRNO_SUCCESS then + begin + Do_Write:=our_nwritten; + InOutRes:=0; + end + else + begin + Do_Write:=0; + InOutRes:=Errno2InoutRes(res); + end; end; function Do_Read(Handle:thandle;Addr:Pointer;Len:Longint):Longint; var our_iov: __wasi_iovec_t; our_nread: __wasi_size_t; + res: __wasi_errno_t; begin - our_iov.buf:=Addr; - our_iov.buf_len:=Len; - fd_read(Handle,@our_iov,1,@our_nread); - Do_Read:=our_nread; + repeat + our_iov.buf:=Addr; + our_iov.buf_len:=Len; + fd_read(Handle,@our_iov,1,@our_nread); + until (res=__WASI_ERRNO_SUCCESS) or ((res<>__WASI_ERRNO_INTR) and (res<>__WASI_ERRNO_AGAIN)); + if res=__WASI_ERRNO_SUCCESS then + begin + Do_Read:=our_nread; + InOutRes:=0; + end + else + begin + Do_Read:=0; + InOutRes:=Errno2InoutRes(res); + end; end; function Do_FilePos(Handle: thandle):Int64; diff --git a/rtl/wasi/sysos.inc b/rtl/wasi/sysos.inc index 4a8247606b..bd35669e6f 100644 --- a/rtl/wasi/sysos.inc +++ b/rtl/wasi/sysos.inc @@ -15,22 +15,42 @@ **********************************************************************} -{procedure GetInOutRes(def: Word); -var - regs : Registers; +function Errno2InoutRes(errno: __wasi_errno_t): Word; begin - regs.AX:=$5900; - regs.BX:=$0; - MsDos(regs); - InOutRes:=regs.AX; - case InOutRes of - 19 : InOutRes:=150; - 21 : InOutRes:=152; - 32 : InOutRes:=5; + case errno of + __WASI_ERRNO_NFILE, + __WASI_ERRNO_MFILE: + Errno2InoutRes:=4; + __WASI_ERRNO_NOENT: + Errno2InoutRes:=2; + __WASI_ERRNO_BADF: + Errno2InoutRes:=6; + __WASI_ERRNO_NOMEM, + __WASI_ERRNO_FAULT: + Errno2InoutRes:=217; + __WASI_ERRNO_INVAL: + Errno2InoutRes:=218; + __WASI_ERRNO_PIPE, + __WASI_ERRNO_INTR, + __WASI_ERRNO_IO, + __WASI_ERRNO_AGAIN, + __WASI_ERRNO_NOSPC: + Errno2InoutRes:=101; + __WASI_ERRNO_NAMETOOLONG: + Errno2InoutRes:=3; + __WASI_ERRNO_ROFS, + __WASI_ERRNO_EXIST, + __WASI_ERRNO_NOTEMPTY, + __WASI_ERRNO_ACCES: + Errno2InoutRes:=5; + __WASI_ERRNO_BUSY, + __WASI_ERRNO_NOTDIR, // busy, enotdir, mantis #25931 + __WASI_ERRNO_ISDIR: + Errno2InoutRes:=5; + else + Errno2InoutRes:=errno; end; - if InOutRes=0 then - InOutRes:=Def; -end;} +end; {***************************************************************************** Low Level File Routines