浏览代码

* unicode executeprocess from work during Lazarus convention in IJsselstein

git-svn-id: trunk@33290 -
marco 9 年之前
父节点
当前提交
66608fec02

+ 10 - 10
rtl/amicommon/sysutils.pp

@@ -837,11 +837,11 @@ begin
   Result:=Dos.EnvStr(Index);
   Result:=Dos.EnvStr(Index);
 end;
 end;
 
 
-function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString;Flags:TExecuteFlags=[]):
+function ExecuteProcess (const Path: RawByteString; const ComLine: RawByteString;Flags:TExecuteFlags=[]):
                                                                        integer;
                                                                        integer;
 var
 var
-  tmpPath: AnsiString;
-  convPath: AnsiString;
+  tmpPath,
+  convPath: RawByteString;
   CommandLine: AnsiString;
   CommandLine: AnsiString;
   tmpLock: longint;
   tmpLock: longint;
 
 
@@ -849,8 +849,8 @@ var
 begin
 begin
   DosError:= 0;
   DosError:= 0;
   
   
-  convPath:=PathConv(Path);
-  tmpPath:=convPath+' '+ComLine;
+  convPath:=PathConv((ToSingleByteFileSystemEncodedFileName(Path));
+  tmpPath:=convPath+' '+ToSingleByteFileSystemEncodedFileName(ComLine);
   
   
   { Here we must first check if the command we wish to execute }
   { Here we must first check if the command we wish to execute }
   { actually exists, because this is NOT handled by the        }
   { actually exists, because this is NOT handled by the        }
@@ -883,19 +883,19 @@ begin
   end;
   end;
 end;
 end;
 
 
-function ExecuteProcess (const Path: AnsiString;
-                                  const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
+function ExecuteProcess (const Path: RawByteString;
+                                  const ComLine: array of RawByteString;Flags:TExecuteFlags=[]): integer;
 var
 var
-  CommandLine: AnsiString;
+  CommandLine: RawByteString;
   I: integer;
   I: integer;
 
 
 begin
 begin
   Commandline := '';
   Commandline := '';
   for I := 0 to High (ComLine) do
   for I := 0 to High (ComLine) do
    if Pos (' ', ComLine [I]) <> 0 then
    if Pos (' ', ComLine [I]) <> 0 then
-    CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
+    CommandLine := CommandLine + ' ' + '"' + ToSingleByteFileSystemEncodedFileName(ComLine [I]) + '"'
    else
    else
-    CommandLine := CommandLine + ' ' + Comline [I];
+    CommandLine := CommandLine + ' ' + ToSingleByteFileSystemEncodedFileName(Comline [I]);
   ExecuteProcess := ExecuteProcess (Path, CommandLine);
   ExecuteProcess := ExecuteProcess (Path, CommandLine);
 end;
 end;
 
 

+ 4 - 2
rtl/objpas/sysutils/osutilsh.inc

@@ -29,8 +29,10 @@ Function GetEnvironmentVariableCount : Integer;
 {$IFDEF HAS_SLEEP}
 {$IFDEF HAS_SLEEP}
 procedure Sleep(milliseconds: Cardinal);
 procedure Sleep(milliseconds: Cardinal);
 {$ENDIF}
 {$ENDIF}
-function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
-function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString;Flags:TExecuteFlags=[]):integer;
+function ExecuteProcess(Const Path: RawByteString; Const ComLine: RawByteString;Flags:TExecuteFlags=[]):integer;
+function ExecuteProcess(Const Path: RawByteString; Const ComLine: Array of RawByteString;Flags:TExecuteFlags=[]):integer;
+function ExecuteProcess(Const Path: UnicodeString; Const ComLine: UnicodeString;Flags:TExecuteFlags=[]):integer;
+function ExecuteProcess(Const Path: UnicodeString; Const ComLine: Array of UnicodeString;Flags:TExecuteFlags=[]):integer;
 
 
 Function GetTempDir(Global : Boolean) : String;
 Function GetTempDir(Global : Boolean) : String;
 Function GetTempDir : String;
 Function GetTempDir : String;

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

@@ -751,3 +751,21 @@ begin
     OnBeep;
     OnBeep;
 end;
 end;
 
 
+// OSes that only provide 1 byte versions can enable the following define
+{$ifdef executeprocuni}
+function ExecuteProcess(Const Path: UnicodeString; Const ComLine: UnicodeString;Flags:TExecuteFlags=[]):integer;
+begin
+  result:=ExecuteProcess(ToSingleByteFileSystemEncodedFileName(Path),ToSingleByteFileSystemEncodedFileName(ComLine));
+end;
+
+function ExecuteProcess(Const Path: UnicodeString; Const ComLine: Array of UnicodeString;Flags:TExecuteFlags=[]):integer;
+var 
+  ComLineA : array of RawByteString;
+  I        : Integer;
+begin
+  SetLength(ComLineA,high(comline)-low(comline)+1);
+  For I:=0 to length(ComLineA)-1 Do
+    ComLineA[i]:=ToSingleByteFileSystemEncodedFileName(ComLine[I]);
+  result:=ExecuteProcess(ToSingleByteFileSystemEncodedFileName(Path),ComLineA);
+end;
+{$endif}

+ 2 - 2
rtl/unix/dos.pp

@@ -312,7 +312,7 @@ Procedure Exec (Const Path: PathStr; Const ComLine: ComStr);
 var
 var
   pid      : longint; // pid_t?
   pid      : longint; // pid_t?
   cmdline2 : ppchar;
   cmdline2 : ppchar;
-  commandline : ansistring;
+  commandline : RawByteString;
   realpath : ansistring;
   realpath : ansistring;
 
 
 // The Error-Checking in the previous Version failed, since halt($7F) gives an WaitPid-status of $7F00
 // The Error-Checking in the previous Version failed, since halt($7F) gives an WaitPid-status of $7F00
@@ -330,7 +330,7 @@ Begin
      realpath:=path;
      realpath:=path;
      if Comline<>'' Then
      if Comline<>'' Then
        begin
        begin
-         CommandLine:=ComLine;  // conversion must live till after fpexec!
+         CommandLine:=ToSingleByteFileSystemEncodedFileName(ComLine);  // conversion must live till after fpexec!
          cmdline2:=StringtoPPChar(CommandLine,1);
          cmdline2:=StringtoPPChar(CommandLine,1);
          cmdline2^:=pchar(realPath);
          cmdline2^:=pchar(realPath);
        end
        end

+ 1 - 1
rtl/unix/genfunch.inc

@@ -16,6 +16,6 @@
 
 
 function CreateShellArgV(const prog:string):ppchar; deprecated;
 function CreateShellArgV(const prog:string):ppchar; deprecated;
 
 
-function CreateShellArgV(const prog:Ansistring):ppchar; deprecated;
+function CreateShellArgV(const prog:RawByteString):ppchar; deprecated;
 
 
 procedure FreeShellArgV(p:ppchar); deprecated;
 procedure FreeShellArgV(p:ppchar); deprecated;

+ 1 - 1
rtl/unix/genfuncs.inc

@@ -42,7 +42,7 @@ begin
   CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog));
   CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog));
 end;
 end;
 
 
-function CreateShellArgV(const prog:Ansistring):ppchar;
+function CreateShellArgV(const prog:RawByteString):ppchar;
 {
 {
   Create an argv which executes a command in a shell using /bin/sh -c
   Create an argv which executes a command in a shell using /bin/sh -c
   using a AnsiString;
   using a AnsiString;

+ 18 - 11
rtl/unix/sysutils.pp

@@ -280,6 +280,8 @@ procedure UnhookSignal(RtlSigNum: Integer; OnlyIfHooked: Boolean = True);
 {$DEFINE FPC_FEXPAND_GETENVPCHAR} { GetEnv result is a PChar }
 {$DEFINE FPC_FEXPAND_GETENVPCHAR} { GetEnv result is a PChar }
 
 
 { Include platform independent implementation part }
 { Include platform independent implementation part }
+
+{$define executeprocuni}
 {$i sysutils.inc}
 {$i sysutils.inc}
 
 
 { Include SysCreateGUID function }
 { Include SysCreateGUID function }
@@ -1291,11 +1293,12 @@ begin
 end;
 end;
 
 
 
 
-function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
+function ExecuteProcess(Const Path: RawByteString; Const ComLine: RawByteString;Flags:TExecuteFlags=[]):integer;
 var
 var
   pid    : longint;
   pid    : longint;
   e      : EOSError;
   e      : EOSError;
-  CommandLine: AnsiString;
+  CommandLine: RawByteString;
+  LPath  : RawByteString;
   cmdline2 : ppchar;
   cmdline2 : ppchar;
 
 
 Begin
 Begin
@@ -1306,19 +1309,24 @@ Begin
 
 
    // Only place we still parse
    // Only place we still parse
    cmdline2:=nil;
    cmdline2:=nil;
+   LPath:=Path;
+   UniqueString(LPath);
+   SetCodePage(LPath,DefaultFileSystemCodePage,true);
    if Comline<>'' Then
    if Comline<>'' Then
      begin
      begin
        CommandLine:=ComLine;
        CommandLine:=ComLine;
+
        { Make an unique copy because stringtoppchar modifies the
        { Make an unique copy because stringtoppchar modifies the
-         string }
+         string, and force conversion to intended fscp }
        UniqueString(CommandLine);
        UniqueString(CommandLine);
+       SetCodePage(CommandLine,DefaultFileSystemCodePage,true);
        cmdline2:=StringtoPPChar(CommandLine,1);
        cmdline2:=StringtoPPChar(CommandLine,1);
-       cmdline2^:=pchar(pointer(Path));
+       cmdline2^:=pchar(pointer(LPath));
      end
      end
    else
    else
      begin
      begin
        getmem(cmdline2,2*sizeof(pchar));
        getmem(cmdline2,2*sizeof(pchar));
-       cmdline2^:=pchar(Path);
+       cmdline2^:=pchar(LPath);
        cmdline2[1]:=nil;
        cmdline2[1]:=nil;
      end;
      end;
 
 
@@ -1330,14 +1338,14 @@ Begin
   if pid=0 then
   if pid=0 then
    begin
    begin
    {The child does the actual exec, and then exits}
    {The child does the actual exec, and then exits}
-      fpexecv(pchar(pointer(Path)),Cmdline2);
+      fpexecv(pchar(pointer(LPath)),Cmdline2);
      { If the execve fails, we return an exitvalue of 127, to let it be known}
      { If the execve fails, we return an exitvalue of 127, to let it be known}
      fpExit(127);
      fpExit(127);
    end
    end
   else
   else
    if pid=-1 then         {Fork failed}
    if pid=-1 then         {Fork failed}
     begin
     begin
-      e:=EOSError.CreateFmt(SExecuteProcessFailed,[Path,-1]);
+      e:=EOSError.CreateFmt(SExecuteProcessFailed,[LPath,-1]);
       e.ErrorCode:=-1;
       e.ErrorCode:=-1;
       raise e;
       raise e;
     end;
     end;
@@ -1350,18 +1358,17 @@ Begin
 
 
   if (result<0) or (result=127) then
   if (result<0) or (result=127) then
     begin
     begin
-    E:=EOSError.CreateFmt(SExecuteProcessFailed,[Path,result]);
+    E:=EOSError.CreateFmt(SExecuteProcessFailed,[LPath,result]);
     E.ErrorCode:=result;
     E.ErrorCode:=result;
     Raise E;
     Raise E;
     end;
     end;
 End;
 End;
 
 
-function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array Of AnsiString;Flags:TExecuteFlags=[]):integer;
+function ExecuteProcess(Const Path: RawByteString; Const ComLine: Array Of RawByteString;Flags:TExecuteFlags=[]):integer;
 
 
 var
 var
   pid    : longint;
   pid    : longint;
-  e : EOSError;
-
+  e      : EOSError;
 Begin
 Begin
   pid:=fpFork;
   pid:=fpFork;
   if pid=0 then
   if pid=0 then

+ 69 - 40
rtl/unix/unix.pp

@@ -70,15 +70,15 @@ Procedure ReReadLocalTime;
 
 
 {**  Process Handling  **}
 {**  Process Handling  **}
 
 
-function FpExecLE (Const PathName:AnsiString;const S:Array Of AnsiString;MyEnv:ppchar):cint;
-function FpExecL  (Const PathName:AnsiString;const S:Array Of AnsiString):cint;
-function FpExecLP (Const PathName:AnsiString;const S:Array Of AnsiString):cint;
-function FpExecLPE(Const PathName:AnsiString;const S:Array Of AnsiString;env:ppchar):cint;
-function FpExecV  (Const PathName:AnsiString;args:ppchar):cint;
-function FpExecVP (Const PathName:AnsiString;args:ppchar):cint;
-function FpExecVPE(Const PathName:AnsiString;args,env:ppchar):cint;
+function FpExecLE (Const PathName:RawByteString;const S:Array Of RawByteString;MyEnv:ppchar):cint;
+function FpExecL  (Const PathName:RawByteString;const S:Array Of RawByteString):cint;
+function FpExecLP (Const PathName:RawByteString;const S:Array Of RawByteString):cint;
+function FpExecLPE(Const PathName:RawByteString;const S:Array Of RawByteString;env:ppchar):cint;
+function FpExecV  (Const PathName:RawByteString;args:ppchar):cint;
+function FpExecVP (Const PathName:RawByteString;args:ppchar):cint;
+function FpExecVPE(Const PathName:RawByteString;args,env:ppchar):cint;
 
 
-Function fpSystem(const Command:AnsiString):cint;
+Function fpSystem(const Command:RawByteString):cint;
 
 
 Function WaitProcess (Pid:cint):cint; 
 Function WaitProcess (Pid:cint):cint; 
 
 
@@ -116,8 +116,10 @@ Type
                            CurrentDirectoryFirst,
                            CurrentDirectoryFirst,
                            CurrentDirectoryLast);
                            CurrentDirectoryLast);
 
 
-Function  FSearch  (const path:AnsiString;dirlist:Ansistring;CurrentDirStrategy:TFSearchOption):AnsiString;
-Function  FSearch  (const path:AnsiString;dirlist:AnsiString):AnsiString;
+Function  FSearch  (const path:RawByteString;dirlist:RawByteString;CurrentDirStrategy:TFSearchOption):RawByteString;
+Function  FSearch  (const path:RawByteString;dirlist:RawByteString):RawByteString;
+Function  FSearch  (const path:UnicodeString;dirlist:UnicodeString;CurrentDirStrategy:TFSearchOption):UnicodeString;
+Function  FSearch  (const path:UnicodeString;dirlist:UnicodeString):UnicodeString;
 
 
 {$ifdef FPC_USE_LIBC}
 {$ifdef FPC_USE_LIBC}
   const clib = 'c';
   const clib = 'c';
@@ -179,14 +181,14 @@ begin
    end;
    end;
 end;
 end;
 
 
-function intFpExecVEMaybeP (Const PathName:AnsiString;Args,MyEnv:ppchar;SearchPath:Boolean):cint;
+function intFpExecVEMaybeP (Const PathName:RawByteString;Args,MyEnv:ppchar;SearchPath:Boolean):cint;
 // does an ExecVE, but still has to handle P
 // does an ExecVE, but still has to handle P
 // execv variants call this directly, execl variants indirectly via
 // execv variants call this directly, execl variants indirectly via
 //     intfpexecl
 //     intfpexecl
 
 
 Var
 Var
-  NewCmd  : ansistring;
-  ThePath : AnsiString;
+  NewCmd  : RawByteString;
+  ThePath : RawByteString;
 
 
 Begin
 Begin
   If SearchPath and (pos('/',pathname)=0) Then
   If SearchPath and (pos('/',pathname)=0) Then
@@ -196,19 +198,21 @@ Begin
       // Stevens says only search if newcmd contains no '/'
       // Stevens says only search if newcmd contains no '/'
       // fsearch is not ansistring clean yet.
       // fsearch is not ansistring clean yet.
       ThePath:=fpgetenv('PATH');
       ThePath:=fpgetenv('PATH');
+      SetCodePage(ThePath,DefaultSystemCodePage,false);
+      SetCodePage(ThePath,DefaultFileSystemCodePage,true);
       if thepath='' then
       if thepath='' then
         thepath:='.';     // FreeBSD uses _PATH_DEFPATH = /usr/bin:/bin
         thepath:='.';     // FreeBSD uses _PATH_DEFPATH = /usr/bin:/bin
                           // but a quick check showed that _PATH_DEFPATH
                           // but a quick check showed that _PATH_DEFPATH
                           // varied from OS to OS
                           // varied from OS to OS
 
 
-      newcmd:=FSearch(pathname,thepath,NoCurrentDirectory);
+      newcmd:=ToSingleByteFileSystemEncodedFileName(FSearch(pathname,thepath,NoCurrentDirectory));
       // FreeBSD libc keeps on trying till a file is successfully run.
       // FreeBSD libc keeps on trying till a file is successfully run.
       // Stevens says "try each path prefix"
       // Stevens says "try each path prefix"
 
 
       // execp puts newcmd here.
       // execp puts newcmd here.
         args^:=pchar(newcmd);
         args^:=pchar(newcmd);
    End else
    End else
-      newcmd:=pathname;
+      newcmd:=ToSingleByteFileSystemEncodedFileName(pathname);
  // repeat
  // repeat
 //      if searchpath then args^:=pchar(commandtorun)
 //      if searchpath then args^:=pchar(commandtorun)
 
 
@@ -218,10 +222,9 @@ Begin
 // Should we deallocate p on fail? -> no fpexit is run no matter what
 // Should we deallocate p on fail? -> no fpexit is run no matter what
 //
 //
 }
 }
-// if intfpexecvemaybep=-1 then zoekvolgende file.
+// if intfpexecvemaybep=-1 then seach next file.
 // until (Goexit) or SearchExit;
 // until (Goexit) or SearchExit;
 
 
-
 {
 {
  If IntFpExec=-1 Then
  If IntFpExec=-1 Then
     Begin
     Begin
@@ -234,19 +237,23 @@ Begin
 }
 }
 end;
 end;
 
 
-function intFpExecl (Const PathName:AnsiString;const s:array of ansistring;MyEnv:ppchar;SearchPath:Boolean):cint;
+function intFpExecl (Const PathName:RawByteString;const s:array of RawByteString;MyEnv:ppchar;SearchPath:Boolean):cint;
 { Handles the array of ansistring -> ppchar conversion.
 { Handles the array of ansistring -> ppchar conversion.
   Base for the the "l" variants.
   Base for the the "l" variants.
 }
 }
 var p:ppchar;
 var p:ppchar;
-
+    i:integer;
+    s2:array of Rawbytestring;
 begin
 begin
   If PathName='' Then
   If PathName='' Then
     Begin
     Begin
       fpsetErrno(ESysEnoEnt);
       fpsetErrno(ESysEnoEnt);
       Exit(-1);                 // Errno?
       Exit(-1);                 // Errno?
     End;
     End;
-  p:=ArrayStringToPPchar(s,1);
+  setlength(s2,high(s)+1);
+  for i:=low(s) to high(s) do
+    s2[i]:=ToSingleByteFileSystemEncodedFileName(s[i]);
+  p:=ArrayStringToPPchar(s2,1);
   if p=NIL Then
   if p=NIL Then
     Begin
     Begin
       GetMem(p,2*sizeof(pchar));
       GetMem(p,2*sizeof(pchar));
@@ -266,44 +273,44 @@ begin
   Freemem(p);
   Freemem(p);
 end;
 end;
 
 
-function FpExecLE (Const PathName:AnsiString;const S:Array Of AnsiString;MyEnv:ppchar):cint;
+function FpExecLE (Const PathName:RawByteString;const S:Array Of RawByteString;MyEnv:ppchar):cint;
 
 
 Begin
 Begin
   FpExecLE:=intFPExecl(PathName,s,MyEnv,false);
   FpExecLE:=intFPExecl(PathName,s,MyEnv,false);
 End;
 End;
 
 
 
 
-function FpExecL(Const PathName:AnsiString;const S:Array Of AnsiString):cint;
+function FpExecL(Const PathName:RawByteString;const S:Array Of RawByteString):cint;
 
 
 Begin
 Begin
   FpExecL:=intFPExecl(PathName,S,EnvP,false);
   FpExecL:=intFPExecl(PathName,S,EnvP,false);
 End;
 End;
 
 
-function FpExecLP(Const PathName:AnsiString;const S:Array Of AnsiString):cint;
+function FpExecLP(Const PathName:RawByteString;const S:Array Of RawByteString):cint;
 
 
 Begin
 Begin
   FpExecLP:=intFPExecl(PathName,S,EnvP,True);
   FpExecLP:=intFPExecl(PathName,S,EnvP,True);
 End;
 End;
 
 
-function FpExecLPE(Const PathName:AnsiString;const S:Array Of AnsiString;env:ppchar):cint;
+function FpExecLPE(Const PathName:RawByteString;const S:Array Of RawByteString;env:ppchar):cint;
 
 
 Begin
 Begin
   FpExecLPE:=intFPExecl(PathName,S,Env,True);
   FpExecLPE:=intFPExecl(PathName,S,Env,True);
 End;
 End;
 
 
-function FpExecV(Const PathName:AnsiString;args:ppchar):cint;
+function FpExecV(Const PathName:RawByteString;args:ppchar):cint;
 
 
 Begin
 Begin
  fpexecV:=intFpExecVEMaybeP (PathName,args,envp,false);
  fpexecV:=intFpExecVEMaybeP (PathName,args,envp,false);
 End;
 End;
 
 
-function FpExecVP(Const PathName:AnsiString;args:ppchar):cint;
+function FpExecVP(Const PathName:RawByteString;args:ppchar):cint;
 
 
 Begin
 Begin
  fpexecVP:=intFpExecVEMaybeP (PathName,args,envp,true);
  fpexecVP:=intFpExecVEMaybeP (PathName,args,envp,true);
 End;
 End;
 
 
-function FpExecVPE(Const PathName:AnsiString;args,env:ppchar):cint;
+function FpExecVPE(Const PathName:RawByteString;args,env:ppchar):cint;
 
 
 Begin
 Begin
  fpexecVPE:=intFpExecVEMaybeP (PathName,args,env,true);
  fpexecVPE:=intFpExecVEMaybeP (PathName,args,env,true);
@@ -322,13 +329,16 @@ End;
 {$ifdef FPC_USE_LIBC}
 {$ifdef FPC_USE_LIBC}
 function xfpsystem(p:pchar):cint; cdecl; external clib name 'system';
 function xfpsystem(p:pchar):cint; cdecl; external clib name 'system';
 
 
-Function fpSystem(const Command:AnsiString):cint;
+Function fpSystem(const Command:RawByteString):cint;
+var
+  cmd: RawByteString;
 begin
 begin
-  fpsystem:=xfpsystem(pchar(command));
+  cmd:=ToSingleByteFileSystemEncodedFileName(Command);
+  fpsystem:=xfpsystem(pchar(cmd));
 end;
 end;
 
 
 {$else}
 {$else}
-Function fpSystem(const Command:AnsiString):cint;
+Function fpSystem(const Command:RawByteString):cint;
 var
 var
   pid,savedpid   : cint;
   pid,savedpid   : cint;
   pstat          : cint;
   pstat          : cint;
@@ -339,8 +349,10 @@ var
  {$ifndef SHELL_USE_FPEXEC}
  {$ifndef SHELL_USE_FPEXEC}
    p      : ppchar;
    p      : ppchar;
  {$endif}
  {$endif}
+  cmd     : RawByteString;
 
 
 begin { Changes as above }
 begin { Changes as above }
+  { fpexec* take care of converting the command to the right code page }
   if command='' then exit(1);
   if command='' then exit(1);
   {$ifndef SHELL_USE_FPEXEC}
   {$ifndef SHELL_USE_FPEXEC}
     p:=CreateShellArgv(command);
     p:=CreateShellArgv(command);
@@ -1126,7 +1138,7 @@ end;
                              Utility calls
                              Utility calls
 ******************************************************************************}
 ******************************************************************************}
 
 
-Function FSearch(const path:AnsiString;dirlist:Ansistring;CurrentDirStrategy:TFSearchOption):AnsiString;
+Function FSearch(const path:RawByteString;dirlist:RawByteString;CurrentDirStrategy:TFSearchOption):RawByteString;
 {
 {
   Searches for a file 'path' in the list of direcories in 'dirlist'.
   Searches for a file 'path' in the list of direcories in 'dirlist'.
   returns an empty string if not found. Wildcards are NOT allowed.
   returns an empty string if not found. Wildcards are NOT allowed.
@@ -1137,17 +1149,18 @@ stringhandling overhead at the same time.
 
 
 }
 }
 Var
 Var
-  mydir,NewDir : ansistring;
+  mypath,
+  mydir,NewDir : RawByteString;
   p1     : cint;
   p1     : cint;
   Info   : Stat;
   Info   : Stat;
   i,j      : cint;
   i,j      : cint;
   p      : pchar;
   p      : pchar;
 Begin
 Begin
-
+ SetCodePage(dirlist,DefaultFileSystemCodePage);
  if CurrentDirStrategy=CurrentDirectoryFirst Then
  if CurrentDirStrategy=CurrentDirectoryFirst Then
-     Dirlist:='.:'+dirlist;             {Make sure current dir is first to be searched.}
- if CurrentDirStrategy=CurrentDirectoryLast Then
-     Dirlist:=dirlist+':.';             {Make sure current dir is last to be searched.}
+     Dirlist:=ToSingleByteFileSystemEncodedFileName('.:')+dirlist             {Make sure current dir is first to be searched.}
+ else if CurrentDirStrategy=CurrentDirectoryLast Then
+     Dirlist:=dirlist+ToSingleByteFileSystemEncodedFileName('.:');             {Make sure current dir is last to be searched.}
 
 
 {Replace ':' and ';' with #0}
 {Replace ':' and ';' with #0}
 
 
@@ -1160,14 +1173,19 @@ Begin
    FSearch:='' {No wildcards allowed in these things.}
    FSearch:='' {No wildcards allowed in these things.}
   Else
   Else
    Begin
    Begin
+     mypath:=ToSingleByteFileSystemEncodedFileName(path);
      p:=pchar(dirlist);
      p:=pchar(dirlist);
      i:=length(dirlist);
      i:=length(dirlist);
      j:=1;
      j:=1;
      Repeat
      Repeat
-       mydir:=ansistring(p);
+       mydir:=RawByteString(p);
        if (length(mydir)>0) and (mydir[length(mydir)]<>'/') then
        if (length(mydir)>0) and (mydir[length(mydir)]<>'/') then
-          mydir:=mydir+'/';
-       NewDir:=mydir+Path;
+          begin
+            { concatenate character without influencing code page }
+            setlength(mydir,length(mydir)+1);
+            mydir[length(mydir)]:='/';
+          end;
+       NewDir:=mydir+mypath;
        if (FpStat(NewDir,Info)>=0) and
        if (FpStat(NewDir,Info)>=0) and
           (not fpS_ISDIR(Info.st_Mode)) then
           (not fpS_ISDIR(Info.st_Mode)) then
         Begin
         Begin
@@ -1181,15 +1199,26 @@ Begin
        if p^=#0 then inc(p);
        if p^=#0 then inc(p);
      Until (j>=i) or (Length(NewDir) > 0);
      Until (j>=i) or (Length(NewDir) > 0);
      FSearch:=NewDir;
      FSearch:=NewDir;
+     SetCodePage(FSearch,DefaultRTLFileSystemCodePage);
    End;
    End;
 End;
 End;
 
 
-Function FSearch(const path:AnsiString;dirlist:Ansistring):AnsiString;
 
 
+Function FSearch(const path:RawByteString;dirlist:RawByteString):RawByteString;
 Begin
 Begin
  FSearch:=FSearch(path,dirlist,CurrentDirectoryFirst);
  FSearch:=FSearch(path,dirlist,CurrentDirectoryFirst);
 End;
 End;
 
 
+function FSearch(const path: UnicodeString; dirlist: UnicodeString; CurrentDirStrategy: TFSearchOption): UnicodeString;
+begin
+  FSearch:=FSearch(ToSingleByteFileSystemEncodedFileName(path),ToSingleByteFileSystemEncodedFileName(dirlist),CurrentDirStrategy);
+end;
+
+function FSearch(const path: UnicodeString; dirlist: UnicodeString): UnicodeString;
+begin
+  FSearch:=FSearch(ToSingleByteFileSystemEncodedFileName(path),ToSingleByteFileSystemEncodedFileName(dirlist),CurrentDirectoryFirst);
+end;
+
 Initialization
 Initialization
 {$IFNDEF DONT_READ_TIMEZONE}
 {$IFNDEF DONT_READ_TIMEZONE}
   InitLocalTime;
   InitLocalTime;

+ 4 - 4
rtl/unix/unixutil.pp

@@ -31,8 +31,8 @@ var
   Tzseconds : Longint;
   Tzseconds : Longint;
 
 
 Function StringToPPChar(S: PChar;ReserveEntries:integer):ppchar;
 Function StringToPPChar(S: PChar;ReserveEntries:integer):ppchar;
-Function StringToPPChar(Var S:AnsiString;ReserveEntries:integer):ppchar;
-function ArrayStringToPPchar(const S:Array of AnsiString;reserveentries:Longint):ppchar; // const ?
+Function StringToPPChar(Var S:RawByteString;ReserveEntries:integer):ppchar;
+function ArrayStringToPPchar(const S:Array of RawByteString;reserveentries:Longint):ppchar; // const ?
 Function LocalToEpoch(year,month,day,hour,minute,second:Word):Longint; deprecated 'use DateUtils.DateTimeToUnix';
 Function LocalToEpoch(year,month,day,hour,minute,second:Word):Longint; deprecated 'use DateUtils.DateTimeToUnix';
 Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word); deprecated 'use DateUtils.UnixToDateTime';
 Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word); deprecated 'use DateUtils.UnixToDateTime';
 Procedure JulianToGregorian(JulianDN:LongInt;Var Year,Month,Day:Word); deprecated 'use DateUtils.DateTimetoJulianDate';
 Procedure JulianToGregorian(JulianDN:LongInt;Var Year,Month,Day:Word); deprecated 'use DateUtils.DateTimetoJulianDate';
@@ -40,7 +40,7 @@ Function GregorianToJulian(Year,Month,Day:Longint):LongInt; deprecated 'use Date
 
 
 implementation
 implementation
 
 
-function ArrayStringToPPchar(const S:Array of AnsiString;reserveentries:Longint):ppchar; // const ?
+function ArrayStringToPPchar(const S:Array of RawByteString;reserveentries:Longint):ppchar; // const ?
 // Extra allocate reserveentries pchar's at the beginning (default param=0 after 1.0.x ?)
 // Extra allocate reserveentries pchar's at the beginning (default param=0 after 1.0.x ?)
 // Note: for internal use by skilled programmers only
 // Note: for internal use by skilled programmers only
 // if "s" goes out of scope in the parent procedure, the pointer is dangling.
 // if "s" goes out of scope in the parent procedure, the pointer is dangling.
@@ -64,7 +64,7 @@ begin
   ArrayStringToPPchar:=p;
   ArrayStringToPPchar:=p;
 end;
 end;
 
 
-Function StringToPPChar(Var S:AnsiString;ReserveEntries:integer):ppchar;
+Function StringToPPChar(Var S:RawByteString;ReserveEntries:integer):ppchar;
 {
 {
   Create a PPChar to structure of pchars which are the arguments specified
   Create a PPChar to structure of pchars which are the arguments specified
   in the string S. Especially useful for creating an ArgV for Exec-calls
   in the string S. Especially useful for creating an ArgV for Exec-calls

+ 31 - 8
rtl/win/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
@@ -1110,14 +1110,20 @@ end;
 
 
 {$pop}
 {$pop}
 
 
-function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
+function ExecuteProcess(Const Path: RawByteString; Const ComLine: RawByteString;Flags:TExecuteFlags=[]):integer;
+begin
+  result:=ExecuteProcess(Unicodestring(Path),UnicodeString(ComLine),Flags);
+end;
+
+
+function ExecuteProcess(Const Path: UnicodeString; Const ComLine: UnicodeString;Flags:TExecuteFlags=[]):integer;
 // win specific  function
 // win specific  function
 var
 var
-  SI: TStartupInfo;
+  SI: TStartupInfoW;
   PI: TProcessInformation;
   PI: TProcessInformation;
   Proc : THandle;
   Proc : THandle;
   l    : DWord;
   l    : DWord;
-  CommandLine : ansistring;
+  CommandLine : unicodestring;
   e : EOSError;
   e : EOSError;
   ExecInherits : longbool;
   ExecInherits : longbool;
 begin
 begin
@@ -1140,7 +1146,7 @@ begin
 
 
   ExecInherits:=ExecInheritsHandles in Flags;
   ExecInherits:=ExecInheritsHandles in Flags;
 
 
-  if not CreateProcessA(nil, pchar(CommandLine),
+  if not CreateProcessW(nil, pwidechar(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]);
@@ -1165,10 +1171,27 @@ begin
     end;
     end;
 end;
 end;
 
 
-function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString;Flags:TExecuteFlags=[]):integer;
+
+function ExecuteProcess(Const Path: RawByteString; Const ComLine: Array of RawByteString;Flags:TExecuteFlags=[]):integer;
+
+var
+  CommandLine: UnicodeString;
+  I: integer;
+
+begin
+  Commandline := '';
+  for I := 0 to High (ComLine) do
+   if Pos (' ', ComLine [I]) <> 0 then
+    CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
+   else
+    CommandLine := CommandLine + ' ' + Comline [I];
+  ExecuteProcess := ExecuteProcess (UnicodeString(Path), CommandLine,Flags);
+end;
+
+function ExecuteProcess(Const Path: UnicodeString; Const ComLine: Array of UnicodeString;Flags:TExecuteFlags=[]):integer;
 
 
 var
 var
-  CommandLine: AnsiString;
+  CommandLine: UnicodeString;
   I: integer;
   I: integer;
 
 
 begin
 begin
@@ -1178,7 +1201,7 @@ begin
     CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
     CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
    else
    else
     CommandLine := CommandLine + ' ' + Comline [I];
     CommandLine := CommandLine + ' ' + Comline [I];
-  ExecuteProcess := ExecuteProcess (Path, CommandLine,Flags);
+  ExecuteProcess := ExecuteProcess (Path,CommandLine,Flags);
 end;
 end;
 
 
 Procedure Sleep(Milliseconds : Cardinal);
 Procedure Sleep(Milliseconds : Cardinal);