Browse Source

* Fixed a readdir bug, already fixed in januari in 1.0.x

marco 23 years ago
parent
commit
a6426d100a
1 changed files with 29 additions and 22 deletions
  1. 29 22
      rtl/freebsd/syscalls.inc

+ 29 - 22
rtl/freebsd/syscalls.inc

@@ -42,7 +42,7 @@ paste to and AS source). Ultimately I hope to design something like this}
 procedure actualsyscall; cdecl; EXTERNAL NAME '_actualsyscall';
 procedure actualsyscall; cdecl; EXTERNAL NAME '_actualsyscall';
 }
 }
 
 
-procedure actualsyscall; assembler;
+procedure actualsyscall; assembler; {inline requires a dummy push IIRC}
     asm
     asm
          int $0x80
          int $0x80
          jb .LErrorcode
          jb .LErrorcode
@@ -53,7 +53,6 @@ procedure actualsyscall; assembler;
          mov $-1,%eax
          mov $-1,%eax
    end;
    end;
 
 
-
 function Do_SysCall(sysnr:LONGINT):longint; assembler;
 function Do_SysCall(sysnr:LONGINT):longint; assembler;
 
 
 asm
 asm
@@ -301,6 +300,7 @@ begin
  sys_rmdir:=do_syscall(syscall_nr_rmdir,longint(filename));
  sys_rmdir:=do_syscall(syscall_nr_rmdir,longint(filename));
 end;
 end;
 
 
+{$ifndef NewReaddir}
 
 
 const DIRBLKSIZ=1024;
 const DIRBLKSIZ=1024;
 
 
@@ -373,42 +373,46 @@ begin
 end;
 end;
 
 
 var
 var
-    l              : pdirent;
+    FinalEntry     : pdirent;
     novalid        : boolean;
     novalid        : boolean;
-
+    Reclen	   : Longint;
+    CurEntry	   : PDirent;
 begin
 begin
  if (p^.buf=nil) or (p^.loc=0) THEN
  if (p^.buf=nil) or (p^.loc=0) THEN
   exit(nil);
   exit(nil);
- if p^.loc=-1 then         {First readdir on this pdir. Initial fill of buffer}
-  begin
-   if readbuffer()=0 Then    {nothing to be read}
-    exit(nil)
-  end;
- l:=nil;
+ if (p^.loc=-1)   OR     {First readdir on this pdir. Initial fill of buffer}
+   (p^.rewind>=(longint(p^.buf)+dirblksiz)) then  {no more entries left?}
+  Begin
+    if readbuffer=0 then        {succesful read?}
+     Exit(NIL);			{No more data}
+  End;
+ FinalEntry:=NIL;
+ CurEntry:=nil;
  repeat
  repeat
   novalid:=false;
   novalid:=false;
-  if (pdirent(p^.rewind)^.reclen<>0) then
+  CurEntry:=pdirent(p^.rewind);
+  RecLen:=CurEntry^.reclen;
+  if RecLen<>0 Then
    begin {valid direntry?}
    begin {valid direntry?}
-    if pdirent(P^.rewind)^.ino<>0 then
-     l:=pdirent(p^.rewind);       
-    inc(p^.rewind,pdirent(p^.rewind)^.reclen);
-    if p^.rewind>=(longint(p^.buf)+dirblksiz) then
-     novalid:=true;
+    if CurEntry^.ino<>0 then
+     FinalEntry:=CurEntry;
+    inc(p^.rewind,Reclen);
    end
    end
   else
   else
-   novalid:=true;
-  if novalid then
    begin {block entirely searched or reclen=0}
    begin {block entirely searched or reclen=0}
+    Novalid:=True;
     if p^.loc<>0 THEN             {blocks left?}
     if p^.loc<>0 THEN             {blocks left?}
      if readbuffer()<>0 then        {succesful read?}
      if readbuffer()<>0 then        {succesful read?}
       novalid:=false;
       novalid:=false;
    end;
    end;
- until (l<>nil) or novalid;
+ until (FinalEntry<>nil) or novalid;
  If novalid then
  If novalid then
-  l:=nil;
- Sys_ReadDir:=l;
+  FinalEntry:=nil;
+ Sys_ReadDir:=FinalEntry;
 end;
 end;
 
 
+{$endif}
+
 
 
 {*****************************************************************************
 {*****************************************************************************
         --- Process:Process & program handling - related calls ---
         --- Process:Process & program handling - related calls ---
@@ -510,7 +514,10 @@ end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.7  2001-08-27 09:35:07  marco
+  Revision 1.8  2002-05-06 07:27:39  marco
+   * Fixed a readdir bug, already fixed in januari in 1.0.x
+
+  Revision 1.7  2001/08/27 09:35:07  marco
    * Ftruncate intermediate fix.
    * Ftruncate intermediate fix.
 
 
   Revision 1.6  2001/06/19 08:34:16  marco
   Revision 1.6  2001/06/19 08:34:16  marco