Преглед изворни кода

- fixed system.chdir() to properly return error
+ better, more Amigaish sysutils.DirectoryExists() implementation

git-svn-id: trunk@2195 -

Károly Balogh пре 19 година
родитељ
комит
000e839d77
2 измењених фајлова са 23 додато и 7 уклоњено
  1. 2 0
      rtl/morphos/sysdir.inc
  2. 21 7
      rtl/morphos/sysutils.pp

+ 2 - 0
rtl/morphos/sysdir.inc

@@ -75,6 +75,8 @@ begin
       MOS_OrigDir:=tmpLock;
       tmpLock:=0;
     end;
+  end else begin
+    dosError2InOut(ERROR_DIR_NOT_FOUND);
   end;
 
   if tmpLock<>0 then Unlock(tmpLock);

+ 21 - 7
rtl/morphos/sysutils.pp

@@ -427,18 +427,32 @@ begin
 end;
 
 
-Function DirectoryExists(const Directory: string): Boolean;
+function DirectoryExists(const Directory: string): Boolean;
 var
- s: string;
+  tmpStr : array[0..255] of Char;
+  tmpLock: LongInt;
+  FIB    : PFileInfoBlock;
 begin
-  { Get old directory }
-  s:=GetCurrentDir;
-  ChDir(Directory);
-  DirectoryExists := (IOResult = 0);
-  ChDir(s);
+  DirectoryExists:=False;
+  If (Directory='') or (InOutRes<>0) then exit;
+  tmpStr:=PathConv(Directory)+#0;
+  tmpLock:=0;
+
+  tmpLock:=Lock(@tmpStr,SHARED_LOCK);
+  if tmpLock=0 then exit;
+
+  FIB:=nil; new(FIB);
+
+  if (Examine(tmpLock,FIB)=True) and (FIB^.fib_DirEntryType>0) then begin
+    DirectoryExists:=True;
+  end;
+
+  if tmpLock<>0 then Unlock(tmpLock);
+  if assigned(FIB) then dispose(FIB);
 end;
 
 
+
 {****************************************************************************
                               Misc Functions
 ****************************************************************************}