+ implemented FindFirst, FindNext and FindClose in SysUtils for the WASI platform

This commit is contained in:
Nikolay Nikolov 2021-10-19 15:39:59 +03:00
parent 090cc8fa8f
commit 8e730d20db
2 changed files with 42 additions and 7 deletions

View File

@ -43,6 +43,10 @@ Type
TFindData = TNativeNTFindData; TFindData = TNativeNTFindData;
{$define SEARCHREC_USEFINDDATA} {$define SEARCHREC_USEFINDDATA}
{$endif} {$endif}
{$ifdef wasi}
TFindData = TWasiFindData;
{$define SEARCHREC_USEFINDDATA}
{$endif}
// The actual unicode search record // The actual unicode search record
TUnicodeSearchRec = Record TUnicodeSearchRec = Record

View File

@ -26,7 +26,7 @@ interface
{$modeswitch advancedrecords} {$modeswitch advancedrecords}
uses uses
wasiapi; wasiapi, wasiutil;
{$DEFINE OS_FILESETDATEBYNAME} {$DEFINE OS_FILESETDATEBYNAME}
{$DEFINE HAS_SLEEP} {$DEFINE HAS_SLEEP}
@ -37,6 +37,9 @@ uses
{ OS has an ansistring/single byte environment variable API } { OS has an ansistring/single byte environment variable API }
{$define SYSUTILS_HAS_ANSISTR_ENVVAR_IMPL} {$define SYSUTILS_HAS_ANSISTR_ENVVAR_IMPL}
type
TWasiFindData = TWasiSearchRec;
{ Include platform independent interface part } { Include platform independent interface part }
{$i sysutilh.inc} {$i sysutilh.inc}
@ -44,7 +47,7 @@ uses
implementation implementation
uses uses
sysconst, wasiutil; sysconst;
{$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *) {$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
{$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *) {$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
@ -526,21 +529,49 @@ end;
Function InternalFindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TAbstractSearchRec; var Name: RawByteString) : Longint; Function InternalFindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TAbstractSearchRec; var Name: RawByteString) : Longint;
var
derror: longint;
begin begin
{ not yet implemented } Result:=-1;
Result := -1; { this is safe even though Rslt actually contains a refcounted field, because
it is declared as "out" and hence has already been initialised }
fillchar(Rslt,sizeof(Rslt),0);
if Path='' then
exit;
derror:=WasiFindFirst(Path, Attr, Rslt.FindData);
if derror=0 then
result:=0
else
result:=-1;
Name:=Rslt.FindData.Name;
Rslt.Attr:=Rslt.FindData.Attr;
Rslt.Size:=Rslt.FindData.Size;
Rslt.Time:=Rslt.FindData.Time div 1000000000;
end; end;
Function InternalFindNext (var Rslt : TAbstractSearchRec; var Name : RawByteString) : Longint; Function InternalFindNext (var Rslt : TAbstractSearchRec; var Name : RawByteString) : Longint;
var
derror: longint;
begin begin
{ not yet implemented } derror:=WasiFindNext(Rslt.FindData);
Result := -1; if derror=0 then
result:=0
else
result:=-1;
Name:=Rslt.FindData.Name;
Rslt.Attr:=Rslt.FindData.Attr;
Rslt.Size:=Rslt.FindData.Size;
Rslt.Time:=Rslt.FindData.Time div 1000000000;
end; end;
Procedure InternalFindClose(var Handle: THandle); Procedure InternalFindClose(var Handle: THandle; var FindData: TFindData);
begin begin
WasiFindClose(FindData);
end; end;