Hi

Kylix adds field "Mode" to TSearchRec type under Linux. This field comes directly from UNIX stat structure (st_mode field). It is useful when you already have TSearchRec describing some file and you want to check the exact type of that file, e.g. "is it a symbolic link ? is it a device ?". It would be silly to call lstat with full filename, when all needed information was already available when constructing TSearchRec for this file.

I am not exactly a Kylix enthusiast but this "Mode" field is something that I consider useful. I guess that you will agree with this since you already added OS-specific fields to TSearchRec for Windows and Netware.

So I made a small patches to "rtl/objpas/sysutils/filutilh.inc" and "rtl/unix/sysutils.pp" to implement this. Well, that wasn't much work; all information was already available. I'm attaching those patches as "filutilh.inc.patch" and "sysutils.pp.patch". I'm also attaching very short demo program, "mode_field_demo.pas", to show that it really works.

Note: it would be more elegant to wrap "Mode" field inside something like "FindData: TUNIXFindData". This would break Kylix compatibility, but I don't know is there a real need to be compatible with Kylix. Personally, I want something like "Mode" field to be included in TSearchRec not because of Kylix compatiblity but because it's just useful.

BTW: Are you going to apply my Libc fixes (from letter "A few fixes for Libc unit") ? If you want I can provide a simple test program (to show that those fixes are really needed and that they are really fixing the problems) and/or ready-to-apply patches.

Regards,
Michalis
Index: filutilh.inc
===================================================================
RCS file: /FPC/CVS/fpc/rtl/objpas/sysutils/filutilh.inc,v
retrieving revision 1.2
diff -u -u -r1.2 filutilh.inc
--- filutilh.inc        8 Feb 2004 14:50:51 -0000       1.2
+++ filutilh.inc        24 Feb 2004 17:59:07 -0000
@@ -28,6 +28,9 @@
 {$ifdef netware}
     FindData : TNetwareFindData;
 {$endif}
+{$ifdef UNIX}
+    Mode : TMode;
+{$endif}
   end;
 
 Const
Index: sysutils.pp
===================================================================
RCS file: /FPC/CVS/fpc/rtl/unix/sysutils.pp,v
retrieving revision 1.36
diff -u -u -r1.36 sysutils.pp
--- sysutils.pp 13 Feb 2004 10:50:23 -0000      1.36
+++ sysutils.pp 24 Feb 2004 17:58:22 -0000
@@ -25,7 +25,7 @@
 {$DEFINE HAS_OSERROR}
 
 uses
-  Unix,errors,sysconst;
+  Baseunix,Unix,errors,sysconst;
 
 { Include platform independent interface part }
 {$i sysutilh.inc}
@@ -33,7 +33,7 @@
 
 implementation
 
-Uses UnixUtil,Baseunix;
+Uses UnixUtil;
 
 {$Define OS_FILEISREADONLY} // Specific implementation for Unix.
 
@@ -197,7 +197,7 @@
   If Result then
     begin
     GlobSearchRec^.GlobHandle:=P^.Next;
-    Result:=Fpstat(GlobSearchRec^.Path+StrPas(p^.name),SInfo)>=0;
+    Result:=FpLStat(GlobSearchRec^.Path+StrPas(p^.name), @SInfo)>=0;
     If Result then
       begin
       Info.Attr:=LinuxToWinAttr(p^.name,SInfo);
@@ -210,6 +210,7 @@
            Name:=strpas(p^.name);
            Time:=Sinfo.st_mtime;
            Size:=Sinfo.st_Size;
+           Mode:=Sinfo.st_mode;
            end;
       end;
     P^.Next:=Nil;
uses BaseUnix, Unix, SysUtils;

var 
  SR:TSearchRec;
  FindResult:Integer;
begin
 FindResult:=FindFirst('/*', faAnyFile, SR);
 try
  while FindResult=0 do
  begin                 
   Writeln(SR.Name:20, ' symlink ? ', FpS_ISLNK(SR.Mode));
   FindResult:=FindNext(SR);  
  end;
 finally FindClose(SR) end;
end.

Reply via email to