+ workaround for newer wasmtime versions that don't report the fd type of

stdin/stdout/stderr. Always assume handles 0..2 are a device, so that
  standard input and output are flushed.

git-svn-id: trunk@49541 -
This commit is contained in:
nickysn 2021-06-23 21:22:15 +00:00
parent 827f543289
commit 720068360e

View File

@ -58,8 +58,19 @@ end;
function Do_IsDevice(Handle:THandle):boolean;
var
res: __wasi_errno_t;
ourfdstat: __wasi_fdstat_t;
begin
__wasi_fd_fdstat_get(Handle,@ourfdstat);
Do_IsDevice:=ourfdstat.fs_filetype in [__WASI_FILETYPE_BLOCK_DEVICE,__WASI_FILETYPE_CHARACTER_DEVICE];
res:=__wasi_fd_fdstat_get(Handle,@ourfdstat);
if res=__WASI_ERRNO_SUCCESS then
begin
if ourfdstat.fs_filetype=__WASI_FILETYPE_UNKNOWN then
{ wasmtime 0.24.0 and later versions return __WASI_FILETYPE_UNKNOWN for stdin/stdout/stderr }
Do_IsDevice:=Handle<=2
else
Do_IsDevice:=ourfdstat.fs_filetype in [__WASI_FILETYPE_BLOCK_DEVICE,__WASI_FILETYPE_CHARACTER_DEVICE]
end
else
{ in case of error (e.g. access denied), assume device for stdin/stdout/stderr }
Do_IsDevice:=Handle<=2;
end;