Browse Source

+ 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 -

nickysn 4 years ago
parent
commit
720068360e
1 changed files with 13 additions and 2 deletions
  1. 13 2
      rtl/wasi/sysos.inc

+ 13 - 2
rtl/wasi/sysos.inc

@@ -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;