From 8c39213d39eca0bfe89168734159f86bebbcbb4a Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Tue, 19 Oct 2021 16:24:43 +0300 Subject: [PATCH] + implemented DOS.FSearch for WASI --- rtl/wasi/dos.pp | 55 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/rtl/wasi/dos.pp b/rtl/wasi/dos.pp index 191af213f2..2bd9c6b391 100644 --- a/rtl/wasi/dos.pp +++ b/rtl/wasi/dos.pp @@ -451,15 +451,52 @@ End; --- File --- ******************************************************************************} -Function FSearch(path : pathstr;dirlist : string) : pathstr; -{Var - info : BaseUnix.stat;} -Begin -{ if (length(Path)>0) and (path[1]='/') and (fpStat(path,info)>=0) and (not fpS_ISDIR(Info.st_Mode)) then - FSearch:=path - else - FSearch:=Unix.FSearch(path,dirlist);} -End; +Function FSearch(path: pathstr; dirlist: string): pathstr; +var + p1 : longint; + s : searchrec; + newdir : pathstr; +begin + { No wildcards allowed in these things } + if (pos('?',path)<>0) or (pos('*',path)<>0) then + begin + fsearch:=''; + exit; + end; + { check if the file specified exists } + findfirst(path,anyfile and not(directory),s); + if doserror=0 then + begin + findclose(s); + fsearch:=path; + exit; + end; + findclose(s); + //{ allow slash as backslash } + //DoDirSeparators(dirlist); + repeat + p1:=pos(';',dirlist); + if p1<>0 then + begin + newdir:=copy(dirlist,1,p1-1); + delete(dirlist,1,p1); + end + else + begin + newdir:=dirlist; + dirlist:=''; + end; + if (newdir<>'') and (not (newdir[length(newdir)] in (AllowDirectorySeparators+[':']))) then + newdir:=newdir+DirectorySeparator; + findfirst(newdir+path,anyfile and not(directory),s); + if doserror=0 then + newdir:=newdir+path + else + newdir:=''; + findclose(s); + until (dirlist='') or (newdir<>''); + fsearch:=newdir; +end; Procedure GetFAttr(var f; var attr : word); Var