+ started working on DOS.FindFirst

git-svn-id: trunk@49555 -
This commit is contained in:
nickysn 2021-06-24 01:35:24 +00:00
parent 73aa30ee0a
commit 5eac35664f

View File

@ -24,7 +24,7 @@ Type
{$endif FPC_REQUIRES_PROPER_ALIGNMENT} {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
Record Record
{Fill : array[1..21] of byte; Fill replaced with below} {Fill : array[1..21] of byte; Fill replaced with below}
// SearchPos : TOff; {directory position} SearchPos : UInt64; {directory position}
SearchNum : LongInt; {to track which search this is} SearchNum : LongInt; {to track which search this is}
DirPtr : Pointer; {directory pointer for reading directory} DirPtr : Pointer; {directory pointer for reading directory}
SearchType : Byte; {0=normal, 1=open will close, 2=only 1 file} SearchType : Byte; {0=normal, 1=open will close, 2=only 1 file}
@ -69,15 +69,15 @@ Uses
--- Link C Lib if set --- --- Link C Lib if set ---
******************************************************************************} ******************************************************************************}
{type type
RtlInfoType = Record RtlInfoType = Record
FMode, FMode: LongInt;
FInode, {FInode,
FUid, FUid,
FGid, FGid,}
FSize, FSize: __wasi_filesize_t;
FMTime : LongInt; FMTime: __wasi_timestamp_t;
End;} End;
{****************************************************************************** {******************************************************************************
@ -405,22 +405,32 @@ End;
Function FindGetFileInfo(const s:string;var f:SearchRec):boolean; Function FindGetFileInfo(const s:string;var f:SearchRec):boolean;
{var var
s_ansi: ansistring;
DT : DateTime; DT : DateTime;
Info : RtlInfoType; Info : RtlInfoType;
st : baseunix.stat;} st : __wasi_filestat_t;
fd : __wasi_fd_t;
pr : PChar;
begin begin
{ FindGetFileInfo:=false; FindGetFileInfo:=false;
if not fpstat(s,st)>=0 then s_ansi:=s;
exit; if not ConvertToFdRelativePath(PChar(s_ansi),fd,pr) then
info.FSize:=st.st_Size; exit;
info.FMTime:=st.st_mtime; { todo: __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW??? }
if (st.st_mode and STAT_IFMT)=STAT_IFDIR then if __wasi_path_filestat_get(fd,0,pr,StrLen(pr),@st)<>__WASI_ERRNO_SUCCESS then
begin
FreeMem(pr);
exit;
end;
info.FSize:=st.size;
info.FMTime:=st.mtim;
if st.filetype=__WASI_FILETYPE_DIRECTORY then
info.fmode:=$10 info.fmode:=$10
else else
info.fmode:=$0; info.fmode:=$0;
if (st.st_mode and STAT_IWUSR)=0 then {if (st.st_mode and STAT_IWUSR)=0 then
info.fmode:=info.fmode or 1; info.fmode:=info.fmode or 1;}
if s[f.NamePos+1]='.' then if s[f.NamePos+1]='.' then
info.fmode:=info.fmode or $2; info.fmode:=info.fmode or $2;
@ -429,11 +439,12 @@ begin
f.Name:=Copy(s,f.NamePos+1,255); f.Name:=Copy(s,f.NamePos+1,255);
f.Attr:=Info.FMode; f.Attr:=Info.FMode;
f.Size:=Info.FSize; f.Size:=Info.FSize;
f.mode:=st.st_mode; {f.mode:=st.st_mode;}
UnixDateToDT(Info.FMTime, DT); WasiDateToDT(Info.FMTime, DT);
PackTime(DT,f.Time); PackTime(DT,f.Time);
FindGetFileInfo:=true; FindGetFileInfo:=true;
End;} End;
FreeMem(pr);
end; end;
@ -561,7 +572,7 @@ Procedure FindFirst(Const Path: PathStr; Attr: Word; Var f: SearchRec);
opens dir and calls FindWorkProc opens dir and calls FindWorkProc
} }
Begin Begin
(* fillchar(f,sizeof(f),0); fillchar(f,sizeof(f),0);
if Path='' then if Path='' then
begin begin
DosError:=3; DosError:=3;
@ -573,7 +584,7 @@ Begin
f.SearchAttr := Attr or archive or readonly; f.SearchAttr := Attr or archive or readonly;
f.SearchPos := 0; f.SearchPos := 0;
f.NamePos := Length(f.SearchSpec); f.NamePos := Length(f.SearchSpec);
while (f.NamePos>0) and (f.SearchSpec[f.NamePos]<>'/') do while (f.NamePos>0) and (f.SearchSpec[f.NamePos] in ['/','\']) do
dec(f.NamePos); dec(f.NamePos);
{Wildcards?} {Wildcards?}
if (Pos('?',Path)=0) and (Pos('*',Path)=0) then if (Pos('?',Path)=0) and (Pos('*',Path)=0) then
@ -599,7 +610,7 @@ Begin
f.SearchNum:=CurrSearchNum; f.SearchNum:=CurrSearchNum;
f.SearchType:=0; f.SearchType:=0;
FindNext(f); FindNext(f);
end;*) end;
End; End;