[fpc-pascal] RE: findfirst and findnext on non accessible files

Tomas Hajny XHajT03 at mbox.vol.cz
Thu Jun 29 00:38:40 CEST 2006


On 29 Jun 06, at 0:19, Marc Santhoff wrote:
> Am Donnerstag, den 29.06.2006, 00:04 +0200 schrieb Michael Van Canneyt:
 .
 .
> My approach to detect failing FindFirst/FindNext would be to do
> something like this:
> 
> <--- rtl/unix/sysutils.pp:549 --->
> Function GlobToTSearchRec (Var Info : TSearchRec) : Boolean;
> 
> Var SInfo : Stat;
>     p     : Pglob;
>     GlobSearchRec : PGlobSearchrec;
> 
> begin
>   GlobSearchRec:=Info.FindHandle;
>   P:=GlobSearchRec^.GlobHandle;
>   Result:=P<>Nil;
>   If Result then
>     begin
>     GlobSearchRec^.GlobHandle:=P^.Next;
>     Result:=Fpstat(GlobSearchRec^.Path+StrPas(p^.name),SInfo)>=0;
> +    if NOT Result then
> +      begin
> +        fpseterrno(??? anything "legal" representing the system error);
> +      end;
>     Info.PathOnly:=GlobSearchRec^.Path;
>     If Result then
> </--->
> 
> I'd appreciate hints on doing it this way (getting system error number
> by "fpgetCerrno()"?) or some better technique.
> 
> If the errno variants are not reliable it could be done by
> 
> 1. using an additional out-parameter value
> 2. changing the result from boolean to interger or longint returning the
> error number
> 
> But both methods would break old code.

If I understand it correctly, GlobToTSearchRec is 
an internal function (not available in 
interface), and only used in function DoFind. 
Changing e.g. its return value shouldn't cause 
any harm.

Tomas



More information about the fpc-pascal mailing list