[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Lost] [PATCH 3/5] Pascal-RTL: DirectoryExists



+ Pascal-RTL: sysutils.DirectoryExists
! Pascal-RTL: sysutils.FileExists gibt auch bei Verzeichnissen true zurueck
---
 src/modules/pas/lib/rtl/sysutils.pp |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/src/modules/pas/lib/rtl/sysutils.pp b/src/modules/pas/lib/rtl/sysutils.pp
index a106650..f4fd8fc 100644
--- a/src/modules/pas/lib/rtl/sysutils.pp
+++ b/src/modules/pas/lib/rtl/sysutils.pp
@@ -48,6 +48,22 @@ function c_fseek(f: longint; offset, whence: longint): longint; cdecl; external
 
 function c_feof(f: longint): boolean; cdecl; external name 'feof';
 
+type
+    DirEntry = record
+        name:   array [1..32] of char;
+        ftype:  byte;
+        size:   qword;
+
+        ctime,
+        mtime,
+        atime:  qword;
+    end;
+    PDirEntry = ^DirEntry;
+
+function c_directory_open(dirname: PChar): Pointer; cdecl; external name 'directory_open';
+function c_directory_close(handle: Pointer): longint; cdecl; external name 'directory_close';
+function c_directory_read(handle: Pointer): PDirEntry; cdecl; external name 'directory_read';
+
 
 function FileOpen(const filename: String; mode: Integer): LongInt;
 var
@@ -101,6 +117,8 @@ begin
     FileExists := handle <> -1;
     if FileExists then begin
         FileClose(handle);
+    end else begin
+        FileExists := DirectoryExists(FileName);
     end;
 end;
 
@@ -196,8 +214,14 @@ begin
 end;    
 
 function DirectoryExists(const directory: AnsiString):Boolean;
+var
+    handle: Pointer;
 begin
-    Result := true; // FIXME
+    handle := c_directory_open(@directory[1]);
+    DirectoryExists := (handle <> nil);
+    if DirectoryExists then begin
+        c_directory_close(handle);
+    end;
 end;
 
 function FindFirst(const path: AnsiString; attr: LongInt;out rslt: TSearchRec):LongInt;
-- 
1.5.4.5