浏览代码

* converted the following sysutils routines to unicodestring and
rawbytestring: FileExists, DirectoryExists, FileSetDate, FileGetAttr,
FileSetAttr, DeleteFile, RenameFile, FileSearch, ExeSearch,
FileIsReadOnly

git-svn-id: branches/cpstrrtl@25078 -

Jonas Maebe 12 年之前
父节点
当前提交
26b2149ced

+ 18 - 18
rtl/amiga/sysutils.pp

@@ -234,24 +234,24 @@ begin
 end;
 
 
-function DeleteFile(const FileName: string) : Boolean;
+function DeleteFile(const FileName: RawByteString) : Boolean;
 var
-  tmpStr: array[0..255] of char;
+  SystemFileName: RawByteString;
 begin
-  tmpStr:=PathConv(FileName)+#0;
+  SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
 
-  DeleteFile:=dosDeleteFile(@tmpStr);
+  DeleteFile:=dosDeleteFile(PChar(SystemFileName));
 end;
 
 
 function RenameFile(const OldName, NewName: string): Boolean;
 var
-  tmpOldName, tmpNewName: array[0..255] of char;
+  OldSystemFileName, NewSystemFileName: RawByteString;
 begin
-  tmpOldName:=PathConv(OldName)+#0;
-  tmpNewName:=PathConv(NewName)+#0;
+  OldSystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(OldName));
+  NewSystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(NewName));
 
-  RenameFile:=dosRename(tmpOldName, tmpNewName);
+  RenameFile:=dosRename(PChar(OldSystemFileName), PChar(NewSystemFileName));
 end;
 
 
@@ -287,16 +287,15 @@ begin
 end;
 
 
-function FileExists (const FileName : String) : Boolean;
+function FileExists (const FileName : RawByteString) : Boolean;
 var
-  tmpName: String;
   tmpLock: LongInt;
   tmpFIB : PFileInfoBlock;
-
+  SystemFileName: RawByteString;
 begin
   result:=false;
-  tmpName := PathConv(FileName);
-  tmpLock := dosLock(tmpName, SHARED_LOCK);
+  SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
+  tmpLock := dosLock(PChar(SystemFileName), SHARED_LOCK);
 
   if (tmpLock <> 0) then begin
     new(tmpFIB);
@@ -388,7 +387,7 @@ end;
 
 (****** end of non portable routines ******)
 
-Function FileGetAttr (Const FileName : String) : Longint;
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
 var
  F: file;
  attr: word;
@@ -402,7 +401,7 @@ begin
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
 var
  F: file;
 begin
@@ -491,17 +490,18 @@ begin
 end;
 
 
-function DirectoryExists(const Directory: string): Boolean;
+function DirectoryExists(const Directory: RawBytetring): Boolean;
 var
   tmpStr : String;
   tmpLock: LongInt;
   FIB    : PFileInfoBlock;
+  SystemFileName: RawByteString;
 begin
   result:=false;
   if (Directory='') or (InOutRes<>0) then exit;
-  tmpStr:=PathConv(Directory);
+  SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
 
-  tmpLock:=dosLock(tmpStr,SHARED_LOCK);
+  tmpLock:=dosLock(PChar(SystemFileName),SHARED_LOCK);
   if tmpLock=0 then exit;
 
   FIB:=nil; new(FIB);

+ 6 - 6
rtl/embedded/sysutils.pp

@@ -107,13 +107,13 @@ begin
 end;
 
 
-function DeleteFile(const FileName: string) : Boolean;
+function DeleteFile(const FileName: RawByteString) : Boolean;
 begin
   result := false;
 end;
 
 
-function RenameFile(const OldName, NewName: string): Boolean;
+function RenameFile(const OldName, NewName: RawByteString): Boolean;
 begin
   result := false;
 end;
@@ -125,7 +125,7 @@ begin
 end;
 
 
-Function FileExists (Const FileName : String) : Boolean;
+Function FileExists (Const FileName : RawByteString) : Boolean;
 Begin
   result := false;
 end;
@@ -148,13 +148,13 @@ begin
 end;
 
 
-Function FileGetAttr (Const FileName : String) : Longint;
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
 begin
   result := -1;
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
 begin
   result := -1;
 end;
@@ -205,7 +205,7 @@ begin
 end;
 
 
-function DirectoryExists(const Directory: string): Boolean;
+function DirectoryExists(const Directory: RawByteString): Boolean;
 begin
   result := false;
 end;

+ 52 - 53
rtl/emx/sysutils.pp

@@ -654,10 +654,11 @@ begin
 end;
 
 
-function FileExists (const FileName: string): boolean;
+function FileExists (const FileName: RawByteString): boolean;
 var
   L: longint;
 begin
+  { no need to convert to DefaultFileSystemEncoding, FileGetAttr will do that }
   if FileName = '' then
    Result := false
   else
@@ -895,59 +896,56 @@ asm
 end {['eax', 'edx']};
 
 
-function FileSetAttr (const Filename: string; Attr: longint): longint; assembler;
-asm
-{$IFDEF REGCALL}
- mov ecx, edx
- mov edx, eax
-{$ELSE REGCALL}
- mov ecx, Attr
- mov edx, FileName
-{$ENDIF REGCALL}
- mov ax, 4301h
- call syscall
- mov eax, 0
- jnc @FSetAttrEnd
- mov eax, -1
-@FSetAttrEnd:
-end {['eax', 'ecx', 'edx']};
-
-
-function DeleteFile (const FileName: string): boolean; assembler;
-asm
-{$IFDEF REGCALL}
- mov edx, eax
-{$ELSE REGCALL}
- mov edx, FileName
-{$ENDIF REGCALL}
- mov ax, 4100h
- call syscall
- mov eax, 0
- jc @FDeleteEnd
- inc eax
-@FDeleteEnd:
-end {['eax', 'edx']};
-
+function FileSetAttr (const Filename: RawByteString; Attr: longint): longint;
+var
+  SystemFileName: RawByteString;
+begin
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Filename);
+  asm
+   mov ecx, Attr
+   mov edx, SystemFileName
+   mov ax, 4301h
+   call syscall
+   mov @result, 0
+   jnc @FSetAttrEnd
+   mov @result, -1
+  @FSetAttrEnd:
+  end ['eax', 'ecx', 'edx'];
+end;
 
-function RenameFile (const OldName, NewName: string): boolean; assembler;
-asm
- push edi
-{$IFDEF REGCALL}
- mov edx, eax
- mov edi, edx
-{$ELSE REGCALL}
- mov edx, OldName
- mov edi, NewName
-{$ENDIF REGCALL}
- mov ax, 5600h
- call syscall
- mov eax, 0
- jc @FRenameEnd
- inc eax
-@FRenameEnd:
- pop edi
-end {['eax', 'edx', 'edi']};
+function DeleteFile (const FileName: string): boolean;
+var
+  SystemFileName: RawByteString;
+begin
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Filename);
+  asm
+   mov edx, SystemFileName
+   mov ax, 4100h
+   call syscall
+   mov @result, 0
+   jc @FDeleteEnd
+   moc @result, 1
+  @FDeleteEnd:
+  end ['eax', 'edx'];
+end;
 
+function RenameFile (const OldName, NewName: string): boolean;
+var
+  OldSystemFileName, NewSystemFileName: RawByteString;
+Begin
+  OldSystemFileName:=ToSingleByteFileSystemEncodedFileName(OldName);
+  NewSystemFileName:=ToSingleByteFileSystemEncodedFileName(NewName);
+  asm
+   mov edx, OldSystemFileName
+   mov edi, NewSystemFileName
+   mov ax, 5600h
+   call syscall
+   mov @result, 0
+   jc @FRenameEnd
+   mov @result, 1
+  @FRenameEnd:
+  end ['eax', 'edx', 'edi'];
+end;
 
 {****************************************************************************
                               Disk Functions
@@ -1072,10 +1070,11 @@ begin
 end;
 
 
-function DirectoryExists (const Directory: string): boolean;
+function DirectoryExists (const Directory: RawByteString): boolean;
 var
   L: longint;
 begin
+  { no need to convert to DefaultFileSystemEncoding, FileGetAttr will do that }
   if Directory = '' then
    Result := false
   else

+ 6 - 6
rtl/gba/sysutils.pp

@@ -121,13 +121,13 @@ begin
 end;
 
 
-function DeleteFile(const FileName: string) : Boolean;
+function DeleteFile(const FileName: RawByteString) : Boolean;
 begin
   result := false;
 end;
 
 
-function RenameFile(const OldName, NewName: string): Boolean;
+function RenameFile(const OldName, NewName: RawByteString): Boolean;
 begin
   result := false;
 end;
@@ -142,7 +142,7 @@ begin
 end;
 
 
-Function FileExists (Const FileName : String) : Boolean;
+Function FileExists (Const FileName : RawByteString) : Boolean;
 Begin
   result := false;
 end;
@@ -164,13 +164,13 @@ Procedure FindClose (Var F : TSearchrec);
 begin
 end;
 
-Function FileGetAttr (Const FileName : String) : Longint;
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
 begin
   result := -1;
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
 begin
   result := -1;
 end;
@@ -224,7 +224,7 @@ begin
 end;
 
 
-function DirectoryExists(const Directory: string): Boolean;
+function DirectoryExists(const Directory: RawByteString): Boolean;
 begin
   result := false;
 end;

+ 24 - 13
rtl/go32v2/sysutils.pp

@@ -293,7 +293,7 @@ begin
 end;
 
 
-function FileExists (const FileName: string): boolean;
+function FileExists (const FileName: RawByteString): boolean;
 var
   L: longint;
 begin
@@ -301,6 +301,7 @@ begin
    Result := false
   else
    begin
+    { no need to convert to DefaultFileSystemEncoding, FileGetAttr will do that }
     L := FileGetAttr (FileName);
     Result := (L >= 0) and (L and (faDirectory or faVolumeID) = 0);
 (* Neither VolumeIDs nor directories are files. *)
@@ -308,12 +309,13 @@ begin
 end;
 
 
-Function DirectoryExists (Const Directory : String) : Boolean;
+Function DirectoryExists (Const Directory : RawByteString) : Boolean;
 Var
-  Dir : String;
+  Dir : RawByteString;
   drive : byte;
   FADir, StoredIORes : longint;
 begin
+  { no need to convert to DefaultFileSystemEncoding, FileGetAttr will do that }
   Dir:=Directory;
   if (length(dir)=2) and (dir[2]=':') and
      ((dir[1] in ['A'..'Z']) or (dir[1] in ['a'..'z'])) then
@@ -441,11 +443,13 @@ begin
 end;
 
 
-Function FileGetAttr (Const FileName : String) : Longint;
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
 var
   Regs: registers;
+  SystemFileName: RawByteString;
 begin
-  StringToTB(FileName);
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Filename);
+  StringToTB(SystemFileName);
   Regs.Edx := tb_offset;
   Regs.Ds := tb_segment;
   if LFNSupport then
@@ -463,11 +467,13 @@ begin
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
 var
   Regs: registers;
+  SystemFileName: RawByteString;
 begin
-  StringToTB(FileName);
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Filename);
+  StringToTB(SystemFileName);
   Regs.Edx := tb_offset;
   Regs.Ds := tb_segment;
   if LFNSupport then
@@ -486,11 +492,13 @@ begin
 end;
 
 
-Function DeleteFile (Const FileName : String) : Boolean;
+Function DeleteFile (Const FileName : RawByteString) : Boolean;
 var
   Regs: registers;
+  SystemFileName: RawByteString;
 begin
-  StringToTB(FileName);
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Filename);
+  StringToTB(SystemFileName);
   Regs.Edx := tb_offset;
   Regs.Ds := tb_segment;
   if LFNSupport then
@@ -504,14 +512,17 @@ begin
 end;
 
 
-Function RenameFile (Const OldName, NewName : String) : Boolean;
+Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
 var
   Regs: registers;
-begin
-  StringToTB(OldName + #0 + NewName);
+  OldSystemFileName, NewSystemFileName: RawByteString;
+Begin
+  OldSystemFileName:=ToSingleByteFileSystemEncodedFileName(OldName);
+  NewSystemFileName:=ToSingleByteFileSystemEncodedFileName(NewName);
+  StringToTB(OldSystemFileName + #0 + NewSystemFileName);
   Regs.Edx := tb_offset;
   Regs.Ds := tb_segment;
-  Regs.Edi := tb_offset + Length(OldName) + 1;
+  Regs.Edi := tb_offset + Length(OldSystemFileName) + 1;
   Regs.Es := tb_segment;
   if LFNSupport then
     Regs.Eax := $7156

+ 6 - 6
rtl/macos/sysutils.pp

@@ -203,7 +203,7 @@ begin
 end;
 
 
-Function FileExists (Const FileName : String) : Boolean;
+Function FileExists (Const FileName : RawByteString) : Boolean;
 
   (*
 Var Info : Stat;
@@ -216,7 +216,7 @@ begin
 end;
 
 
-Function DirectoryExists (Const Directory : String) : Boolean;
+Function DirectoryExists (Const Directory : RawByteString) : Boolean;
 
   (*
 Var Info : Stat;
@@ -450,7 +450,7 @@ begin
 end;
 
 
-Function FileGetAttr (Const FileName : String) : Longint;
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
 
   (*
 Var Info : Stat;
@@ -466,14 +466,14 @@ begin
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
 
 begin
   Result:=-1;
 end;
 
 
-Function DeleteFile (Const FileName : String) : Boolean;
+Function DeleteFile (Const FileName : RawByteString) : Boolean;
 
 begin
   (* TODO fix
@@ -482,7 +482,7 @@ begin
 end;
 
 
-Function RenameFile (Const OldName, NewName : String) : Boolean;
+Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
 
 begin
   (* TODO fix

+ 23 - 26
rtl/morphos/sysutils.pp

@@ -188,15 +188,15 @@ begin
 end;
 
 
-function FileSetDate(const FileName: string; Age: LongInt) : LongInt;
+function FileSetDate(const FileName: RawByteString; Age: LongInt) : LongInt;
 var
   tmpDateStamp: TDateStamp;
-  tmpName: array[0..255] of char;
+  SystemFileName: RawByteString;
 begin
   result:=0;
-  tmpName:=PathConv(FileName)+#0;
+  SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
   tmpDateStamp:=DateTimeToAmigaDateStamp(FileDateToDateTime(Age));
-  if not SetFileDate(@tmpName,@tmpDateStamp) then begin
+  if not SetFileDate(PChar(SystemFileName),@tmpDateStamp) then begin
     IoErr(); // dump the error code for now (TODO)
     result:=-1;
   end;
@@ -308,24 +308,22 @@ begin
 end;
 
 
-function DeleteFile(const FileName: string) : Boolean;
+function DeleteFile(const FileName: RawByteString) : Boolean;
 var
-  tmpStr: array[0..255] of char;
+  SystemFileName: RawByteString;
 begin
-  tmpStr:=PathConv(FileName)+#0;
-
-  DeleteFile:=dosDeleteFile(@tmpStr);
+  SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
+  DeleteFile:=dosDeleteFile(PChar(SystemFileName));
 end;
 
 
-function RenameFile(const OldName, NewName: string): Boolean;
+function RenameFile(const OldName, NewName: RawByteString): Boolean;
 var
-  tmpOldName, tmpNewName: array[0..255] of char;
+  OldSystemFileName, NewSystemFileName: RawByteString;
 begin
-  tmpOldName:=PathConv(OldName)+#0;
-  tmpNewName:=PathConv(NewName)+#0;
-
-  RenameFile:=dosRename(tmpOldName, tmpNewName);
+  OldSystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(OldName));
+  NewSystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(NewName));
+  RenameFile:=dosRename(PChar(OldSystemFileName), PChar(NewSystemFileName));
 end;
 
 
@@ -361,16 +359,15 @@ begin
 end;
 
 
-function FileExists (const FileName : String) : Boolean;
+function FileExists (const FileName : RawByteString) : Boolean;
 var
-  tmpName: String;
   tmpLock: LongInt;
   tmpFIB : PFileInfoBlock;
-
+  SystemFileName: RawByteString;
 begin
   result:=false;
-  tmpName := PathConv(FileName);
-  tmpLock := dosLock(tmpName, SHARED_LOCK);
+  SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
+  tmpLock := dosLock(PChar(SystemFileName), SHARED_LOCK);
 
   if (tmpLock <> 0) then begin
     new(tmpFIB);
@@ -462,7 +459,7 @@ end;
 
 (****** end of non portable routines ******)
 
-Function FileGetAttr (Const FileName : String) : Longint;
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
 var
  F: file;
  attr: word;
@@ -476,7 +473,7 @@ begin
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
 var
  F: file;
 begin
@@ -565,17 +562,17 @@ begin
 end;
 
 
-function DirectoryExists(const Directory: string): Boolean;
+function DirectoryExists(const Directory: RawByteString): Boolean;
 var
-  tmpStr : String;
   tmpLock: LongInt;
   FIB    : PFileInfoBlock;
+  SystemFileName: RawByteString;
 begin
   result:=false;
   if (Directory='') or (InOutRes<>0) then exit;
-  tmpStr:=PathConv(Directory);
+  SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(Directory));
 
-  tmpLock:=dosLock(tmpStr,SHARED_LOCK);
+  tmpLock:=dosLock(PChar(SystemFileName),SHARED_LOCK);
   if tmpLock=0 then exit;
 
   FIB:=nil; new(FIB);

+ 7 - 7
rtl/msdos/sysutils.pp

@@ -287,7 +287,7 @@ begin
 end;
 
 
-function FileExists (const FileName: string): boolean;
+function FileExists (const FileName: RawByteString): boolean;
 var
   L: longint;
 begin
@@ -302,9 +302,9 @@ begin
 end;
 
 
-Function DirectoryExists (Const Directory : String) : Boolean;
+Function DirectoryExists (Const Directory : RawByteString) : Boolean;
 Var
-  Dir : String;
+  Dir : RawByteString;
   drive : byte;
   FADir, StoredIORes : longint;
 begin
@@ -435,7 +435,7 @@ begin
 end;
 
 
-Function FileGetAttr (Const FileName : String) : Longint;
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
 var
   Regs: registers;
 begin
@@ -456,7 +456,7 @@ begin
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
 var
   Regs: registers;
 begin
@@ -478,7 +478,7 @@ begin
 end;
 
 
-Function DeleteFile (Const FileName : String) : Boolean;
+Function DeleteFile (Const FileName : RawByteString) : Boolean;
 var
   Regs: registers;
 begin
@@ -495,7 +495,7 @@ begin
 end;
 
 
-Function RenameFile (Const OldName, NewName : String) : Boolean;
+Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
 var
   Regs: registers;
 begin

+ 13 - 13
rtl/nativent/sysutils.pp

@@ -315,7 +315,7 @@ begin
 end;
 
 
-function FileExists(const FileName: String): Boolean;
+function FileExists(const FileName: UnicodeString): Boolean;
 var
   ntstr: UNICODE_STRING;
   objattr: OBJECT_ATTRIBUTES;
@@ -323,7 +323,7 @@ var
   iostatus: IO_STATUS_BLOCK;
   h: THandle;
 begin
-  AnsiStrToNtStr(FileName, ntstr);
+  UnicodeStrToNtStr(FileName, ntstr);
   InitializeObjectAttributes(objattr, @ntstr, 0, 0, Nil);
   res := NtOpenFile(@h, FILE_READ_ATTRIBUTES or NT_SYNCHRONIZE, @objattr,
            @iostatus, FILE_SHARE_READ or FILE_SHARE_WRITE,
@@ -336,7 +336,7 @@ begin
 end;
 
 
-function DirectoryExists(const Directory : String) : Boolean;
+function DirectoryExists(const Directory : UnicodeString) : Boolean;
 var
   ntstr: UNICODE_STRING;
   objattr: OBJECT_ATTRIBUTES;
@@ -344,7 +344,7 @@ var
   iostatus: IO_STATUS_BLOCK;
   h: THandle;
 begin
-  AnsiStrToNtStr(Directory, ntstr);
+  UnicodeStrToNtStr(Directory, ntstr);
   InitializeObjectAttributes(objattr, @ntstr, 0, 0, Nil);
 
   { first test wether this is a object directory }
@@ -782,14 +782,14 @@ begin
 end;
 
 
-function FileGetAttr(const FileName: String): Longint;
+function FileGetAttr(const FileName: UnicodeString): Longint;
 var
   objattr: OBJECT_ATTRIBUTES;
   info: FILE_NETWORK_OPEN_INFORMATION;
   res: NTSTATUS;
   ntstr: UNICODE_STRING;
 begin
-  AnsiStrToNtStr(FileName, ntstr);
+  UnicodeStrToNtStr(FileName, ntstr);
   InitializeObjectAttributes(objattr, @ntstr, 0, 0, Nil);
 
   res := NtQueryFullAttributesFile(@objattr, @info);
@@ -802,7 +802,7 @@ begin
 end;
 
 
-function FileSetAttr(const Filename: String; Attr: LongInt): Longint;
+function FileSetAttr(const Filename: UnicodeString; Attr: LongInt): Longint;
 var
   h: THandle;
   objattr: OBJECT_ATTRIBUTES;
@@ -811,7 +811,7 @@ var
   res: NTSTATUS;
   iostatus: IO_STATUS_BLOCK;
 begin
-  AnsiStrToNtStr(Filename, ntstr);
+  UnicodeStrToNtStr(Filename, ntstr);
   InitializeObjectAttributes(objattr, @ntstr, 0, 0, Nil);
   res := NtOpenFile(@h,
            NT_SYNCHRONIZE or FILE_READ_ATTRIBUTES or FILE_WRITE_ATTRIBUTES,
@@ -837,7 +837,7 @@ begin
 end;
 
 
-function DeleteFile(const FileName: String): Boolean;
+function DeleteFile(const FileName: UnicodeString): Boolean;
 var
   h: THandle;
   objattr: OBJECT_ATTRIBUTES;
@@ -846,7 +846,7 @@ var
   res: NTSTATUS;
   iostatus: IO_STATUS_BLOCK;
 begin
-  AnsiStrToNtStr(Filename, ntstr);
+  UnicodeStrToNtStr(Filename, ntstr);
   InitializeObjectAttributes(objattr, @ntstr, 0, 0, Nil);
   res := NtOpenFile(@h, NT_DELETE, @objattr, @iostatus,
            FILE_SHARE_READ or FILE_SHARE_WRITE or FILE_SHARE_DELETE,
@@ -868,7 +868,7 @@ begin
 end;
 
 
-function RenameFile(const OldName, NewName: String): Boolean;
+function RenameFile(const OldName, NewName: UnicodeString): Boolean;
 var
   h: THandle;
   objattr: OBJECT_ATTRIBUTES;
@@ -878,7 +878,7 @@ var
   res: LongInt;
 begin
   { check whether the destination exists first }
-  AnsiStrToNtStr(NewName, dest);
+  UnicodeStrToNtStr(NewName, dest);
   InitializeObjectAttributes(objattr, @dest, 0, 0, Nil);
 
   res := NtCreateFile(@h, 0, @objattr, @iostatus, Nil, 0,
@@ -889,7 +889,7 @@ begin
     NtClose(h);
     Result := False;
   end else begin
-    AnsiStrToNtStr(OldName, src);
+    UnicodeStrToNtStr(OldName, src);
     InitializeObjectAttributes(objattr, @src, 0, 0, Nil);
 
     res := NtCreateFile(@h,

+ 24 - 11
rtl/nds/sysutils.pp

@@ -138,15 +138,22 @@ begin
 end;
 
 
-function DeleteFile(const FileName: string) : Boolean;
+function DeleteFile(const FileName: RawByteString) : Boolean;
+var
+  SystemFileName: RawByteString;
 begin
-  Result := _UnLink(pointer(FileName))>= 0;
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  Result := _UnLink(pointer(SystemFileName))>= 0;
 end;
 
 
-function RenameFile(const OldName, NewName: string): Boolean;
+function RenameFile(const OldName, NewName: RawByteString): Boolean;
+var
+  OldSystemFileName, NewSystemFileName: RawByteString;
 begin
-  RenameFile := _Rename(pointer(OldNAme), pointer(NewName)) >= 0;
+  OldSystemFileName:=ToSingleByteFileSystemEncodedFileName(OldName);
+  NewSystemFileName:=ToSingleByteFileSystemEncodedFileName(NewName);
+  RenameFile := _Rename(pointer(OldSystemFileName), pointer(NewSystemFileName)) >= 0;
 end;
 
 
@@ -164,9 +171,12 @@ begin
 end;
 
 
-Function FileExists (Const FileName : String) : Boolean;
+Function FileExists (Const FileName : RawByteString) : Boolean;
+var
+  SystemFileName: RawByteString;
 begin
-  FileExists := _Access(pointer(filename), F_OK) = 0;
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  FileExists := _Access(pointer(SystemFileName), F_OK) = 0;
 end;
 
 
@@ -187,17 +197,20 @@ begin
 
 end;
 
-Function FileGetAttr (Const FileName : String) : Longint;
-Var Info : TStat;
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
+var
+  Info : TStat;
+  SystemFileName: RawByteString;
 begin
-  If _stat(pchar(FileName), Info) <> 0 then
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  If _stat(pchar(SystemFileName), Info) <> 0 then
     Result := -1
   Else
     Result := (Info.st_mode shr 16) and $ffff;
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
 begin
   result := -1;
 end;
@@ -251,7 +264,7 @@ begin
 end;
 
 
-function DirectoryExists(const Directory: string): Boolean;
+function DirectoryExists(const Directory: RawByteString): Boolean;
 begin
   result := false;
 end;

+ 29 - 14
rtl/netware/sysutils.pp

@@ -211,10 +211,12 @@ begin
 end;
 
 
-Function FileExists (Const FileName : String) : Boolean;
+Function FileExists (Const FileName : RawByteString) : Boolean;
 VAR Info : NWStatBufT;
+    SystemFileName: RawByteString;
 begin
-  FileExists:=(_stat(pchar(filename),Info) = 0);
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  FileExists:=(_stat(pchar(SystemFileName),Info) = 0);
 end;
 
 
@@ -319,38 +321,48 @@ begin
 end;
 
 
-Function FileGetAttr (Const FileName : String) : Longint;
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
 Var Info : NWStatBufT;
+    SystemFileName: RawByteString;
 begin
-  If _stat (pchar(FileName),Info) <> 0 then
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  If _stat (pchar(SystemFileName),Info) <> 0 then
     Result:=-1
   Else
     Result := Info.st_attr AND $FFFF;
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
 VAR MS : NWModifyStructure;
+    SystemFileName: RawByteString;
 begin
+  { The Attr parameter is not used! }
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
   FillChar (MS, SIZEOF (MS), 0);
-  if _ChangeDirectoryEntry (PChar (Filename), MS, MFileAtrributesBit, 0) <> 0 then
+  if _ChangeDirectoryEntry (PChar (SystemFilename), MS, MFileAtrributesBit, 0) <> 0 then
     result := -1
   else
     result := 0;
 end;
 
 
-Function DeleteFile (Const FileName : String) : Boolean;
-
+Function DeleteFile (Const FileName : RawByteString) : Boolean;
+var
+  SystemFileName: RawByteString;
 begin
-  Result:= (_UnLink (pchar(FileName)) = 0);
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  Result:= (_UnLink (pchar(SystemFileName)) = 0);
 end;
 
 
-Function RenameFile (Const OldName, NewName : String) : Boolean;
-
+Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
+var
+  OldSystemFileName, NewSystemFileName: RawByteString;
 begin
-  RenameFile:=(_rename(pchar(OldName),pchar(NewName)) = 0);
+  OldSystemFileName:=ToSingleByteFileSystemEncodedFileName(OldName);
+  NewSystemFileName:=ToSingleByteFileSystemEncodedFileName(NewName);
+  RenameFile:=(_rename(pchar(OldSystemFileName),pchar(NewSystemFileName)) = 0);
 end;
 
 
@@ -456,9 +468,12 @@ end;
 
 
 function DirectoryExists (const Directory: string): boolean;
-VAR Info : NWStatBufT;
+var
+  Info : NWStatBufT;
+  SystemFileName: RawByteString;
 begin
-  If _stat (pchar(Directory),Info) <> 0 then
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Directory);
+  If _stat (pchar(SystemFileName),Info) <> 0 then
     exit(false)
   else
     Exit ((Info.st_attr and faDirectory) <> 0);

+ 29 - 15
rtl/netwlibc/sysutils.pp

@@ -209,10 +209,12 @@ begin
 end;
 
 
-Function FileExists (Const FileName : String) : Boolean;
+Function FileExists (Const FileName : RawByteString) : Boolean;
 VAR Info : TStat;
+    SystemFileName: RawByteString;
 begin
-  FileExists:=(Fpstat(pchar(filename),Info) = 0);
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  FileExists:=(Fpstat(pchar(SystemFileName),Info) = 0);
 end;
 
 
@@ -359,22 +361,26 @@ Begin
 end;
 
 
-Function FileGetAttr (Const FileName : String) : Longint;
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
 Var Info : TStat;
+    SystemFileName: RawByteString;
 begin
-  If Fpstat (pchar(FileName),Info) <> 0 then
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  If Fpstat (pchar(SystemFileName),Info) <> 0 then
     Result:=-1
   Else
     Result := (Info.st_mode shr 16) and $ffff;
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
 var
   StatBuf : TStat;
   newMode : longint;
+  SystemFileName: RawByteString;
 begin
-  if Fpstat (pchar(Filename),StatBuf) = 0 then
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  if Fpstat (pchar(SystemFilename),StatBuf) = 0 then
   begin
     {what should i do here ?
      only support sysutils-standard attributes or also support the extensions defined
@@ -390,7 +396,7 @@ begin
       newmode := StatBuf.st_mode and ($ffff0000-M_A_RDONLY-M_A_HIDDEN- M_A_SYSTEM-M_A_SUBDIR-M_A_ARCH);
       newmode := newmode or (attr shl 16) or M_A_BITS_SIGNIFICANT;
     end;
-    if Fpchmod (pchar(Filename),newMode) < 0 then
+    if Fpchmod (pchar(SystemFilename),newMode) < 0 then
       result := ___errno^ else
       result := 0;
   end else
@@ -398,17 +404,22 @@ begin
 end;
 
 
-Function DeleteFile (Const FileName : String) : Boolean;
-
+Function DeleteFile (Const FileName : RawByteString) : Boolean;
+var
+  SystemFileName: RawByteString;
 begin
-  Result:= (libc.UnLink (pchar(FileName)) = 0);
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  Result:= (libc.UnLink (pchar(SystemFileName)) = 0);
 end;
 
 
 Function RenameFile (Const OldName, NewName : String) : Boolean;
-
+var
+  OldSystemFileName, NewSystemFileName: RawByteString;
 begin
-  RenameFile:=(libc.rename(pchar(OldName),pchar(NewName)) = 0);
+  OldSystemFileName:=ToSingleByteFileSystemEncodedFileName(OldName);
+  NewSystemFileName:=ToSingleByteFileSystemEncodedFileName(NewName);
+  RenameFile:=(libc.rename(pchar(OldSystemFileName),pchar(NewSystemFileName)) = 0);
 end;
 
 
@@ -507,10 +518,13 @@ begin
 end;
 
 
-function DirectoryExists (const Directory: string): boolean;
-var Info : TStat;
+function DirectoryExists (const Directory: RawByteString): boolean;
+var
+  Info : TStat;
+  SystemFileName: RawByteString;
 begin
-  If Fpstat (pchar(Directory),Info) <> 0 then
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Directory);
+  If Fpstat (pchar(SystemFileName),Info) <> 0 then
     exit(false)
   else
     Exit ((Info.st_mode and M_A_SUBDIR) <> 0);

+ 271 - 0
rtl/objpas/sysutils/filutil.inc

@@ -38,9 +38,148 @@ Function FileCreate (Const FileName : UnicodeString; ShareMode : Integer; Rights
 begin
   Result:=FileCreate(ToSingleByteFileSystemEncodedFileName(FileName),ShareMode,Rights);
 end;
+
+
+Function FileExists (Const FileName : UnicodeString) : Boolean;
+begin
+  Result:=FileExists(ToSingleByteFileSystemEncodedFileName(FileName));
+end;
+
+
+Function DirectoryExists (Const Directory : UnicodeString) : Boolean;
+begin
+  Result:=DirectoryExists(ToSingleByteFileSystemEncodedFileName(Directory));
+end;
+
+
+Function FileGetAttr (Const FileName : UnicodeString) : Longint;
+begin
+  Result:=FileGetAttr(ToSingleByteFileSystemEncodedFileName(FileName));
+end;
+
+
+Function FileSetAttr (Const Filename : UnicodeString; Attr: longint) : Longint;
+begin
+  Result:=FileSetAttr(ToSingleByteFileSystemEncodedFileName(FileName),Attr);
+end;
+
+
+Function DeleteFile (Const FileName : UnicodeString) : Boolean;
+begin
+  Result:=DeleteFile(ToSingleByteFileSystemEncodedFileName(FileName));
+end;
+
+
+Function RenameFile (Const OldName, NewName : UnicodeString) : Boolean;
+
+begin
+  Result:=RenameFile(ToSingleByteFileSystemEncodedFileName(OldName),
+                     ToSingleByteFileSystemEncodedFileName(NewName));
+end;
+
+{$ifdef OS_FILEISREADONLY}
+Function FileIsReadOnly(const FileName: UnicodeString): Boolean;
+begin
+  Result:=FileIsReadOnly(ToSingleByteFileSystemEncodedFileName(FileName));
+end;
+{$endif}
+
+
+{$ifdef OS_FILESETDATEBYNAME}
+Function FileSetDate (Const FileName : UnicodeString;Age : Longint) : Longint;
+begin
+  Result:=FileSetDate(ToSingleByteFileSystemEncodedFileName(FileName),Age);
+end;
 {$endif}
 
 
+Function FileSearch (Const Name, DirList : UnicodeString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : UnicodeString;
+begin
+  Result:=UnicodeString(FileSearch(ToSingleByteFileSystemEncodedFileName(Name),
+                                   ToSingleByteFileSystemEncodedFileName(Dirlist),Options));
+end;
+
+
+Function FileSearch (Const Name, DirList : UnicodeString; ImplicitCurrentDir : Boolean) : UnicodeString;
+begin
+  Result:=UnicodeString(FileSearch(ToSingleByteFileSystemEncodedFileName(Name),
+                                   ToSingleByteFileSystemEncodedFileName(DirList),ImplicitCurrentDir));
+end;
+
+
+Function ExeSearch (Const Name : UnicodeString; Const DirList : UnicodeString ='' ) : UnicodeString;
+begin
+  Result:=UnicodeString(ExeSearch(ToSingleByteFileSystemEncodedFileName(Name),
+                                  ToSingleByteFileSystemEncodedFileName(Dirlist)));
+end;
+
+
+
+Function FileSearch (Const Name, DirList : RawByteString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : RawByteString;
+Var
+  I : longint;
+  Temp : RawByteString;
+begin
+  Result:=Name;
+  temp:=SetDirSeparators(DirList);
+  // Start with checking the file in the current directory
+  If (sfoImplicitCurrentDir in Options) and (Result <> '') and FileExists(Result) Then
+    exit;
+  while True do begin
+    If Temp = '' then
+      Break; // No more directories to search - fail
+    I:=pos(PathSeparator,Temp);
+    If I<>0 then
+      begin
+        Result:=Copy (Temp,1,i-1);
+        system.Delete(Temp,1,I);
+      end
+    else
+      begin
+        Result:=Temp;
+        Temp:='';
+      end;
+    If Result<>'' then
+      begin
+      If (sfoStripQuotes in Options) and (Result[1]='"') and (Result[Length(Result)]='"') then
+        Result:=Copy(Result,2,Length(Result)-2);
+      if (Result<>'') then
+        Result:=IncludeTrailingPathDelimiter(Result)+name;
+      end;
+    If (Result <> '') and FileExists(Result) Then
+      exit;
+  end;
+  Result:='';
+end;
+
+
+Function FileSearch (Const Name, DirList : RawByteString; ImplicitCurrentDir : Boolean) : RawByteString;
+begin
+  if ImplicitCurrentDir then
+    Result:=FileSearch(Name,DirList,[sfoImplicitCurrentDir])
+  else
+    Result:=FileSearch(Name,DirList,[]);
+end;
+
+
+Function ExeSearch (Const Name : RawByteString; Const DirList : RawByteString ='' ) : RawByteString;
+Var
+  D : RawByteString;
+  O : TFileSearchOptions;
+begin
+  D:=DirList;
+  if (D='') then
+    D:=GetEnvironmentVariable('PATH');
+{$ifdef unix}
+  O:=[];
+{$else unix}
+  O:=[sfoImplicitCurrentDir,sfoStripQuotes];
+{$endif unix}
+  Result := FileSearch(Name, D, O);
+end;
+
+{$endif}
+
 {$ifndef SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
 Function FileOpen (Const FileName : rawbytestring; Mode : Integer) : THandle;
 begin
@@ -64,6 +203,138 @@ Function FileCreate (Const FileName : RawByteString; ShareMode : Integer; Rights
 begin
   Result:=FileCreate(UnicodeString(FileName),ShareMode,Rights);
 end;
+
+
+Function FileExists (Const FileName : RawByteString) : Boolean;
+begin
+  Result:=FileExists(UnicodeString(FileName));
+end;
+
+
+Function DirectoryExists (Const Directory : RawByteString) : Boolean;
+begin
+  Result:=DirectoryExists(UnicodeString(Directory));
+end;
+
+
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
+begin
+  Result:=FileGetAttr(unicodestring(FileName));
+end;
+
+
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
+begin
+  Result:=FileSetAttr(unicodestring(FileName),Attr);
+end;
+
+
+Function DeleteFile (Const FileName : RawByteString) : Boolean;
+begin
+  Result:=DeleteFile(UnicodeString(FileName));
+end;
+
+
+Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
+begin
+  Result:=RenameFile(UnicodeString(OldName),UnicodeString(NewName));
+end;
+
+{$ifdef OS_FILEISREADONLY}
+Function FileIsReadOnly(const FileName: RawByteString): Boolean;
+begin
+  Result:=FileIsReadOnly(UnicodeString(FileName));
+end;
+{$endif}
+
+{$ifdef OS_FILESETDATEBYNAME}
+Function FileSetDate (Const FileName : RawByteString;Age : Longint) : Longint;
+begin
+  Result:=FileSetDate(UnicodeString(FileName),Age);
+end;
+{$endif}
+
+
+Function FileSearch (Const Name, DirList : UnicodeString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : UnicodeString;
+Var
+  I : longint;
+  Temp : UnicodeString;
+begin
+  Result:=Name;
+  temp:=SetDirSeparators(DirList);
+  // Start with checking the file in the current directory
+  If (sfoImplicitCurrentDir in Options) and (Result <> '') and FileExists(Result) Then
+    exit;
+  while True do begin
+    If Temp = '' then
+      Break; // No more directories to search - fail
+    I:=pos(PathSeparator,Temp);
+    If I<>0 then
+      begin
+        Result:=Copy (Temp,1,i-1);
+        system.Delete(Temp,1,I);
+      end
+    else
+      begin
+        Result:=Temp;
+        Temp:='';
+      end;
+    If Result<>'' then
+      begin
+      If (sfoStripQuotes in Options) and (Result[1]='"') and (Result[Length(Result)]='"') then
+        Result:=Copy(Result,2,Length(Result)-2);
+      if (Result<>'') then
+        Result:=IncludeTrailingPathDelimiter(Result)+name;
+      end;
+    If (Result <> '') and FileExists(Result) Then
+      exit;
+  end;
+  Result:='';
+end;
+
+
+Function FileSearch (Const Name, DirList : RawbyteString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : RawByteString;
+begin
+  Result:=ToSingleByteFileSystemEncodedFileName(FileSearch(unicodestring(name),unicodestring(dirlist),options));
+end;
+
+
+Function FileSearch (Const Name, DirList : RawbyteString; ImplicitCurrentDir : Boolean) : RawByteString;
+begin
+  Result:=ToSingleByteFileSystemEncodedFileName(FileSearch(unicodestring(name),unicodestring(dirlist),ImplicitCurrentDir));
+end;
+
+
+Function FileSearch (Const Name, DirList : UnicodeString; ImplicitCurrentDir : Boolean) : UnicodeString;
+begin
+  if ImplicitCurrentDir then
+    Result:=FileSearch(Name,DirList,[sfoImplicitCurrentDir])
+  else
+    Result:=FileSearch(Name,DirList,[]);
+end;
+
+
+Function ExeSearch (Const Name : UnicodeString; Const DirList : UnicodeString ='' ) : UnicodeString;
+Var
+  D : UnicodeString;
+  O : TFileSearchOptions;
+begin
+  D:=DirList;
+  if (D='') then
+    D:=GetEnvironmentVariable('PATH');
+{$ifdef unix}
+  O:=[];
+{$else unix}
+  O:=[sfoImplicitCurrentDir,sfoStripQuotes];
+{$endif unix}
+  Result := FileSearch(Name, D, O);
+end;
+
+
+Function ExeSearch (Const Name : RawbyteString; Const DirList : RawbyteString ='' ) : RawByteString;
+begin
+  Result:=ToSingleByteFileSystemEncodedFileName(ExeSearch(unicodestring(name),unicodestring(dirlist)));
+end;
 {$endif}
 
 

+ 21 - 13
rtl/objpas/sysutils/filutilh.inc

@@ -81,11 +81,32 @@ Function FileOpen (Const FileName : unicodestring; Mode : Integer) : THandle;
 Function FileCreate (Const FileName : UnicodeString) : THandle;
 Function FileCreate (Const FileName : UnicodeString; Rights : Integer) : THandle;
 Function FileCreate (Const FileName : UnicodeString; ShareMode : Integer; Rights : Integer) : THandle;
+Function FileExists (Const FileName : UnicodeString) : Boolean;
+Function DirectoryExists (Const Directory : UnicodeString) : Boolean;
+Function FileSetDate (Const FileName : UnicodeString;Age : Longint) : Longint;
+Function FileGetAttr (Const FileName : UnicodeString) : Longint;
+Function FileSetAttr (Const Filename : UnicodeString; Attr: longint) : Longint;
+Function DeleteFile (Const FileName : UnicodeString) : Boolean;
+Function RenameFile (Const OldName, NewName : UnicodeString) : Boolean;
+Function FileSearch (Const Name, DirList : UnicodeString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : UnicodeString;
+Function FileSearch (Const Name, DirList : UnicodeString; ImplicitCurrentDir : Boolean) : UnicodeString;
+Function ExeSearch  (Const Name : UnicodeString; Const DirList : UnicodeString = '') : UnicodeString;
+Function FileIsReadOnly(const FileName : UnicodeString): Boolean;
 
 Function FileOpen (Const FileName : RawByteString; Mode : Integer) : THandle;
 Function FileCreate (Const FileName : RawByteString) : THandle;
 Function FileCreate (Const FileName : RawByteString; Rights : Integer) : THandle;
 Function FileCreate (Const FileName : RawByteString; ShareMode : Integer; Rights : Integer) : THandle;
+Function FileExists (Const FileName : RawByteString) : Boolean;
+Function DirectoryExists (Const Directory : RawByteString) : Boolean;
+Function FileSetDate (Const FileName : RawByteString;Age : Longint) : Longint;
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
+Function DeleteFile (Const FileName : RawByteString) : Boolean;
+Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
+Function FileSearch (Const Name, DirList : RawByteString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : RawByteString;
+Function FileSearch (Const Name, DirList : RawByteString; ImplicitCurrentDir : Boolean) : RawByteString;
+Function ExeSearch  (Const Name : RawByteString; Const DirList : RawByteString = '') : RawByteString;
 
 Function FileRead (Handle : THandle; out Buffer; Count : longint) : Longint;
 Function FileWrite (Handle : THandle; const Buffer; Count : Longint) : Longint;
@@ -96,24 +117,11 @@ Function FileTruncate (Handle : THandle;Size: Int64) : boolean;
 {$ifndef FPUNONE}
 Function FileAge (Const FileName : String): Longint;
 {$endif}
-Function FileExists (Const FileName : String) : Boolean;
-Function DirectoryExists (Const Directory : String) : Boolean;
 Function FindFirst (Const Path : String; Attr : Longint; out Rslt : TSearchRec) : Longint;
 Function FindNext (Var Rslt : TSearchRec) : Longint;
 Procedure FindClose (Var F : TSearchrec);
 Function FileGetDate (Handle : THandle) : Longint;
 Function FileSetDate (Handle : THandle;Age : Longint) : Longint;
-Function FileSetDate (Const FileName : String;Age : Longint) : Longint;
-Function FileGetAttr (Const FileName : String) : Longint;
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
-Function DeleteFile (Const FileName : String) : Boolean;
-Function RenameFile (Const OldName, NewName : String) : Boolean;
-
-Function FileSearch (Const Name, DirList : String; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : String;
-Function FileSearch (Const Name, DirList : String; ImplicitCurrentDir : Boolean) : String;
-Function ExeSearch  (Const Name : String; Const DirList : String = '') : String;
-Function FileIsReadOnly(const FileName: String): Boolean;
-
 Function GetFileHandle(var f : File):THandle;
 Function GetFileHandle(var f : Text):THandle;
 function FileAge(const FileName: string; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;

+ 28 - 65
rtl/objpas/sysutils/sysutils.inc

@@ -34,73 +34,15 @@
   { variant error codes }
   {$i varerror.inc}
 
-    Function FileSearch (Const Name, DirList : String; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : String;
-    Var
-      I : longint;
-      Temp : String;
-
-    begin
-      Result:=Name;
-      temp:=SetDirSeparators(DirList);
-      // Start with checking the file in the current directory
-      If (sfoImplicitCurrentDir in Options) and (Result <> '') and FileExists(Result) Then
-        exit;
-      while True do begin
-        If Temp = '' then
-          Break; // No more directories to search - fail
-        I:=pos(PathSeparator,Temp);
-        If I<>0 then
-          begin
-            Result:=Copy (Temp,1,i-1);
-            system.Delete(Temp,1,I);
-          end
-        else
-          begin
-            Result:=Temp;
-            Temp:='';
-          end;
-        If Result<>'' then
-          begin
-          If (sfoStripQuotes in Options) and (Result[1]='"') and (Result[Length(Result)]='"') then
-            Result:=Copy(Result,2,Length(Result)-2);
-          if (Result<>'') then
-            Result:=IncludeTrailingPathDelimiter(Result)+name;
-          end;
-        If (Result <> '') and FileExists(Result) Then
-          exit;
-      end;
-      result:='';
-    end;
-
-    Function FileSearch (Const Name, DirList : String; ImplicitCurrentDir : Boolean) : String;
-
-    begin
-      if ImplicitCurrentDir then
-        Result:=FileSearch(Name,DirList,[sfoImplicitCurrentDir])
-      else  
-        Result:=FileSearch(Name,DirList,[]);
-    end;
-    
-    Function ExeSearch (Const Name : String; Const DirList : String ='' ) : String;
-    
-    Var
-      D : String;
-      O : TFileSearchOptions;
-    begin
-      D:=DirList;
-      if (D='') then
-        D:=GetEnvironmentVariable('PATH');
-    {$ifdef unix}
-      O:=[];
-    {$else unix}
-      O:=[sfoImplicitCurrentDir,sfoStripQuotes];
-    {$endif unix}
-      Result := FileSearch(Name, D, O);
-    end;
 
   {$ifndef OS_FILEISREADONLY}
-  Function FileIsReadOnly(const FileName: String): Boolean;
+  Function FileIsReadOnly(const FileName: RawByteString): Boolean;
+  begin
+    Result := (FileGetAttr(FileName) and faReadOnly) <> 0;
+  end;
 
+
+  Function FileIsReadOnly(const FileName: UnicodeString): Boolean;
   begin
     Result := (FileGetAttr(FileName) and faReadOnly) <> 0;
   end;
@@ -108,7 +50,28 @@
 
 
   {$ifndef OS_FILESETDATEBYNAME}
-  Function FileSetDate (Const FileName : String;Age : Longint) : Longint;
+  Function FileSetDate (Const FileName : RawByteString;Age : Longint) : Longint;
+  Var
+    fd : THandle;
+  begin
+    { at least windows requires fmOpenWrite here }
+    fd:=FileOpen(FileName,fmOpenWrite);
+    If (Fd<>feInvalidHandle) then
+      try
+        Result:=FileSetDate(fd,Age);
+      finally
+        FileClose(fd);
+      end
+    else
+  {$ifdef HAS_OSERROR}
+      Result:=GetLastOSError;
+  {$else}
+      Result:=-1;
+  {$endif}
+  end;
+
+
+  Function FileSetDate (Const FileName : UnicodeString;Age : Longint) : Longint;
   Var
     fd : THandle;
   begin

+ 25 - 12
rtl/os2/sysutils.pp

@@ -178,16 +178,17 @@ begin
 end;
 
 
-function FileExists (const FileName: string): boolean;
+function FileExists (const FileName: RawByteString): boolean;
 var
   L: longint;
 begin
+  { no need to convert to DefaultFileSystemEncoding, FileGetAttr will do that }
   if FileName = '' then
-   Result := false
+    Result := false
   else
    begin
-    L := FileGetAttr (FileName);
-    Result := (L >= 0) and (L and (faDirectory or faVolumeID) = 0);
+     L := FileGetAttr (FileName);
+     Result := (L >= 0) and (L and (faDirectory or faVolumeID) = 0);
 (* Neither VolumeIDs nor directories are files. *)
    end;
 end;
@@ -328,36 +329,47 @@ begin
   Dispose (FStat);
 end;
 
-function FileGetAttr (const FileName: string): longint;
+function FileGetAttr (const FileName: RawByteString): longint;
 var
   FS: PFileStatus3;
+  SystemFileName: RawByteString;
 begin
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Filename);
   New(FS);
-  Result:=-DosQueryPathInfo(PChar (FileName), ilStandard, FS, SizeOf(FS^));
+  Result:=-DosQueryPathInfo(PChar (SystemFileName), ilStandard, FS, SizeOf(FS^));
   If Result=0 Then Result:=FS^.attrFile;
   Dispose(FS);
 end;
 
-function FileSetAttr (const Filename: string; Attr: longint): longint;
+function FileSetAttr (const Filename: RawByteString; Attr: longint): longint;
 Var
   FS: PFileStatus3;
+  SystemFileName: RawByteString;
 Begin
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Filename);
   New(FS);
   FillChar(FS, SizeOf(FS^), 0);
   FS^.AttrFile:=Attr;
-  Result:=-DosSetPathInfo(PChar (FileName), ilStandard, FS, SizeOf(FS^), 0);
+  Result:=-DosSetPathInfo(PChar (SystemFileName), ilStandard, FS, SizeOf(FS^), 0);
   Dispose(FS);
 end;
 
 
-function DeleteFile (const FileName: string): boolean;
+function DeleteFile (const FileName: RawByteString): boolean;
+var
+  SystemFileName: RawByteString;
 Begin
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Filename);
   Result:=(DosDelete(PChar (FileName))=0);
 End;
 
-function RenameFile (const OldName, NewName: string): boolean;
+function RenameFile (const OldName, NewName: RawByteString): boolean;
+var
+  OldSystemFileName, NewSystemFileName: RawByteString;
 Begin
-  Result:=(DosMove(PChar (OldName), PChar (NewName))=0);
+  OldSystemFileName:=ToSingleByteFileSystemEncodedFileName(OldName);
+  NewSystemFileName:=ToSingleByteFileSystemEncodedFileName(NewName);
+  Result:=(DosMove(PChar (OldSystemFileName), PChar (NewSystemFileName))=0);
 End;
 
 {****************************************************************************
@@ -443,10 +455,11 @@ begin
 end;
 
 
-function DirectoryExists (const Directory: string): boolean;
+function DirectoryExists (const Directory: RawByteString): boolean;
 var
   L: longint;
 begin
+  { no need to convert to DefaultFileSystemEncoding, FileGetAttr will do that }
   if Directory = '' then
    Result := false
   else

+ 50 - 41
rtl/unix/sysutils.pp

@@ -558,29 +558,29 @@ begin
 end;
 
 
-Function FileExists (Const FileName : String) : Boolean;
-
+Function FileExists (Const FileName : RawByteString) : Boolean;
+var
+  SystemFileName: RawByteString;
 begin
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
   // Don't use stat. It fails on files >2 GB.
   // Access obeys the same access rules, so the result should be the same.
-  FileExists:=fpAccess(pointer(filename),F_OK)=0;
+  FileExists:=fpAccess(pointer(SystemFileName),F_OK)=0;
 end;
 
-
-Function DirectoryExists (Const Directory : String) : Boolean;
-
-Var Info : Stat;
-
+Function DirectoryExists (Const Directory : RawByteString) : Boolean;
+Var
+  Info : Stat;
+  SystemFileName: RawByteString;
 begin
-  DirectoryExists:=(fpstat(pointer(Directory),Info)>=0) and fpS_ISDIR(Info.st_mode);
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Directory);
+  DirectoryExists:=(fpstat(pointer(SystemFileName),Info)>=0) and fpS_ISDIR(Info.st_mode);
 end;
 
-
-Function LinuxToWinAttr (const FN : Ansistring; Const Info : Stat) : Longint;
-
+Function LinuxToWinAttr (const FN : RawByteString; Const Info : Stat) : Longint;
 Var
   LinkInfo : Stat;
-  nm : AnsiString;
+  nm : RawByteString;
 begin
   Result:=faArchive;
   If fpS_ISDIR(Info.st_mode) then
@@ -596,10 +596,10 @@ begin
      Result:=Result or faSysFile;
   If fpS_ISLNK(Info.st_mode) Then
     begin
-    Result:=Result or faSymLink;
-    // Windows reports if the link points to a directory.
-    if (fpstat(FN,LinkInfo)>=0) and fpS_ISDIR(LinkInfo.st_mode) then
-      Result := Result or faDirectory;
+      Result:=Result or faSymLink;
+      // Windows reports if the link points to a directory.
+      if (fpstat(pchar(FN),LinkInfo)>=0) and fpS_ISDIR(LinkInfo.st_mode) then
+        Result := Result or faDirectory;
     end;
 end;
 
@@ -857,58 +857,67 @@ begin
 end;
 
 
-Function FileGetAttr (Const FileName : String) : Longint;
-
-Var Info : Stat;
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
+Var
+  SystemFileName: RawByteString;
+  Info : Stat;
   res : Integer;
 begin
-  res:=FpLStat (pointer(FileName),Info);
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  res:=FpLStat(pointer(SystemFileName),Info);
   if res<0 then
-    res:=FpStat (pointer(FileName),Info);
+    res:=FpStat(pointer(SystemFileName),Info);
   if res<0 then
     Result:=-1
   Else
-    Result:=LinuxToWinAttr(Pchar(FileName),Info);
+    Result:=LinuxToWinAttr(SystemFileName,Info);
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
-
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
 begin
   Result:=-1;
 end;
 
 
-Function DeleteFile (Const FileName : String) : Boolean;
-
+Function DeleteFile (Const FileName : RawByteString) : Boolean;
+var
+  SystemFileName: RawByteString;
 begin
-  Result:=fpUnLink (pointer(FileName))>=0;
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  Result:=fpUnLink (pchar(SystemFileName))>=0;
 end;
 
 
-Function RenameFile (Const OldName, NewName : String) : Boolean;
-
+Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
+var
+  SystemOldName, SystemNewName: RawByteString;
 begin
-  RenameFile:=BaseUnix.FpRename(pointer(OldNAme),pointer(NewName))>=0;
+  SystemOldName:=ToSingleByteFileSystemEncodedFileName(OldName);
+  SystemNewName:=ToSingleByteFileSystemEncodedFileName(NewName);
+  RenameFile:=BaseUnix.FpRename(pointer(SystemOldNAme),pointer(SystemNewName))>=0;
 end;
 
-Function FileIsReadOnly(const FileName: String): Boolean;
 
+Function FileIsReadOnly(const FileName: RawByteString): Boolean;
+var
+  SystemFileName: RawByteString;
 begin
-  Result := fpAccess(PChar(pointer(FileName)),W_OK)<>0;
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  Result:=fpAccess(PChar(SystemFileName),W_OK)<>0;
 end;
 
-Function FileSetDate (Const FileName : String;Age : Longint) : Longint;
-
+Function FileSetDate (Const FileName : RawByteString; Age : Longint) : Longint;
 var
+  SystemFileName: RawByteString;
   t: TUTimBuf;
-
 begin
-  Result := 0;
-  t.actime := Age;
-  t.modtime := Age;
-  if fputime(PChar(pointer(FileName)), @t) = -1 then
-    Result := fpgeterrno;
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+  Result:=0;
+  t.actime:= Age;
+  t.modtime:=Age;
+  if fputime(PChar(SystemFileName), @t) = -1 then
+    Result:=fpgeterrno;
 end;
 
 {****************************************************************************

+ 22 - 11
rtl/watcom/sysutils.pp

@@ -288,10 +288,11 @@ begin
 end;
 
 
-function FileExists (const FileName: string): boolean;
+function FileExists (const FileName: RawByteString): boolean;
 var
   L: longint;
 begin
+  { no need to convert to DefaultFileSystemEncoding, FileGetAttr will do that }
   if FileName = '' then
    Result := false
   else
@@ -303,10 +304,11 @@ begin
 end;
 
 
-function DirectoryExists (const Directory: string): boolean;
+function DirectoryExists (const Directory: RawByteString): boolean;
 var
   L: longint;
 begin
+  { no need to convert to DefaultFileSystemEncoding, FileGetAttr will do that }
   if Directory = '' then
    Result := false
   else
@@ -422,11 +424,13 @@ begin
 end;
 
 
-Function FileGetAttr (Const FileName : String) : Longint;
+Function FileGetAttr (Const FileName : RawByteString) : Longint;
 var
   Regs: registers;
+  SystemFileName: RawByteString;
 begin
-  StringToTB(FileName);
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Filename);
+  StringToTB(SystemFileName);
   Regs.Edx := tb_offset;
   Regs.Ds := tb_segment;
   if LFNSupport then
@@ -444,11 +448,13 @@ begin
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
+Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
 var
   Regs: registers;
+  SystemFileName: RawByteString;
 begin
-  StringToTB(FileName);
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Filename);
+  StringToTB(SystemFileName);
   Regs.Edx := tb_offset;
   Regs.Ds := tb_segment;
   if LFNSupport then
@@ -467,11 +473,13 @@ begin
 end;
 
 
-Function DeleteFile (Const FileName : String) : Boolean;
+Function DeleteFile (Const FileName : RawByteString) : Boolean;
 var
   Regs: registers;
+  SystemFileName: RawByteString;
 begin
-  StringToTB(FileName);
+  SystemFileName:=ToSingleByteFileSystemEncodedFileName(Filename);
+  StringToTB(SystemFileName);
   Regs.Edx := tb_offset;
   Regs.Ds := tb_segment;
   if LFNSupport then
@@ -485,14 +493,17 @@ begin
 end;
 
 
-Function RenameFile (Const OldName, NewName : String) : Boolean;
+Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
 var
   Regs: registers;
+  OldSystemFileName, NewSystemFileName: RawByteString;
 begin
-  StringToTB(OldName + #0 + NewName);
+  OldSystemFileName:=ToSingleByteFileSystemEncodedFileName(OldName);
+  NewSystemFileName:=ToSingleByteFileSystemEncodedFileName(NewFile);
+  StringToTB(OldSystemFileName + #0 + NewSystemFileName);
   Regs.Edx := tb_offset;
   Regs.Ds := tb_segment;
-  Regs.Edi := tb_offset + Length(OldName) + 1;
+  Regs.Edi := tb_offset + Length(OldSystemFileName) + 1;
   Regs.Es := tb_segment;
   if LFNSupport then
     Regs.Eax := $7156

+ 3 - 3
rtl/wii/sysutils.pp

@@ -114,13 +114,13 @@ begin
 end;
 
 
-function DeleteFile(const FileName: string) : Boolean;
+function DeleteFile(const FileName: RawByteString) : Boolean;
 begin
   result := false;
 end;
 
 
-function RenameFile(const OldName, NewName: string): Boolean;
+function RenameFile(const OldName, NewName: RawByteString): Boolean;
 begin
   result := false;
 end;
@@ -135,7 +135,7 @@ begin
 end;
 
 
-Function FileExists (Const FileName : String) : Boolean;
+Function FileExists (Const FileName : RawByteString) : Boolean;
 Begin
   result := false;
 end;

+ 13 - 12
rtl/win/sysutils.pp

@@ -359,11 +359,12 @@ begin
 end;
 
 
-Function FileExists (Const FileName : String) : Boolean;
+Function FileExists (Const FileName : UnicodeString) : Boolean;
 var
   Attr:Dword;
 begin
-  Attr:=GetFileAttributes(PChar(FileName));
+
+  Attr:=GetFileAttributesW(PWideChar(FileName));
   if Attr <> $ffffffff then
     Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0
   else
@@ -371,11 +372,11 @@ begin
 end;
 
 
-Function DirectoryExists (Const Directory : String) : Boolean;
+Function DirectoryExists (Const Directory : UnicodeString) : Boolean;
 var
   Attr:Dword;
 begin
-  Attr:=GetFileAttributes(PChar(Directory));
+  Attr:=GetFileAttributesW(PWideChar(Directory));
   if Attr <> $ffffffff then
     Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) > 0
   else
@@ -460,30 +461,30 @@ begin
 end;
 
 
-Function FileGetAttr (Const FileName : String) : Longint;
+Function FileGetAttr (Const FileName : UnicodeString) : Longint;
 begin
-  Result:=Longint(GetFileAttributes(PChar(FileName)));
+  Result:=Longint(GetFileAttributesW(PWideChar(FileName)));
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
+Function FileSetAttr (Const Filename : UnicodeString; Attr: longint) : Longint;
 begin
-  if SetFileAttributes(PChar(FileName), Attr) then
+  if SetFileAttributesW(PWideChar(FileName), Attr) then
     Result:=0
   else
     Result := GetLastError;
 end;
 
 
-Function DeleteFile (Const FileName : String) : Boolean;
+Function DeleteFile (Const FileName : UnicodeString) : Boolean;
 begin
-  Result:=Windows.DeleteFile(Pchar(FileName));
+  Result:=Windows.DeleteFileW(PWidechar(FileName));
 end;
 
 
-Function RenameFile (Const OldName, NewName : String) : Boolean;
+Function RenameFile (Const OldName, NewName : UnicodeString) : Boolean;
 begin
-  Result := MoveFile(PChar(OldName), PChar(NewName));
+  Result := MoveFileW(PWideChar(OldName), PWideChar(NewName));
 end;
 
 

+ 9 - 23
rtl/wince/sysutils.pp

@@ -264,7 +264,7 @@ begin
 end;
 
 
-Function FileExists (Const FileName : String) : Boolean;
+Function FileExists (Const FileName : UnicodeString) : Boolean;
 var
   Attr:Dword;
 begin
@@ -276,7 +276,7 @@ begin
 end;
 
 
-Function DirectoryExists (Const Directory : String) : Boolean;
+Function DirectoryExists (Const Directory : UnicodeString) : Boolean;
 var
   Attr:Dword;
 begin
@@ -368,7 +368,7 @@ begin
 end;
 
 
-Function FileGetAttr (Const FileName : String) : Longint;
+Function FileGetAttr (Const FileName : UnicodeString) : Longint;
 var
   fn: PWideChar;
 begin
@@ -378,38 +378,24 @@ begin
 end;
 
 
-Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
-var
-  fn: PWideChar;
+Function FileSetAttr (Const Filename : UnicodeString; Attr: longint) : Longint;
 begin
-  fn:=StringToPWideChar(FileName);
-  if not SetFileAttributes(fn, Attr) then
+  if not SetFileAttributes(PWideChar(FileName), Attr) then
     Result := GetLastError
   else
     Result:=0;
-  FreeMem(fn);
 end;
 
 
-Function DeleteFile (Const FileName : String) : Boolean;
-var
-  fn: PWideChar;
+Function DeleteFile (Const FileName : UnicodeString) : Boolean;
 begin
-  fn:=StringToPWideChar(FileName);
-  DeleteFile:=Windows.DeleteFile(fn);
-  FreeMem(fn);
+  DeleteFile:=Windows.DeleteFile(PWideChar(FileName));
 end;
 
 
-Function RenameFile (Const OldName, NewName : String) : Boolean;
-var
-  fold, fnew: PWideChar;
+Function RenameFile (Const OldName, NewName : UnicodeString) : Boolean;
 begin
-  fold:=StringToPWideChar(OldName);
-  fnew:=StringToPWideChar(NewName);
-  Result := MoveFile(fold, fnew);
-  FreeMem(fnew);
-  FreeMem(fold);
+  Result := MoveFile(PWideChar(OldName), PWideChar(NewName));
 end;