[fpc-devel]Linux readdir syscall is superseded by getdents

Joost van der Sluis joost at cnoc.nl
Sun Apr 4 17:23:23 CEST 2004


Hello all,

I'm new to this list and I coudn't find out how to send in patches so i do
it here...

On my system FPC doesn't work because the fpreaddir-function failes on
larger directories. I saw that fpreaddir still uses the linux
readdir-call, wich is superseded by getdents. (also the comments are
wrong. The result of the readdir-call isn't the amount of bytes
read. That's only the case by the getdents-call)

I've rewritten Fpreaddir (in rtl/linux/ossysc.inc) as follows:

-----
Function Fpreaddir(dirp : pdir) : pdirent; [public, alias
: 'FPC_SYSC_READDIR'];                                                                                

{readdir is obsolete. Use getdents instead...}

var bytes : integer;
    dp    : pdirent;	
                                                                               
begin
  repeat
  if dirp^.dd_nextoff >= dirp^.dd_size then
    begin
      bytes :=
do_SysCall(SysCall_nr_getdents,TSysParam(dirp^.dd_fd),TSysParam(dirp^.dd_buf),TSysParam(dirp^.dd_max));
      if bytes <= 0 then
	begin
	  fpreaddir := nil;
	  exit;
        end;
      dirp^.dd_size := bytes;
      dirp^.dd_nextoff := 0;
    end;
  dp := pdirent(ptrint(dirp^.dd_buf)+dirp^.dd_nextoff);
  dirp^.dd_nextoff := dirp^.dd_nextoff + dp^.d_reclen;
  dirp^.dd_loc := dirp^.dd_loc + dp^.d_reclen;
  until dp^.d_fileno <> 0; // Don't show deleted files
  Fpreaddir := dp;
end;

-----

and I had to change Fpopendir a little. Just added

---
  ptr^.dd_nextoff:= 0;
--- 

before the last line.

Oh, and btw: in install/install.sh the version-number is still 1.9.2,
which causes the installation to fail. (symbolic links are wronly created)

Joost van der Sluis.






More information about the fpc-devel mailing list