Browse Source

* merged my own Windows specific fixes, and reworked the sysutils part a bit.

git-svn-id: branches/unicode@24741 -
marco 12 years ago
parent
commit
15d86a5489

+ 2 - 2
compiler/globals.pas

@@ -874,7 +874,7 @@ implementation
       {$endif}
       {$endif}
       {$ifdef mswindows}
       {$ifdef mswindows}
         GetEnvPchar:=nil;
         GetEnvPchar:=nil;
-        p:=GetEnvironmentStrings;
+        p:=GetEnvironmentStringsA;
         hp:=p;
         hp:=p;
         while hp^<>#0 do
         while hp^<>#0 do
          begin
          begin
@@ -891,7 +891,7 @@ implementation
            { next string entry}
            { next string entry}
            hp:=hp+len+1;
            hp:=hp+len+1;
          end;
          end;
-        FreeEnvironmentStrings(p);
+        FreeEnvironmentStringsA(p);
         {$define GETENVOK}
         {$define GETENVOK}
       {$endif}
       {$endif}
       {$ifdef os2}
       {$ifdef os2}

+ 6 - 6
rtl/inc/exeinfo.pp

@@ -71,11 +71,11 @@ uses
 
 
   var
   var
     Tmm: TMemoryBasicInformation;
     Tmm: TMemoryBasicInformation;
-{$ifdef wince}
+{$ifdef FPC_OS_UNICODE}
     TST: array[0..Max_Path] of WideChar;
     TST: array[0..Max_Path] of WideChar;
-{$else wince}
+{$else}
     TST: array[0..Max_Path] of Char;
     TST: array[0..Max_Path] of Char;
-{$endif wince}
+{$endif FPC_OS_UNICODE}
   procedure GetModuleByAddr(addr: pointer; var baseaddr: pointer; var filename: string);
   procedure GetModuleByAddr(addr: pointer; var baseaddr: pointer; var filename: string);
     begin
     begin
       baseaddr:=nil;
       baseaddr:=nil;
@@ -86,11 +86,11 @@ uses
           baseaddr:=Tmm.AllocationBase;
           baseaddr:=Tmm.AllocationBase;
           TST[0]:= #0;
           TST[0]:= #0;
           GetModuleFileName(THandle(Tmm.AllocationBase), TST, Length(TST));
           GetModuleFileName(THandle(Tmm.AllocationBase), TST, Length(TST));
-{$ifdef wince}
+{$ifdef FPC_OS_UNICODE}
           filename:= String(PWideChar(@TST));
           filename:= String(PWideChar(@TST));
-{$else wince}
+{$else}
           filename:= String(PChar(@TST));
           filename:= String(PChar(@TST));
-{$endif wince}
+{$endif FPC_OS_UNICODE}
         end;
         end;
     end;
     end;
 
 

+ 2 - 6
rtl/inc/systemh.inc

@@ -1161,7 +1161,7 @@ Procedure mkdir(const s:rawbytestring); overload;
 Procedure rmdir(const s:rawbytestring); overload;
 Procedure rmdir(const s:rawbytestring); overload;
 
 
 Procedure getdir(drivenr:byte;var dir: unicodestring);
 Procedure getdir(drivenr:byte;var dir: unicodestring);
-Procedure getdir(drivenr:byte;var dir: rawbytestring);rtlproc; // defaultrtlfilesystemcodepage is used here
+Procedure getdir(drivenr:byte;var dir: rawbytestring);{$ifndef VER2_6}rtlproc; {$endif}// defaultrtlfilesystemcodepage is used here
 {$ENDIF}
 {$ENDIF}
 {$endif FPC_HAS_FEATURE_FILEIO}
 {$endif FPC_HAS_FEATURE_FILEIO}
 
 
@@ -1266,11 +1266,7 @@ Procedure Error(RunTimeError : TRunTimeError);
 {$ifdef FPC_HAS_FEATURE_COMMANDARGS}
 {$ifdef FPC_HAS_FEATURE_COMMANDARGS}
 Function  Paramcount:Longint;
 Function  Paramcount:Longint;
 
 
-{$IFDEF FPC_UNICODE_RTL}
-Function  ParamStr(l:Longint):unicodestring;
-{$ELSE}
-Function  ParamStr(l:Longint):string;
-{$ENDIF}
+Function  ParamStr(l:Longint):RawByteString;
 {$endif FPC_HAS_FEATURE_COMMANDARGS}
 {$endif FPC_HAS_FEATURE_COMMANDARGS}
 
 
 Procedure Dump_Stack(var f : text;bp:pointer;addr : pointer = nil);
 Procedure Dump_Stack(var f : text;bp:pointer;addr : pointer = nil);

+ 2 - 5
rtl/linux/system.pp

@@ -121,11 +121,8 @@ end;}
 var
 var
  execpathstr : shortstring;
  execpathstr : shortstring;
 
 
-{$IFDEF FPC_UNICODE_RTL}
-function paramstr(l: longint) : unicodestring;
-{$ELSE}
-function paramstr(l: longint) : string;
-{$ENDIF}
+function paramstr(l: longint) : RawbyteString;
+
  begin
  begin
    { stricly conforming POSIX applications  }
    { stricly conforming POSIX applications  }
    { have the executing filename as argv[0] }
    { have the executing filename as argv[0] }

+ 4 - 4
rtl/objpas/objpas.pp

@@ -96,9 +96,9 @@ Var
      {$endif}
      {$endif}
 {$endif FPC_HAS_FEATURE_FILEIO}
 {$endif FPC_HAS_FEATURE_FILEIO}
 
 
-{$if defined(FPC_HAS_FEATURE_COMMANDARGS) and not defined(FPC_UNICODE_RTL)}
+{$if defined(FPC_HAS_FEATURE_COMMANDARGS) }
      { ParamStr should return also an ansistring }
      { ParamStr should return also an ansistring }
-     Function ParamStr(Param : Integer) : Ansistring;
+     Function ParamStr(Param : Integer) : UnicodeString;
 {$endif FPC_HAS_FEATURE_COMMANDARGS}
 {$endif FPC_HAS_FEATURE_COMMANDARGS}
 
 
 {$if defined(FPC_HAS_FEATURE_FILEIO) and defined(FPC_HAS_FEATURE_ANSISTRINGS) and not defined(FPC_UNICODE_RTL)}
 {$if defined(FPC_HAS_FEATURE_FILEIO) and defined(FPC_HAS_FEATURE_ANSISTRINGS) and not defined(FPC_UNICODE_RTL)}
@@ -262,8 +262,8 @@ end;
 {$endif}
 {$endif}
 {$endif FPC_HAS_FEATURE_FILEIO}
 {$endif FPC_HAS_FEATURE_FILEIO}
 
 
-{$if defined(FPC_HAS_FEATURE_COMMANDARGS) and not defined(FPC_UNICODE_RTL)}
-Function ParamStr(Param : Integer) : Ansistring;
+{$if defined(FPC_HAS_FEATURE_COMMANDARGS) }
+Function ParamStr(Param : Integer) : unicodestring;
 
 
 Var Len : longint;
 Var Len : longint;
 
 

+ 85 - 103
rtl/objpas/sysutils/filutil.inc

@@ -79,17 +79,21 @@ begin
                      ToSingleByteFileSystemEncodedFileName(NewName));
                      ToSingleByteFileSystemEncodedFileName(NewName));
 end;
 end;
 
 
+{$ifdef OS_FILEISREADONLY}
 Function FileIsReadOnly(const FileName: UnicodeString): Boolean;
 Function FileIsReadOnly(const FileName: UnicodeString): Boolean;
 
 
 begin
 begin
   Result:=FileIsReadOnly(ToSingleByteFileSystemEncodedFileName(FileName));
   Result:=FileIsReadOnly(ToSingleByteFileSystemEncodedFileName(FileName));
 end;
 end;
+{$endif}
 
 
+{$ifdef OS_FILESETDATEBYNAME}
 Function FileSetDate (Const FileName : UnicodeString;Age : Longint) : Longint;
 Function FileSetDate (Const FileName : UnicodeString;Age : Longint) : Longint;
 
 
 begin
 begin
   Result:=FileSetDate(ToSingleByteFileSystemEncodedFileName(FileName),Age);
   Result:=FileSetDate(ToSingleByteFileSystemEncodedFileName(FileName),Age);
 end;
 end;
+{$endif}
 
 
 function FileAge(const FileName: RawByteString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
 function FileAge(const FileName: RawByteString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
    
    
@@ -139,9 +143,76 @@ begin
 end;
 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}
 {$endif}
 
 
 {$ifndef SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
 {$ifndef SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
+
 Function FileOpen (Const FileName : rawbytestring; Mode : Integer) : THandle;
 Function FileOpen (Const FileName : rawbytestring; Mode : Integer) : THandle;
 begin
 begin
   Result:=FileOpen(UnicodeString(FileName),Mode);
   Result:=FileOpen(UnicodeString(FileName),Mode);
@@ -181,12 +252,6 @@ begin
   Result:=DirectoryExists(UnicodeString(Directory));
   Result:=DirectoryExists(UnicodeString(Directory));
 end;
 end;
 
 
-Function FindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TSearchRec) : Longint;
-
-begin
-  Result:=FindFirst(unicodestring(path),attr,rslt);
-end;
-
 Function FileGetAttr (Const FileName : RawByteString) : Longint;
 Function FileGetAttr (Const FileName : RawByteString) : Longint;
 begin
 begin
   Result:=FileGetAttr(unicodestring(FileName));  
   Result:=FileGetAttr(unicodestring(FileName));  
@@ -208,17 +273,21 @@ begin
   Result:=RenameFile(UnicodeString(OldName),UnicodeString(NewName));
   Result:=RenameFile(UnicodeString(OldName),UnicodeString(NewName));
 end;
 end;
 
 
+{$ifdef OS_FILEISREADONLY}
 Function FileIsReadOnly(const FileName: RawByteString): Boolean;
 Function FileIsReadOnly(const FileName: RawByteString): Boolean;
 
 
 begin
 begin
   Result:=FileIsReadOnly(UnicodeString(FileName));
   Result:=FileIsReadOnly(UnicodeString(FileName));
 end;
 end;
+{$endif}
 
 
+{$ifdef OS_FILESETDATEBYNAME}
 Function FileSetDate (Const FileName : RawByteString;Age : Longint) : Longint;
 Function FileSetDate (Const FileName : RawByteString;Age : Longint) : Longint;
 
 
 begin
 begin
   Result:=FileSetDate(UnicodeString(FileName),Age);
   Result:=FileSetDate(UnicodeString(FileName),Age);
 end;
 end;
+{$endif}
 
 
 function FileAge(const FileName: UnicodeString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
 function FileAge(const FileName: UnicodeString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
    
    
@@ -245,12 +314,6 @@ begin
 end;
 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 : UnicodeString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : UnicodeString;
 Function FileSearch (Const Name, DirList : UnicodeString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : UnicodeString;
 Var
 Var
   I : longint;
   I : longint;
@@ -289,26 +352,23 @@ begin
   result:='';
   result:='';
 end;
 end;
 
 
-Function FileSearch (Const Name, DirList : RawByteString; ImplicitCurrentDir : Boolean) : RawByteString;
+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
 begin
-  Result:=ToSingleByteFileSystemEncodedFileName(FileSearch(UnicodeString(Name),UnicodeString(DirList),ImplicitCurrentDir));
+     result:=ToSingleByteFileSystemEncodedFileName(FileSearch(unicodestring(name),unicodestring(dirlist),ImplicitCurrentDir));
 end;
 end;
 
 
 Function FileSearch (Const Name, DirList : UnicodeString; ImplicitCurrentDir : Boolean) : UnicodeString;
 Function FileSearch (Const Name, DirList : UnicodeString; ImplicitCurrentDir : Boolean) : UnicodeString;
-
 begin
 begin
   if ImplicitCurrentDir then
   if ImplicitCurrentDir then
     Result:=FileSearch(Name,DirList,[sfoImplicitCurrentDir])
     Result:=FileSearch(Name,DirList,[sfoImplicitCurrentDir])
-  else  
+  else
     Result:=FileSearch(Name,DirList,[]);
     Result:=FileSearch(Name,DirList,[]);
 end;
 end;
-    
-Function ExeSearch (Const Name : RawByteString; Const DirList : RawByteString ='' ) : RawByteString;
-
-begin
-  Result:=ToSingleByteFileSystemEncodedFileName(ExeSearch(UnicodeString(Name),UnicodeString(Dirlist)));
-end;
 
 
 Function ExeSearch (Const Name : UnicodeString; Const DirList : UnicodeString ='' ) : UnicodeString;
 Function ExeSearch (Const Name : UnicodeString; Const DirList : UnicodeString ='' ) : UnicodeString;
 
 
@@ -327,87 +387,9 @@ begin
   Result := FileSearch(Name, D, O);
   Result := FileSearch(Name, D, O);
 end;
 end;
 
 
-{$endif}
-
-Function FileSearch (Const Name, DirList : RawByteString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : RawByteString;
-Var
-  I : longint;
-  Temp : RawByteString;
-
+Function ExeSearch (Const Name : RawbyteString; Const DirList : RawbyteString ='' ) : RawByteString;
 begin
 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:='';
+  result:=ToSingleByteFileSystemEncodedFileName(ExeSearch(unicodestring(name),unicodestring(dirlist)));
 end;
 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;
-
-{$IFNDEF FPC_UNICODE_RTL}
-function FileAge(const FileName: RawByteString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
+{$endif}
 
 
-Var
-  Info : TSearchRec;
-  A : Integer;
-   
-begin
-  for A:=1 to Length(FileName) do
-    If (FileName[A] in ['?','*']) then
-      Exit(False);
-  A:=0;
-  if Not FollowLink then
-    A:=A or faSymLink;
-  Result:=FindFirst(FileName,A,Info)=0;
-  If Result then 
-    FileDateTime:=FileDatetoDateTime (Info.Time);
-  FindClose(Info);
-end;
-{$ENDIF}

+ 0 - 9
rtl/objpas/sysutils/filutilh.inc

@@ -15,7 +15,6 @@
 
 
 Type
 Type
 
 
-{$IFDEF FPC_UNICODE_RTL}
 
 
   // Some operating systems need extra find data.
   // Some operating systems need extra find data.
 {$if defined(Win32) or defined(WinCE) or defined(Win64)}
 {$if defined(Win32) or defined(WinCE) or defined(Win64)}
@@ -34,9 +33,6 @@ Type
     TUnicodeSearchFindData = TNativeNTFindData;
     TUnicodeSearchFindData = TNativeNTFindData;
 {$endif}
 {$endif}
 
 
-
-{$ENDIF FPC_UNICODE_RTL}
-
 // USEFINDDATA is only defined here.
 // USEFINDDATA is only defined here.
 
 
 {$if defined(Win32) or defined(Win64)}
 {$if defined(Win32) or defined(Win64)}
@@ -64,7 +60,6 @@ Type
     {$DEFINE USEFINDDATA}
     {$DEFINE USEFINDDATA}
 {$endif}
 {$endif}
 
 
-{$IFDEF FPC_UNICODE_RTL}
   // The actual unicode search record
   // The actual unicode search record
   TUnicodeSearchRec = Record
   TUnicodeSearchRec = Record
     Time : Longint;
     Time : Longint;
@@ -82,7 +77,6 @@ Type
     FindData : TUnicodeSearchFindData;
     FindData : TUnicodeSearchFindData;
 {$ENDIF}    
 {$ENDIF}    
   end;
   end;
-{$ENDIF}
 
 
   TRawbyteSearchRec = Record
   TRawbyteSearchRec = Record
     Time : Longint;
     Time : Longint;
@@ -141,8 +135,6 @@ Type
   TFileSearchOption = (sfoImplicitCurrentDir,sfoStripQuotes);
   TFileSearchOption = (sfoImplicitCurrentDir,sfoStripQuotes);
   TFileSearchOptions = set of TFileSearchOption;
   TFileSearchOptions = set of TFileSearchOption;
 
 
-{$IFDEF FPC_UNICODE_RTL}
-
 Function FileOpen (Const FileName : unicodestring; Mode : Integer) : THandle;
 Function FileOpen (Const FileName : unicodestring; Mode : Integer) : THandle;
 Function FileCreate (Const FileName : UnicodeString) : THandle;
 Function FileCreate (Const FileName : UnicodeString) : THandle;
 Function FileCreate (Const FileName : UnicodeString; Rights : Integer) : THandle;
 Function FileCreate (Const FileName : UnicodeString; Rights : Integer) : THandle;
@@ -165,7 +157,6 @@ Function FileSearch (Const Name, DirList : UnicodeString; ImplicitCurrentDir : B
 Function ExeSearch  (Const Name : UnicodeString; Const DirList : UnicodeString = '') : UnicodeString;
 Function ExeSearch  (Const Name : UnicodeString; Const DirList : UnicodeString = '') : UnicodeString;
 Function FileIsReadOnly(const FileName : UnicodeString): Boolean;
 Function FileIsReadOnly(const FileName : UnicodeString): Boolean;
 function FileAge(const FileName: UnicodeString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
 function FileAge(const FileName: UnicodeString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
-{$ENDIF UNICODERTL}
 
 
 Function FileOpen (Const FileName : RawByteString; Mode : Integer) : THandle;
 Function FileOpen (Const FileName : RawByteString; Mode : Integer) : THandle;
 Function FileCreate (Const FileName : RawByteString) : THandle;
 Function FileCreate (Const FileName : RawByteString) : THandle;

+ 1 - 1
rtl/objpas/sysutils/fina.inc

@@ -143,7 +143,7 @@ end;
 {$I fexpand.inc}
 {$I fexpand.inc}
 
 
 {$ENDIF}
 {$ENDIF}
-{$UNDEFINE PathStr}
+{$UNDEF PathStr}
 
 
 
 
 function ExpandFileName (Const FileName : string): String;
 function ExpandFileName (Const FileName : string): String;

+ 0 - 12
rtl/objpas/sysutils/sysutils.inc

@@ -23,30 +23,20 @@
 
 
 
 
   {$ifndef OS_FILEISREADONLY}
   {$ifndef OS_FILEISREADONLY}
-{$ifdef FPC_UNICODE_RTL}
   Function FileIsReadOnly(const FileName: RawByteString): Boolean;
   Function FileIsReadOnly(const FileName: RawByteString): Boolean;
-{$else}
-  Function FileIsReadOnly(const FileName: String): Boolean;
-{$endif}
   begin
   begin
     Result := (FileGetAttr(FileName) and faReadOnly) <> 0;
     Result := (FileGetAttr(FileName) and faReadOnly) <> 0;
   end;
   end;
-  {$ifdef  FPC_UNICODE_RTL}
   Function FileIsReadOnly(const FileName: UnicodeString): Boolean;
   Function FileIsReadOnly(const FileName: UnicodeString): Boolean;
 
 
   begin
   begin
     Result := (FileGetAttr(FileName) and faReadOnly) <> 0;
     Result := (FileGetAttr(FileName) and faReadOnly) <> 0;
   end;
   end;
-  {$endif}
   {$endif OS_FILEISREADONLY}
   {$endif OS_FILEISREADONLY}
 
 
 
 
   {$ifndef OS_FILESETDATEBYNAME}
   {$ifndef OS_FILESETDATEBYNAME}
-  {$ifdef FPC_UNICODE_RTL}
   Function FileSetDate (Const FileName : RawByteString;Age : Longint) : Longint;
   Function FileSetDate (Const FileName : RawByteString;Age : Longint) : Longint;
-  {$else}
-  Function FileSetDate (Const FileName : String;Age : Longint) : Longint;
-  {$endif}
   Var
   Var
     fd : THandle;
     fd : THandle;
   begin
   begin
@@ -65,7 +55,6 @@
       Result:=-1;
       Result:=-1;
   {$endif}
   {$endif}
   end;
   end;
-  {$ifdef FPC_UNICODE_RTL}
   Function FileSetDate (Const FileName : UnicodeString;Age : Longint) : Longint;
   Function FileSetDate (Const FileName : UnicodeString;Age : Longint) : Longint;
   Var
   Var
     fd : THandle;
     fd : THandle;
@@ -86,7 +75,6 @@
   {$endif}
   {$endif}
   end;
   end;
   {$endif}
   {$endif}
-  {$endif}
 
 
   { Read String Handling functions implementation }
   { Read String Handling functions implementation }
   {$i sysstr.inc}
   {$i sysstr.inc}

+ 1 - 14
rtl/unix/sysutils.pp

@@ -1,4 +1,4 @@
-{
+{
     This file is part of the Free Pascal run time library.
     This file is part of the Free Pascal run time library.
     Copyright (c) 1999-2000 by Florian Klaempfl
     Copyright (c) 1999-2000 by Florian Klaempfl
     member of the Free Pascal development team
     member of the Free Pascal development team
@@ -267,10 +267,6 @@ procedure UnhookSignal(RtlSigNum: Integer; OnlyIfHooked: Boolean = True);
 
 
 {$DEFINE SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
 {$DEFINE SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
 
 
-{$IFNDEF FPC_UNICODE_RTL}
-{$DEFINE SYSUTILS_HAS_UNICODESTR_FILEUTIL_IMPL}
-{$ENDIF}
-
 { Include platform independent implementation part }
 { Include platform independent implementation part }
 {$i sysutils.inc}
 {$i sysutils.inc}
 
 
@@ -703,13 +699,11 @@ Begin
   f.FindHandle:=nil;
   f.FindHandle:=nil;
 End;
 End;
 
 
-{$IFDEF FPC_UNICODE_RTL}
 Procedure FindClose(Var f: TUnicodeSearchRec);
 Procedure FindClose(Var f: TUnicodeSearchRec);
 Begin
 Begin
   Do_findClose(PUnixFindData(f.FindHandle));
   Do_findClose(PUnixFindData(f.FindHandle));
   f.FindHandle:=nil;
   f.FindHandle:=nil;
 End;
 End;
-{$ENDIF}
 
 
 Function Do_FindGetFileInfo(const s:RawByteString; D:PUnixFindData; 
 Function Do_FindGetFileInfo(const s:RawByteString; D:PUnixFindData; 
                             out st : baseunix.stat; out WinAttr : longint):boolean;
                             out st : baseunix.stat; out WinAttr : longint):boolean;
@@ -747,7 +741,6 @@ begin
     End;
     End;
 end;
 end;
 
 
-{$IFDEF FPC_UNICODE_RTL}
 
 
 Type
 Type
   PUnicodeSearchRec = ^TUnicodeSearchRec;
   PUnicodeSearchRec = ^TUnicodeSearchRec;
@@ -771,7 +764,6 @@ begin
     f^.Time:=st.st_mtime;
     f^.Time:=st.st_mtime;
     End;
     End;
 end;
 end;
-{$ENDIF}
 
 
 // Returns the FOUND filename. Empty if no result is found.
 // Returns the FOUND filename. Empty if no result is found.
 // Uses CB to return file info
 // Uses CB to return file info
@@ -836,13 +828,11 @@ begin
   FindNext:=Do_findNext(PUnixFindData(Rslt.FindHandle),@FindGetFileInfoR,@Rslt);
   FindNext:=Do_findNext(PUnixFindData(Rslt.FindHandle),@FindGetFileInfoR,@Rslt);
 end;
 end;
 
 
-{$IFDEF FPC_UNICODE_RTL}
 Function FindNext (Var Rslt : TUnicodeSearchRec) : Longint;
 Function FindNext (Var Rslt : TUnicodeSearchRec) : Longint;
 
 
 begin
 begin
   FindNext:=Do_findNext(PUnixFindData(Rslt.FindHandle),@FindGetFileInfoU,@Rslt);
   FindNext:=Do_findNext(PUnixFindData(Rslt.FindHandle),@FindGetFileInfoU,@Rslt);
 end;
 end;
-{$ENDIF}
 
 
 Function FindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TRawByteSearchRec) : Longint;
 Function FindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TRawByteSearchRec) : Longint;
 
 
@@ -881,7 +871,6 @@ Begin
     FindClose(Rslt); 
     FindClose(Rslt); 
 End;
 End;
 
 
-{$IFDEF FPC_UNICODE_RTL}
 Function FindFirst (Const Path : UnicodeString; Attr : Longint; out Rslt : TUnicodeSearchRec) : Longint;
 Function FindFirst (Const Path : UnicodeString; Attr : Longint; out Rslt : TUnicodeSearchRec) : Longint;
 
 
 {
 {
@@ -921,8 +910,6 @@ Begin
   If (Result<>0) then
   If (Result<>0) then
     FindClose(Rslt); 
     FindClose(Rslt); 
 End;
 End;
-{$ENDIF}
-
 
 
 Function FileGetDate (Handle : Longint) : Longint;
 Function FileGetDate (Handle : Longint) : Longint;
 
 

+ 11 - 5
rtl/win/dos.pp

@@ -612,9 +612,11 @@ end;
 procedure getfattr(var f;var attr : word);
 procedure getfattr(var f;var attr : word);
 var
 var
    l : longint;
    l : longint;
+   s : ansistring;
 begin
 begin
   doserror:=0;
   doserror:=0;
-  l:=GetFileAttributes(filerec(f).name);
+  s:=filerec(f).name;
+  l:=GetFileAttributes(pchar(s));
   if l=longint($ffffffff) then
   if l=longint($ffffffff) then
    begin
    begin
      doserror:=getlasterror;
      doserror:=getlasterror;
@@ -626,15 +628,19 @@ end;
 
 
 
 
 procedure setfattr(var f;attr : word);
 procedure setfattr(var f;attr : word);
+var s : ansistring;
 begin
 begin
   { Fail for setting VolumeId }
   { Fail for setting VolumeId }
   if (attr and VolumeID)<>0 then
   if (attr and VolumeID)<>0 then
     doserror:=5
     doserror:=5
   else
   else
-   if SetFileAttributes(filerec(f).name,attr) then
-    doserror:=0
-  else
-    doserror:=getlasterror;
+     begin
+       s:=filerec(f).name;
+       if SetFileAttributes(pchar(s),attr) then
+        doserror:=0
+      else
+        doserror:=getlasterror;
+     end;
 end;
 end;
 
 
 { change to short filename if successful win32 call PM }
 { change to short filename if successful win32 call PM }

+ 1 - 1
rtl/win/dynlibs.inc

@@ -39,7 +39,7 @@ Uses windows;
 Function LoadLibrary(const Name : AnsiString) : TlibHandle;
 Function LoadLibrary(const Name : AnsiString) : TlibHandle;
 
 
 begin
 begin
-  Result:=Windows.LoadLibrary(PChar(Name));
+  Result:=Windows.LoadLibraryA(PChar(Name));
 end;
 end;
 
 
 Function GetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;
 Function GetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;

+ 121 - 3
rtl/win/sysdir.inc

@@ -20,6 +20,123 @@
 type
 type
  TDirFnType=function(name:pointer):longbool;stdcall;
  TDirFnType=function(name:pointer):longbool;stdcall;
 
 
+{$ifdef FPC_UNICODE_RTL}
+procedure dirfn(afunc : TDirFnType;s:unicodestring);
+begin
+  DoDirSeparators(s);
+  if not aFunc(punicodechar(s)) then
+    begin
+      errno:=GetLastError;
+      Errno2InoutRes;
+    end;
+end;
+
+function CreateDirectoryTrunc(name:pointer):longbool;stdcall;
+begin
+  CreateDirectoryTrunc:=CreateDirectory(name,nil);
+end;
+
+Procedure do_MkDir(const s: UnicodeString);[IOCheck];
+begin
+  If (length(s)=0) or (InOutRes <> 0) then
+   exit;
+  dirfn(TDirFnType(@CreateDirectoryTrunc),s);
+end;
+
+Procedure do_MkDir(const s: RawByteString);[IOCheck];
+begin
+  do_mkdir(UnicodeString(s));
+end;
+
+Procedure do_RmDir(const s: UnicodeString);[IOCheck];
+begin
+  if (s ='.') then
+    InOutRes := 16;
+  {$ifdef WINCE}
+  if (s='..') then
+    InOutRes := 5;
+  {$endif WINCE}
+  If (s='') or (InOutRes <> 0) then
+   exit;
+  dirfn(TDirFnType(@RemoveDirectory),s);
+{$ifdef WINCE}
+  if (Inoutres=3) and (Pos(DirectorySeparator, s)<2) then
+    Inoutres:=2;
+{$endif WINCE}
+end;
+
+Procedure do_RmDir(const s: RawByteString);[IOCheck];
+begin
+  do_RmDir(UnicodeString(s));
+end;
+
+Procedure do_ChDir(const s: UnicodeString);[IOCheck];
+begin
+{$ifndef WINCE}
+  If (s='') or (InOutRes <> 0) then
+   exit;
+  dirfn(TDirFnType(@SetCurrentDirectory),s);
+  if Inoutres=2 then
+   Inoutres:=3;
+{$else WINCE}
+  InOutRes:=3;
+{$endif WINCE}
+end;
+
+Procedure do_ChDir(const s: RawByteString);[IOCheck];
+begin
+  do_ChDir(UnicodeString(s));
+end;
+
+procedure do_GetDir (DriveNr: byte; var Dir: Unicodestring);
+{$ifndef WINCE}
+var
+  Drive:array[0..3]of char;
+  defaultdrive:boolean;
+  DirBuf,SaveBuf:array[0..259] of WideChar;
+  len : integer;
+{$endif WINCE}
+begin
+{$ifndef WINCE}
+  defaultdrive:=drivenr=0;
+  if not defaultdrive then
+   begin
+    Drive[0]:=widechar(Drivenr+64);
+    Drive[1]:=':';
+    Drive[2]:=#0;
+    Drive[3]:=#0;
+    GetCurrentDirectory(high(SaveBuf)+1,SaveBuf); // in TChar
+    if not SetCurrentDirectory(@Drive) then
+     begin
+      errno := word (GetLastError);
+      Errno2InoutRes;
+      Dir := widechar (DriveNr + 64) + ':\';
+      SetCurrentDirectory(@SaveBuf);
+      Exit;
+     end;
+   end;
+
+  len:=GetCurrentDirectory(0,nil);
+  setlength(dir,len-1); // -1 because len is #0 inclusive
+  GetCurrentDirectory(len,punicodechar(dir));
+  if not defaultdrive then
+   SetCurrentDirectory(@SaveBuf);
+  if not FileNameCasePreserving then
+   dir:=upcase(dir);
+    {todo: massive loss of encoding and number of chars}
+{$else WINCE}
+  Dir:='\';
+{$endif WINCE}
+end;
+
+procedure do_GetDir (DriveNr: byte; var Dir: RawByteString);
+
+var ldir : Unicodestring;
+begin
+  do_GetDir(DriveNr,ldir);
+  dir:=ToSingleByteFileSystemEncodedFileName(ldir);
+end;
+{$else}
 procedure dirfn(afunc : TDirFnType;s:pchar;len:integer);
 procedure dirfn(afunc : TDirFnType;s:pchar;len:integer);
 begin
 begin
   DoDirSeparators(s);
   DoDirSeparators(s);
@@ -35,14 +152,14 @@ begin
   CreateDirectoryTrunc:=CreateDirectory(name,nil);
   CreateDirectoryTrunc:=CreateDirectory(name,nil);
 end;
 end;
 
 
-Procedure MkDir(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_MKDIR'];
+Procedure do_MkDir(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_MKDIR'];
 begin
 begin
   If not assigned(s) or (len=0) or (InOutRes <> 0) then
   If not assigned(s) or (len=0) or (InOutRes <> 0) then
    exit;
    exit;
   dirfn(TDirFnType(@CreateDirectoryTrunc),s,len);
   dirfn(TDirFnType(@CreateDirectoryTrunc),s,len);
 end;
 end;
 
 
-Procedure RmDir(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_RMDIR'];
+Procedure do_RmDir(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_RMDIR'];
 
 
 begin
 begin
   if (len=1) and (s^ ='.') then
   if (len=1) and (s^ ='.') then
@@ -60,7 +177,7 @@ begin
 {$endif WINCE}
 {$endif WINCE}
 end;
 end;
 
 
-Procedure ChDir(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_CHDIR'];
+Procedure do_ChDir(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_CHDIR'];
 
 
 begin
 begin
 {$ifndef WINCE}
 {$ifndef WINCE}
@@ -110,3 +227,4 @@ begin
   Dir:='\';
   Dir:='\';
 {$endif WINCE}
 {$endif WINCE}
 end;
 end;
+{$endif}

+ 66 - 2
rtl/win/sysfile.inc

@@ -31,7 +31,47 @@ begin
   CloseHandle(h);
   CloseHandle(h);
 end;
 end;
 
 
+{$ifdef FPC_UNICODE_RTL}
+procedure do_erase(const p : unicodestring);
+var lp:unicodestring;
+begin
+   lp:=p;
+   DoDirSeparators(lp);
+   if DeleteFile(punicodechar(lp))=0 then
+    Begin
+      errno:=GetLastError;
+      if errno=5 then
+       begin
+         if ((GetFileAttributes(punicodechar(lp)) and FILE_ATTRIBUTE_DIRECTORY)=FILE_ATTRIBUTE_DIRECTORY) then
+          errno:=2;
+       end;
+      Errno2InoutRes;
+    end;
+end;
 
 
+procedure do_erase(const p : rawbytestring);
+begin
+   Do_Erase(Unicodestring(p));
+end;
+
+procedure do_rename(const p1:unicodestring;const p2 : unicodestring);
+var lp1,lp2:unicodestring;
+begin
+  lp1:=p1; lp2:=p2;
+  DoDirSeparators(lp1);
+  DoDirSeparators(lp2);
+  if MoveFile(punicodechar(lp1),punicodechar(lp2))=0 then
+   Begin
+      errno:=GetLastError;
+      Errno2InoutRes;
+   end;
+end;
+
+procedure do_rename(const p1:unicodestring;const p2 : rawbytestring);
+begin
+  do_rename(p1,unicodestring(p2));
+end;
+{$else}
 procedure do_erase(p : pchar);
 procedure do_erase(p : pchar);
 begin
 begin
    DoDirSeparators(p);
    DoDirSeparators(p);
@@ -59,7 +99,7 @@ begin
    end;
    end;
 end;
 end;
 
 
-
+{$endif}
 function do_write(h:thandle;addr:pointer;len : longint) : longint;
 function do_write(h:thandle;addr:pointer;len : longint) : longint;
 var
 var
    size:longint;
    size:longint;
@@ -191,7 +231,11 @@ begin
 end;
 end;
 
 
 
 
+{$ifdef FPC_UNICODE_RTL}
+procedure do_open(var f;const op:unicodestring;flags:longint);
+{$else}
 procedure do_open(var f;p:pchar;flags:longint);
 procedure do_open(var f;p:pchar;flags:longint);
+{$endif}
 {
 {
   filerec and textrec have both handle and mode as the first items so
   filerec and textrec have both handle and mode as the first items so
   they could use the same routine for opening/creating.
   they could use the same routine for opening/creating.
@@ -207,7 +251,13 @@ Var
   shflags,
   shflags,
   oflags,cd : longint;
   oflags,cd : longint;
   security : TSecurityAttributes;
   security : TSecurityAttributes;
+{$ifdef FPC_UNICODE_RTL}
+  p : unicodestring;
+{$endif}
 begin
 begin
+{$ifdef FPC_UNICODE_RTL}
+  p:=op;
+{$endif}
   DoDirSeparators(p);
   DoDirSeparators(p);
   { close first if opened }
   { close first if opened }
   if ((flags and $10000)=0) then
   if ((flags and $10000)=0) then
@@ -266,7 +316,11 @@ begin
   else
   else
     cd:=OPEN_EXISTING;
     cd:=OPEN_EXISTING;
   { empty name is special }
   { empty name is special }
+{$ifdef FPC_UNICODE_RTL}
+  if p='' then
+{$else}
   if p[0]=#0 then
   if p[0]=#0 then
+{$endif}
    begin
    begin
      case FileRec(f).mode of
      case FileRec(f).mode of
        fminput :
        fminput :
@@ -285,8 +339,11 @@ begin
   security.nLength := Sizeof(TSecurityAttributes);
   security.nLength := Sizeof(TSecurityAttributes);
   security.bInheritHandle:=true;
   security.bInheritHandle:=true;
   security.lpSecurityDescriptor:=nil;
   security.lpSecurityDescriptor:=nil;
+  {$ifdef FPC_UNICODE_RTL}
+  filerec(f).handle:=CreateFile(punicodechar(p),oflags,shflags,@security,cd,FILE_ATTRIBUTE_NORMAL,0);
+  {$else}
   filerec(f).handle:=CreateFile(p,oflags,shflags,@security,cd,FILE_ATTRIBUTE_NORMAL,0);
   filerec(f).handle:=CreateFile(p,oflags,shflags,@security,cd,FILE_ATTRIBUTE_NORMAL,0);
-
+  {$endif}
   { append mode }
   { append mode }
   if ((flags and $100)<>0) and
   if ((flags and $100)<>0) and
      (filerec(f).handle<>0) and
      (filerec(f).handle<>0) and
@@ -304,3 +361,10 @@ begin
       Errno2InoutRes;
       Errno2InoutRes;
     end;
     end;
 end;
 end;
+
+{$ifdef FPC_UNICODE_RTL}
+procedure do_open(var f;const p:rawbytestring;flags:longint);
+begin
+ do_open(f,UnicodeString(p),flags);  
+end;
+{$endif}

+ 3 - 4
rtl/win/sysos.inc

@@ -218,7 +218,7 @@ threadvar
    function GetStdHandle(nStdHandle:DWORD):THANDLE;
    function GetStdHandle(nStdHandle:DWORD):THANDLE;
      stdcall;external KernelDLL name 'GetStdHandle';
      stdcall;external KernelDLL name 'GetStdHandle';
 
 
-   {$ifdef FPC_UNICODE_RTL}
+   {$ifdef FPC_UNICODE_RTLx}
    { command line/environment functions }
    { command line/environment functions }
 
 
    function GetCommandLine : pwidechar;
    function GetCommandLine : pwidechar;
@@ -281,7 +281,7 @@ threadvar
    function GetProcAddress(hModule:THandle; lpProcName:pchar):pointer; stdcall; external KernelDLL name 'GetProcAddress';
    function GetProcAddress(hModule:THandle; lpProcName:pchar):pointer; stdcall; external KernelDLL name 'GetProcAddress';
 
 
    {$ifdef FPC_UNICODE_RTL}
    {$ifdef FPC_UNICODE_RTL}
-    function GetFileAttributes(p : punicodechar) : dword;
+   function GetFileAttributes(p : punicodechar) : dword;
      stdcall;external KernelDLL name 'GetFileAttributesW';
      stdcall;external KernelDLL name 'GetFileAttributesW';
    function DeleteFile(p : punicodechar) : longint;
    function DeleteFile(p : punicodechar) : longint;
      stdcall;external KernelDLL name 'DeleteFileW';
      stdcall;external KernelDLL name 'DeleteFileW';
@@ -298,9 +298,8 @@ threadvar
      stdcall;external KernelDLL name 'RemoveDirectoryW';
      stdcall;external KernelDLL name 'RemoveDirectoryW';
    function SetCurrentDirectory(name : pointer) : longbool;
    function SetCurrentDirectory(name : pointer) : longbool;
      stdcall;external KernelDLL name 'SetCurrentDirectoryW';
      stdcall;external KernelDLL name 'SetCurrentDirectoryW';
-   function GetCurrentDirectory(bufsize : longint;name : punicodechar) : longbool;
+   function GetCurrentDirectory(bufsize : longint;name : punicodechar) : Dword;
      stdcall;external KernelDLL name 'GetCurrentDirectoryW';
      stdcall;external KernelDLL name 'GetCurrentDirectoryW';
-
    {$else}
    {$else}
    function GetFileAttributes(p : pchar) : dword;
    function GetFileAttributes(p : pchar) : dword;
      stdcall;external KernelDLL name 'GetFileAttributesA';
      stdcall;external KernelDLL name 'GetFileAttributesA';

+ 256 - 53
rtl/win/sysutils.pp

@@ -124,12 +124,12 @@ function GetFileVersion(const AFileName:string):Cardinal;
     result:=$fffffff;
     result:=$fffffff;
     fn:=AFileName;
     fn:=AFileName;
     UniqueString(fn);
     UniqueString(fn);
-    size:=GetFileVersionInfoSize(pchar(fn),@h);
+    size:=GetFileVersionInfoSizeA(pchar(fn),@h);
     if size>sizeof(buf) then
     if size>sizeof(buf) then
       begin
       begin
         getmem(bufp,size);
         getmem(bufp,size);
         try
         try
-          if GetFileVersionInfo(pchar(fn),h,size,bufp) then
+          if GetFileVersionInfoA(pchar(fn),h,size,bufp) then
             if VerQueryValue(bufp,'\',valrec,valsize) then
             if VerQueryValue(bufp,'\',valrec,valsize) then
               result:=valrec^.dwFileVersionMS;
               result:=valrec^.dwFileVersionMS;
         finally
         finally
@@ -138,7 +138,7 @@ function GetFileVersion(const AFileName:string):Cardinal;
       end
       end
     else
     else
       begin
       begin
-        if GetFileVersionInfo(pchar(fn),h,size,@buf) then
+        if GetFileVersionInfoA(pchar(fn),h,size,@buf) then
           if VerQueryValue(@buf,'\',valrec,valsize) then
           if VerQueryValue(@buf,'\',valrec,valsize) then
             result:=valrec^.dwFileVersionMS;
             result:=valrec^.dwFileVersionMS;
       end;
       end;
@@ -154,6 +154,9 @@ function GetFileVersion(const AFileName:string):Cardinal;
 {$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
 {$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
 
 
 
 
+{define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
+{$define SYSUTILS_HAS_UNICODESTR_FILEUTIL_IMPL}
+
 function ConvertEraYearString(Count ,Year,Month,Day : integer) : string; forward;
 function ConvertEraYearString(Count ,Year,Month,Day : integer) : string; forward;
 function ConvertEraString(Count ,Year,Month,Day : integer) : string; forward;
 function ConvertEraString(Count ,Year,Month,Day : integer) : string; forward;
 { Include platform independent implementation part }
 { Include platform independent implementation part }
@@ -192,12 +195,12 @@ begin
   getmem(buf,size);
   getmem(buf,size);
 
 
   try
   try
-    rc := WNetGetUniversalName (pchar(s), UNIVERSAL_NAME_INFO_LEVEL, buf, @size);
+    rc := WNetGetUniversalNameA (pchar(s), UNIVERSAL_NAME_INFO_LEVEL, buf, @size);
 
 
     if rc=ERROR_MORE_DATA then
     if rc=ERROR_MORE_DATA then
       begin
       begin
         buf:=reallocmem(buf,size);
         buf:=reallocmem(buf,size);
-        rc := WNetGetUniversalName (pchar(s), UNIVERSAL_NAME_INFO_LEVEL, buf, @size);
+        rc := WNetGetUniversalNameA (pchar(s), UNIVERSAL_NAME_INFO_LEVEL, buf, @size);
       end;
       end;
     if rc = NO_ERROR then
     if rc = NO_ERROR then
       Result := PRemoteNameInfo(buf)^.lpUniversalName
       Result := PRemoteNameInfo(buf)^.lpUniversalName
@@ -210,6 +213,39 @@ begin
   end;
   end;
 end;
 end;
 
 
+function ExpandUNCFileName (const filename:unicodestring) : string;
+{ returns empty string on errors }
+var
+  s    : unicodestring;
+  size : dword;
+  rc   : dword;
+  buf : pwidechar;
+begin
+  s := ExpandFileName (filename);
+
+  s := s + #0;
+
+  size := max_path;
+  getmem(buf,size);
+
+  try
+    rc := WNetGetUniversalNameW (pwidechar(s), UNIVERSAL_NAME_INFO_LEVEL, buf, @size);
+
+    if rc=ERROR_MORE_DATA then
+      begin
+        buf:=reallocmem(buf,size);
+        rc := WNetGetUniversalNameW (pwidechar(s), UNIVERSAL_NAME_INFO_LEVEL, buf, @size);
+      end;
+    if rc = NO_ERROR then
+      Result := PRemoteNameInfo(buf)^.lpUniversalName
+    else if rc = ERROR_NOT_CONNECTED then
+      Result := filename
+    else
+      Result := '';
+  finally
+    freemem(buf);
+  end;
+end;
 
 
 {****************************************************************************
 {****************************************************************************
                               File Functions
                               File Functions
@@ -227,27 +263,53 @@ const
                FILE_SHARE_WRITE,
                FILE_SHARE_WRITE,
                FILE_SHARE_READ or FILE_SHARE_WRITE);
                FILE_SHARE_READ or FILE_SHARE_WRITE);
 
 
+
+Function FileOpen (Const FileName : unicodestring; Mode : Integer) : THandle;
+begin
+  result := CreateFileW(PWideChar(FileName), dword(AccessMode[Mode and 3]),
+                       dword(ShareModes[(Mode and $F0) shr 4]), nil, OPEN_EXISTING,
+                       FILE_ATTRIBUTE_NORMAL, 0);
+  //if fail api return feInvalidHandle (INVALIDE_HANDLE=feInvalidHandle=-1)
+end;
+{$ifdef unused}
 Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
 Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
 begin
 begin
-  result := CreateFile(PChar(FileName), dword(AccessMode[Mode and 3]),
+  result := CreateFileA(PChar(FileName), dword(AccessMode[Mode and 3]),
                        dword(ShareModes[(Mode and $F0) shr 4]), nil, OPEN_EXISTING,
                        dword(ShareModes[(Mode and $F0) shr 4]), nil, OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL, 0);
                        FILE_ATTRIBUTE_NORMAL, 0);
   //if fail api return feInvalidHandle (INVALIDE_HANDLE=feInvalidHandle=-1)
   //if fail api return feInvalidHandle (INVALIDE_HANDLE=feInvalidHandle=-1)
 end;
 end;
 
 
-Function FileCreate (Const FileName : String) : THandle;
+Function FileCreate (Const FileName : RawbyteString) : THandle;
+begin
+  FileCreate:=FileCreate(FileName, fmShareExclusive, 0);
+end;
+
+Function FileCreate (Const FileName : RawbyteString; Rights:longint) : THandle;
+begin
+  FileCreate:=FileCreate(FileName, fmShareExclusive, Rights);
+end;
+
+Function FileCreate (Const FileName : RawbyteString; ShareMode : Integer; Rights : Integer) : THandle;
+begin
+  Result := CreateFileA(PChar(FileName), GENERIC_READ or GENERIC_WRITE,
+                       dword(ShareModes[(ShareMode and $F0) shr 4]), nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
+end;
+{$endif}
+
+Function FileCreate (Const FileName : UnicodeString) : THandle;
 begin
 begin
   FileCreate:=FileCreate(FileName, fmShareExclusive, 0);
   FileCreate:=FileCreate(FileName, fmShareExclusive, 0);
 end;
 end;
 
 
-Function FileCreate (Const FileName : String; Rights:longint) : THandle;
+Function FileCreate (Const FileName : UnicodeString; Rights:longint) : THandle;
 begin
 begin
   FileCreate:=FileCreate(FileName, fmShareExclusive, Rights);
   FileCreate:=FileCreate(FileName, fmShareExclusive, Rights);
 end;
 end;
 
 
-Function FileCreate (Const FileName : String; ShareMode : Integer; Rights : Integer) : THandle;
+Function FileCreate (Const FileName : UnicodeString; ShareMode : Integer; Rights : Integer) : THandle;
 begin
 begin
-  Result := CreateFile(PChar(FileName), GENERIC_READ or GENERIC_WRITE,
+  Result := CreateFileW(PwideChar(FileName), GENERIC_READ or GENERIC_WRITE,
                        dword(ShareModes[(ShareMode and $F0) shr 4]), nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
                        dword(ShareModes[(ShareMode and $F0) shr 4]), nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
 end;
 end;
 
 
@@ -327,7 +389,7 @@ begin
                 FileTimeToDosDateTime(lft,Longrec(Dtime).Hi,LongRec(DTIME).lo);
                 FileTimeToDosDateTime(lft,Longrec(Dtime).Hi,LongRec(DTIME).lo);
 end;
 end;
 
 
-
+{$ifdef unused}
 Function FileAge (Const FileName : String): Longint;
 Function FileAge (Const FileName : String): Longint;
 var
 var
   Handle: THandle;
   Handle: THandle;
@@ -343,38 +405,80 @@ begin
     end;
     end;
   Result := -1;
   Result := -1;
 end;
 end;
+{$endif}
+
+Function FileAge (Const FileName : UnicodeString): Longint;
+var
+  Handle: THandle;
+  FindData: TWin32FindDataW;
+begin
+  Handle := FindFirstFileW(Pwidechar(FileName), FindData);
+  if Handle <> INVALID_HANDLE_VALUE then
+    begin
+      Windows.FindClose(Handle);
+      if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
+        If WinToDosTime(FindData.ftLastWriteTime,Result) then
+          exit;
+    end;
+  Result := -1;
+end;
 
 
+{$ifdef unused}
 
 
 Function FileExists (Const FileName : String) : Boolean;
 Function FileExists (Const FileName : String) : Boolean;
 var
 var
   Attr:Dword;
   Attr:Dword;
 begin
 begin
-  Attr:=GetFileAttributes(PChar(FileName));
+  Attr:=GetFileAttributesA(PChar(FileName));
   if Attr <> $ffffffff then
   if Attr <> $ffffffff then
     Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0
     Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0
   else
   else
     Result:=False;
     Result:=False;
 end;
 end;
+{$endif}
 
 
+Function FileExists (Const FileName : UnicodeString) : Boolean;
+var
+  Attr:Dword;
+begin
+  Attr:=GetFileAttributesW(PWideChar(FileName));
+  if Attr <> $ffffffff then
+    Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0
+  else
+    Result:=False;
+end;
 
 
+{$ifdef unused}
 Function DirectoryExists (Const Directory : String) : Boolean;
 Function DirectoryExists (Const Directory : String) : Boolean;
 var
 var
   Attr:Dword;
   Attr:Dword;
 begin
 begin
-  Attr:=GetFileAttributes(PChar(Directory));
+  Attr:=GetFileAttributesA(PChar(Directory));
   if Attr <> $ffffffff then
   if Attr <> $ffffffff then
     Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) > 0
     Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) > 0
   else
   else
     Result:=False;
     Result:=False;
 end;
 end;
+{$endif}
+
 
 
+Function DirectoryExists (Const Directory : UnicodeString) : Boolean;
+var
+  Attr:Dword;
+begin
+  Attr:=GetFileAttributesW(PWideChar(Directory));
+  if Attr <> $ffffffff then
+    Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) > 0
+  else
+    Result:=False;
+end;
 
 
-Function FindMatch(var f: TSearchRec) : Longint;
+Function FindMatch(var f: TRawByteSearchRec) : Longint;
 begin
 begin
   { Find file with correct attribute }
   { Find file with correct attribute }
   While (F.FindData.dwFileAttributes and cardinal(F.ExcludeAttr))<>0 do
   While (F.FindData.dwFileAttributes and cardinal(F.ExcludeAttr))<>0 do
    begin
    begin
-     if not FindNextFile (F.FindHandle,F.FindData) then
+     if not FindNextFileA (F.FindHandle,F.FindData) then
       begin
       begin
         Result:=GetLastError;
         Result:=GetLastError;
         exit;
         exit;
@@ -388,15 +492,14 @@ begin
   Result:=0;
   Result:=0;
 end;
 end;
 
 
-
-Function FindFirst (Const Path : String; Attr : Longint; out Rslt : TSearchRec) : Longint;
+Function FindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TRawByteSearchRec) : Longint;
 begin
 begin
   Rslt.Name:=Path;
   Rslt.Name:=Path;
   Rslt.Attr:=attr;
   Rslt.Attr:=attr;
   Rslt.ExcludeAttr:=(not Attr) and ($1e);
   Rslt.ExcludeAttr:=(not Attr) and ($1e);
                  { $1e = faHidden or faSysFile or faVolumeID or faDirectory }
                  { $1e = faHidden or faSysFile or faVolumeID or faDirectory }
   { FindFirstFile is a Win32 Call }
   { FindFirstFile is a Win32 Call }
-  Rslt.FindHandle:=FindFirstFile (PChar(Path),Rslt.FindData);
+  Rslt.FindHandle:=FindFirstFileA (PChar(Path),Rslt.FindData);
   If Rslt.FindHandle=Invalid_Handle_value then
   If Rslt.FindHandle=Invalid_Handle_value then
    begin
    begin
      Result:=GetLastError;
      Result:=GetLastError;
@@ -406,8 +509,7 @@ begin
   Result:=FindMatch(Rslt);
   Result:=FindMatch(Rslt);
 end;
 end;
 
 
-
-Function FindNext (Var Rslt : TSearchRec) : Longint;
+Function FindNext (Var Rslt : TRawByteSearchRec) : Longint;
 begin
 begin
   if FindNextFile(Rslt.FindHandle, Rslt.FindData) then
   if FindNextFile(Rslt.FindHandle, Rslt.FindData) then
     Result := FindMatch(Rslt)
     Result := FindMatch(Rslt)
@@ -416,12 +518,63 @@ begin
 end;
 end;
 
 
 
 
-Procedure FindClose (Var F : TSearchrec);
+Procedure FindClose (Var F : TRawByteSearchRec);
 begin
 begin
    if F.FindHandle <> INVALID_HANDLE_VALUE then
    if F.FindHandle <> INVALID_HANDLE_VALUE then
     Windows.FindClose(F.FindHandle);
     Windows.FindClose(F.FindHandle);
 end;
 end;
 
 
+Function FindMatch(var f: TUnicodeSearchRec) : Longint;
+begin
+  { Find file with correct attribute }
+  While (F.FindData.dwFileAttributes and cardinal(F.ExcludeAttr))<>0 do
+   begin
+     if not FindNextFileW (F.FindHandle,F.FindData) then
+      begin
+        Result:=GetLastError;
+        exit;
+      end;
+   end;
+  { Convert some attributes back }
+  WinToDosTime(F.FindData.ftLastWriteTime,F.Time);
+  f.size:=F.FindData.NFileSizeLow+(qword(maxdword)+1)*F.FindData.NFileSizeHigh;
+  f.attr:=F.FindData.dwFileAttributes;
+  f.Name:=StrPas(@F.FindData.cFileName[0]);
+  Result:=0;
+end;
+
+
+Function FindFirst (Const Path : UnicodeString; Attr : Longint; out Rslt : TUnicodeSearchRec) : Longint;
+begin
+  Rslt.Name:=Path;
+  Rslt.Attr:=attr;
+  Rslt.ExcludeAttr:=(not Attr) and ($1e);
+                 { $1e = faHidden or faSysFile or faVolumeID or faDirectory }
+  { FindFirstFile is a Win32 Call }
+  Rslt.FindHandle:=FindFirstFileW (PWideChar(Path),Rslt.FindData);
+  If Rslt.FindHandle=Invalid_Handle_value then
+   begin
+     Result:=GetLastError;
+     exit;
+   end;
+  { Find file with correct attribute }
+  Result:=FindMatch(Rslt);
+end;
+
+Function FindNext (Var Rslt : TUnicodeSearchRec) : Longint;
+begin
+  if FindNextFileW(Rslt.FindHandle, Rslt.FindData) then
+    Result := FindMatch(Rslt)
+  else
+    Result := GetLastError;
+end;
+
+
+Procedure FindClose (Var F : TUnicodeSearchrec);
+begin
+   if F.FindHandle <> INVALID_HANDLE_VALUE then
+    Windows.FindClose(F.FindHandle);
+end;
 
 
 Function FileGetDate (Handle : THandle) : Longint;
 Function FileGetDate (Handle : THandle) : Longint;
 Var
 Var
@@ -446,15 +599,15 @@ begin
 end;
 end;
 
 
 
 
-Function FileGetAttr (Const FileName : String) : Longint;
+{Function FileGetAttr (Const FileName : String) : Longint;
 begin
 begin
-  Result:=Longint(GetFileAttributes(PChar(FileName)));
+  Result:=Longint(GetFileAttributesA(PChar(FileName)));
 end;
 end;
 
 
 
 
 Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
 Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
 begin
 begin
-  if SetFileAttributes(PChar(FileName), Attr) then
+  if SetFileAttributesA(PChar(FileName), Attr) then
     Result:=0
     Result:=0
   else
   else
     Result := GetLastError;
     Result := GetLastError;
@@ -463,16 +616,41 @@ end;
 
 
 Function DeleteFile (Const FileName : String) : Boolean;
 Function DeleteFile (Const FileName : String) : Boolean;
 begin
 begin
-  Result:=Windows.DeleteFile(Pchar(FileName));
+  Result:=Windows.DeleteFileA(Pchar(FileName));
 end;
 end;
 
 
 
 
 Function RenameFile (Const OldName, NewName : String) : Boolean;
 Function RenameFile (Const OldName, NewName : String) : Boolean;
 begin
 begin
-  Result := MoveFile(PChar(OldName), PChar(NewName));
+  Result := MoveFileA(PChar(OldName), PChar(NewName));
+end;
+}
+Function FileGetAttr (Const FileName : UnicodeString) : Longint;
+begin
+  Result:=Longint(GetFileAttributesW(PWideChar(FileName)));
+end;
+
+
+Function FileSetAttr (Const Filename : UnicodeString; Attr: longint) : Longint;
+begin
+  if SetFileAttributesW(PWideChar(FileName), Attr) then
+    Result:=0
+  else
+    Result := GetLastError;
+end;
+
+
+Function DeleteFile (Const FileName : UnicodeString) : Boolean;
+begin
+  Result:=Windows.DeleteFileW(PWidechar(FileName));
 end;
 end;
 
 
 
 
+Function RenameFile (Const OldName, NewName : UnicodeString) : Boolean;
+begin
+  Result := MoveFileW(PWideChar(OldName), PWideChar(NewName));
+end;
+
 {****************************************************************************
 {****************************************************************************
                               Disk Functions
                               Disk Functions
 ****************************************************************************}
 ****************************************************************************}
@@ -563,19 +741,19 @@ end;
 
 
 Function SetCurrentDir (Const NewDir : String) : Boolean;
 Function SetCurrentDir (Const NewDir : String) : Boolean;
 begin
 begin
-  Result:=SetCurrentDirectory(PChar(NewDir));
+  Result:=SetCurrentDirectoryA(PChar(NewDir));
 end;
 end;
 
 
 
 
 Function CreateDir (Const NewDir : String) : Boolean;
 Function CreateDir (Const NewDir : String) : Boolean;
 begin
 begin
-  Result:=CreateDirectory(PChar(NewDir),nil);
+  Result:=CreateDirectoryA(PChar(NewDir),nil);
 end;
 end;
 
 
 
 
 Function RemoveDir (Const Dir : String) : Boolean;
 Function RemoveDir (Const Dir : String) : Boolean;
 begin
 begin
-  Result:=RemoveDirectory(PChar(Dir));
+  Result:=RemoveDirectoryA(PChar(Dir));
 end;
 end;
 
 
 
 
@@ -662,7 +840,7 @@ var
   L: Integer;
   L: Integer;
   Buf: array[0..255] of Char;
   Buf: array[0..255] of Char;
 begin
 begin
-  L := GetLocaleInfo(LID, LT, Buf, SizeOf(Buf));
+  L := GetLocaleInfoA(LID, LT, Buf, SizeOf(Buf));
   if L > 0 then
   if L > 0 then
     SetString(Result, @Buf[0], L - 1)
     SetString(Result, @Buf[0], L - 1)
   else
   else
@@ -674,7 +852,7 @@ function GetLocaleChar(LID, LT: Longint; Def: Char): Char;
 var
 var
   Buf: array[0..3] of Char; // sdate allows 4 chars.
   Buf: array[0..3] of Char; // sdate allows 4 chars.
 begin
 begin
-  if GetLocaleInfo(LID, LT, Buf, sizeof(buf)) > 0 then
+  if GetLocaleInfoA(LID, LT, Buf, sizeof(buf)) > 0 then
     Result := Buf[0]
     Result := Buf[0]
   else
   else
     Result := Def;
     Result := Def;
@@ -693,7 +871,7 @@ begin
 
 
   ALCID := GetThreadLocale;
   ALCID := GetThreadLocale;
 //  ALCID := SysLocale.DefaultLCID;
 //  ALCID := SysLocale.DefaultLCID;
-  if GetDateFormat(ALCID , DATE_USE_ALT_CALENDAR
+  if GetDateFormatA(ALCID , DATE_USE_ALT_CALENDAR
       , @ASystemTime, PChar('gg')
       , @ASystemTime, PChar('gg')
       , @buf, SizeOf(buf)) > 0 then
       , @buf, SizeOf(buf)) > 0 then
   begin
   begin
@@ -736,7 +914,7 @@ begin
   ALCID := GetThreadLocale;
   ALCID := GetThreadLocale;
 //  ALCID := SysLocale.DefaultLCID;
 //  ALCID := SysLocale.DefaultLCID;
 
 
-  if GetDateFormat(ALCID, DATE_USE_ALT_CALENDAR
+  if GetDateFormatA(ALCID, DATE_USE_ALT_CALENDAR
       , @ASystemTime, PChar(AFormatText)
       , @ASystemTime, PChar(AFormatText)
       , @buf, SizeOf(buf)) > 0 then
       , @buf, SizeOf(buf)) > 0 then
   begin
   begin
@@ -798,7 +976,7 @@ begin
      EraNames[i] := '';  EraYearOffsets[i] := -1;
      EraNames[i] := '';  EraYearOffsets[i] := -1;
    end;
    end;
   ALCID := GetThreadLocale;
   ALCID := GetThreadLocale;
-  if GetLocaleInfo(ALCID , LOCALE_IOPTIONALCALENDAR, buf, sizeof(buf)) <= 0 then exit;
+  if GetLocaleInfoA(ALCID , LOCALE_IOPTIONALCALENDAR, buf, sizeof(buf)) <= 0 then exit;
   ACALID := StrToIntDef(buf,1);
   ACALID := StrToIntDef(buf,1);
 
 
   if ACALID in [3..5] then
   if ACALID in [3..5] then
@@ -953,7 +1131,7 @@ end;
 { GetEnvironmentStrings cannot be checked by CheckPointer function }
 { GetEnvironmentStrings cannot be checked by CheckPointer function }
 {$checkpointer off}
 {$checkpointer off}
 
 
-Function GetEnvironmentVariable(Const EnvVar : String) : String;
+Function GetEnvironmentVariable(Const EnvVar : Ansistring) : String;
 
 
 var
 var
    s : string;
    s : string;
@@ -961,7 +1139,7 @@ var
    hp,p : pchar;
    hp,p : pchar;
 begin
 begin
    Result:='';
    Result:='';
-   p:=GetEnvironmentStrings;
+   p:=GetEnvironmentStringsA;
    hp:=p;
    hp:=p;
    while hp^<>#0 do
    while hp^<>#0 do
      begin
      begin
@@ -975,7 +1153,32 @@ begin
         { next string entry}
         { next string entry}
         hp:=hp+strlen(hp)+1;
         hp:=hp+strlen(hp)+1;
      end;
      end;
-   FreeEnvironmentStrings(p);
+   FreeEnvironmentStringsA(p);
+end;
+
+Function GetEnvironmentVariable(Const EnvVar : UnicodeString) : UnicodeString;
+
+var
+   s : Unicodestring;
+   i : longint;
+   hp,p : pwidechar;
+begin
+   Result:='';
+   p:=GetEnvironmentStringsW;
+   hp:=p;
+   while hp^<>#0 do
+     begin
+        s:=strpas(hp);
+        i:=pos('=',s);
+        if uppercase(copy(s,1,i-1))=uppercase(envvar) then
+          begin
+             Result:=copy(s,i+1,length(s)-i);
+             break;
+          end;
+        { next string entry}
+        hp:=hp+strlen(hp)+1;
+     end;
+   FreeEnvironmentStringsW(p);
 end;
 end;
 
 
 Function GetEnvironmentVariableCount : Integer;
 Function GetEnvironmentVariableCount : Integer;
@@ -984,7 +1187,7 @@ var
   hp,p : pchar;
   hp,p : pchar;
 begin
 begin
   Result:=0;
   Result:=0;
-  p:=GetEnvironmentStrings;
+  p:=GetEnvironmentStringsA;
   hp:=p;
   hp:=p;
   If (Hp<>Nil) then
   If (Hp<>Nil) then
     while hp^<>#0 do
     while hp^<>#0 do
@@ -992,7 +1195,7 @@ begin
       Inc(Result);
       Inc(Result);
       hp:=hp+strlen(hp)+1;
       hp:=hp+strlen(hp)+1;
       end;
       end;
-  FreeEnvironmentStrings(p);
+  FreeEnvironmentStringsA(p);
 end;
 end;
 
 
 Function GetEnvironmentString(Index : Integer) : String;
 Function GetEnvironmentString(Index : Integer) : String;
@@ -1001,7 +1204,7 @@ var
   hp,p : pchar;
   hp,p : pchar;
 begin
 begin
   Result:='';
   Result:='';
-  p:=GetEnvironmentStrings;
+  p:=GetEnvironmentStringsA;
   hp:=p;
   hp:=p;
   If (Hp<>Nil) then
   If (Hp<>Nil) then
     begin
     begin
@@ -1013,7 +1216,7 @@ begin
     If (hp^<>#0) then
     If (hp^<>#0) then
       Result:=StrPas(HP);
       Result:=StrPas(HP);
     end;
     end;
-  FreeEnvironmentStrings(p);
+  FreeEnvironmentStringsA(p);
 end;
 end;
 
 
 {$pop}
 {$pop}
@@ -1048,7 +1251,7 @@ begin
 
 
   ExecInherits:=ExecInheritsHandles in Flags;
   ExecInherits:=ExecInheritsHandles in Flags;
 
 
-  if not CreateProcess(nil, pchar(CommandLine),
+  if not CreateProcessA(nil, pchar(CommandLine),
     Nil, Nil, ExecInherits,$20, Nil, Nil, SI, PI) then
     Nil, Nil, ExecInherits,$20, Nil, Nil, SI, PI) then
     begin
     begin
       e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
       e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
@@ -1159,7 +1362,7 @@ Procedure InitSysConfigDir;
 
 
 begin
 begin
   SetLength(SysConfigDir, MAX_PATH);
   SetLength(SysConfigDir, MAX_PATH);
-  SetLength(SysConfigDir, GetWindowsDirectory(PChar(SysConfigDir), MAX_PATH));
+  SetLength(SysConfigDir, GetWindowsDirectoryA(PChar(SysConfigDir), MAX_PATH));
 end;
 end;
 
 
 {****************************************************************************
 {****************************************************************************
@@ -1211,7 +1414,7 @@ function Win32AnsiUpperCase(const s: string): string;
       begin
       begin
         result:=s;
         result:=s;
         UniqueString(result);
         UniqueString(result);
-        CharUpperBuff(pchar(result),length(result));
+        CharUpperBuffA(pchar(result),length(result));
       end
       end
     else
     else
       result:='';
       result:='';
@@ -1224,7 +1427,7 @@ function Win32AnsiLowerCase(const s: string): string;
       begin
       begin
         result:=s;
         result:=s;
         UniqueString(result);
         UniqueString(result);
-        CharLowerBuff(pchar(result),length(result));
+        CharLowerBuffA(pchar(result),length(result));
       end
       end
     else
     else
       result:='';
       result:='';
@@ -1233,52 +1436,52 @@ function Win32AnsiLowerCase(const s: string): string;
 
 
 function Win32AnsiCompareStr(const S1, S2: string): PtrInt;
 function Win32AnsiCompareStr(const S1, S2: string): PtrInt;
   begin
   begin
-    result:=CompareString(LOCALE_USER_DEFAULT,0,pchar(s1),length(s1),
+    result:=CompareStringA(LOCALE_USER_DEFAULT,0,pchar(s1),length(s1),
       pchar(s2),length(s2))-2;
       pchar(s2),length(s2))-2;
   end;
   end;
 
 
 
 
 function Win32AnsiCompareText(const S1, S2: string): PtrInt;
 function Win32AnsiCompareText(const S1, S2: string): PtrInt;
   begin
   begin
-    result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,pchar(s1),length(s1),
+    result:=CompareStringA(LOCALE_USER_DEFAULT,NORM_IGNORECASE,pchar(s1),length(s1),
       pchar(s2),length(s2))-2;
       pchar(s2),length(s2))-2;
   end;
   end;
 
 
 
 
 function Win32AnsiStrComp(S1, S2: PChar): PtrInt;
 function Win32AnsiStrComp(S1, S2: PChar): PtrInt;
   begin
   begin
-    result:=CompareString(LOCALE_USER_DEFAULT,0,s1,-1,s2,-1)-2;
+    result:=CompareStringA(LOCALE_USER_DEFAULT,0,s1,-1,s2,-1)-2;
   end;
   end;
 
 
 
 
 function Win32AnsiStrIComp(S1, S2: PChar): PtrInt;
 function Win32AnsiStrIComp(S1, S2: PChar): PtrInt;
   begin
   begin
-    result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,s1,-1,s2,-1)-2;
+    result:=CompareStringA(LOCALE_USER_DEFAULT,NORM_IGNORECASE,s1,-1,s2,-1)-2;
   end;
   end;
 
 
 
 
 function Win32AnsiStrLComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
 function Win32AnsiStrLComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
   begin
   begin
-    result:=CompareString(LOCALE_USER_DEFAULT,0,s1,maxlen,s2,maxlen)-2;
+    result:=CompareStringA(LOCALE_USER_DEFAULT,0,s1,maxlen,s2,maxlen)-2;
   end;
   end;
 
 
 
 
 function Win32AnsiStrLIComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
 function Win32AnsiStrLIComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
   begin
   begin
-    result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,s1,maxlen,s2,maxlen)-2;
+    result:=CompareStringA(LOCALE_USER_DEFAULT,NORM_IGNORECASE,s1,maxlen,s2,maxlen)-2;
   end;
   end;
 
 
 
 
 function Win32AnsiStrLower(Str: PChar): PChar;
 function Win32AnsiStrLower(Str: PChar): PChar;
   begin
   begin
-    CharLower(str);
+    CharLowerA(str);
     result:=str;
     result:=str;
   end;
   end;
 
 
 
 
 function Win32AnsiStrUpper(Str: PChar): PChar;
 function Win32AnsiStrUpper(Str: PChar): PChar;
   begin
   begin
-    CharUpper(str);
+    CharUpperA(str);
     result:=str;
     result:=str;
   end;
   end;
 
 

+ 9 - 2
rtl/win/syswin.inc

@@ -230,15 +230,22 @@ const
     paramcount := argc - 1;
     paramcount := argc - 1;
   end;
   end;
 
 
-  function paramstr(l : longint) : string;
+{$ifdef xFPC_UNICODE_RTL}
+  function paramstr(l : longint) : unicodestring;
+{$else}
+  function paramstr(l : longint) : rawbytestring;
+{$endif}
   begin
   begin
     if (l>=0) and (l<argc) then
     if (l>=0) and (l<argc) then
+{$ifdef FPC_UNICODE_RTL}
+      paramstr:=(argv[l])
+{$else}
       paramstr:=strpas(argv[l])
       paramstr:=strpas(argv[l])
+{$endif}
     else
     else
       paramstr:='';
       paramstr:='';
   end;
   end;
 
 
-
   procedure randomize;
   procedure randomize;
   begin
   begin
     randseed:=GetTickCount;
     randseed:=GetTickCount;

+ 6 - 3
rtl/win/windirs.pp

@@ -59,8 +59,11 @@ uses
   sysutils;
   sysutils;
 
 
 Type
 Type
+{$ifdef FPC_UNICODE_RTL}
+  PFNSHGetFolderPath = Function(Ahwnd: HWND; Csidl: Integer; Token: THandle; Flags: DWord; Path: {$ifdef FPC_UNICODE_RTL}PWideChar{$ELSE}PChar{$ENDIF}): HRESULT; stdcall;
+{$else}
   PFNSHGetFolderPath = Function(Ahwnd: HWND; Csidl: Integer; Token: THandle; Flags: DWord; Path: PChar): HRESULT; stdcall;
   PFNSHGetFolderPath = Function(Ahwnd: HWND; Csidl: Integer; Token: THandle; Flags: DWord; Path: PChar): HRESULT; stdcall;
-
+{$endif}
 
 
 var
 var
   SHGetFolderPath : PFNSHGetFolderPath = Nil;
   SHGetFolderPath : PFNSHGetFolderPath = Nil;
@@ -69,7 +72,7 @@ var
 Procedure InitDLL;
 Procedure InitDLL;
 
 
 Var
 Var
-  pathBuf: array[0..MAX_PATH-1] of char;
+  pathBuf: array[0..MAX_PATH-1] of {$ifdef FPC_UNICODE_RTL}WideChar{$else}char{$endif};
   pathLength: Integer;
   pathLength: Integer;
 begin
 begin
   { Load shfolder.dll using a full path, in order to prevent spoofing (Mantis #18185)
   { Load shfolder.dll using a full path, in order to prevent spoofing (Mantis #18185)
@@ -83,7 +86,7 @@ begin
 
 
     if (CFGDLLHandle<>0) then
     if (CFGDLLHandle<>0) then
     begin
     begin
-      Pointer(ShGetFolderPath):=GetProcAddress(CFGDLLHandle,'SHGetFolderPathA');
+      Pointer(ShGetFolderPath):=GetProcAddress(CFGDLLHandle,{$ifdef FPC_UNICODE_RTL}'SHGetFolderPathW'{$else}'SHGetFolderPathA'{$endif});
       If @ShGetFolderPath=nil then
       If @ShGetFolderPath=nil then
       begin
       begin
         FreeLibrary(CFGDLLHandle);
         FreeLibrary(CFGDLLHandle);