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

Marc Santhoff M.Santhoff at t-online.de
Fri Jun 30 12:04:04 CEST 2006

Am Donnerstag, den 29.06.2006, 16:16 +0200 schrieb Marc Santhoff:

> How can i detect if sysutils.FindFirst() or FindNext() fails lacking
> permissions?

As a quick and dirty hack I added an addtitional "stat" on the starting
dir for FindFirst and let it bail out early for protecting
"ErrNo" ("opendir" gives no reasonable error code on FreeBSD). This in
combination with a bug fix in my code using FindFirst solves the problem
for me for now. Most important is I'm no longer blocked working on my

I'm aware of the fact that there might be problems when hitting an
unreadable item while recursing, but for my program I can rule out this

This was done on FreeBSD 4.11 with fpc 2.0.2 release.

*** sysutils.pp.org	Thu Jun 29 00:06:06 2006
--- sysutils.pp	Fri Jun 30 05:07:22 2006
*** 479,490 ****
--- 479,496 ----
    buffer  : pdirent;
    current : pglob;
+   SInfo : Stat;
+   res: longint;
+   temp3: string[255];
  { Get directory }
    if temp='' then
+   temp3 := temp+'/.'+#0;
+   res := fpstat(temp3, SInfo);
+   if (res<>0) then exit(nil);
    if thedir=nil then

Maybe lateron I'll come back on this topic. Did I understand correctly
that a new implementation :-

- does not need to defer "readdir" or "stat" calls for being fast enough
on modern system implementations

- there could be a check for looping symlinks

- anything else?


More information about the fpc-pascal mailing list