+ implemented DOS.GetFAttr for WASI

This commit is contained in:
Nikolay Nikolov 2021-10-12 09:14:14 +03:00
parent 4e605fb764
commit ca242e9ad0

View File

@ -696,42 +696,27 @@ Begin
End; End;
Procedure GetFAttr(var f; var attr : word); Procedure GetFAttr(var f; var attr : word);
(*Var Var
info : baseunix.stat; pr: RawByteString;
LinAttr : longint; fd: __wasi_fd_t;
p : pchar; Info: __wasi_filestat_t;
{$ifndef FPC_ANSI_TEXTFILEREC}
r : RawByteString;
{$endif not FPC_ANSI_TEXTFILEREC}*)
Begin Begin
(* DosError:=0; DosError:=0;
{$ifdef FPC_ANSI_TEXTFILEREC} Attr:=0;
{ encoding is already correct } if ConvertToFdRelativePath(textrec(f).name,fd,pr)<>0 then
p:=@textrec(f).name; begin
{$else} DosError:=3;
r:=ToSingleByteFileSystemEncodedFileName(textrec(f).name); exit;
p:=pchar(r); end;
{$endif} if __wasi_path_filestat_get(fd,__WASI_LOOKUPFLAGS_SYMLINK_FOLLOW,PChar(pr),length(pr),@Info)<>__WASI_ERRNO_SUCCESS then
{ use the pchar rather than the rawbytestring version so that we don't check begin
a second time whether the string needs to be converted to the right code DosError:=3;
page exit;
} end;
if FPStat(p,info)<0 then if Info.filetype=__WASI_FILETYPE_DIRECTORY then
begin Attr:=$10;
Attr:=0;
DosError:=3;
exit;
end
else
LinAttr:=Info.st_Mode;
if fpS_ISDIR(LinAttr) then
Attr:=$10
else
Attr:=$0;
if fpAccess(p,W_OK)<0 then
Attr:=Attr or $1;
if filerec(f).name[0]='.' then if filerec(f).name[0]='.' then
Attr:=Attr or $2;*) Attr:=Attr or $2;
end; end;
Procedure getftime (var f; var time : longint); Procedure getftime (var f; var time : longint);