Browse Source

* stream functions converted to work without linuxerror

marco 22 years ago
parent
commit
4b8e3387a7
1 changed files with 31 additions and 40 deletions
  1. 31 40
      rtl/unix/unix.pp

+ 31 - 40
rtl/unix/unix.pp

@@ -199,8 +199,8 @@ Function  PClose(Var F:file) : cint;
 Function  POpen(var F:text;const Prog:String;rw:char):cint;
 Function  POpen(var F:text;const Prog:String;rw:char):cint;
 Function  POpen(var F:file;const Prog:String;rw:char):cint;
 Function  POpen(var F:file;const Prog:String;rw:char):cint;
 
 
-function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : longint;
-function AssignStream(var StreamIn, StreamOut, StreamErr: Text; const prog: String): LongInt;
+function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : cint;
+function AssignStream(var StreamIn, StreamOut, StreamErr: Text; const prog: String): cint;
 
 
 {$ifndef BSD}
 {$ifndef BSD}
 Function  GetDomainName:String;
 Function  GetDomainName:String;
@@ -855,7 +855,6 @@ Function AssignPipe(var pipe_in,pipe_out:text):cint;
 {
 {
   Sets up a pair of file variables, which act as a pipe. The first one can
   Sets up a pair of file variables, which act as a pipe. The first one can
   be read from, the second one can be written to.
   be read from, the second one can be written to.
-  If the operation was unsuccesful, linuxerror is set.
 }
 }
 var
 var
   f_in,f_out : longint;
   f_in,f_out : longint;
@@ -1020,7 +1019,6 @@ begin
      exit(-1);
      exit(-1);
    end;
    end;
   ret:=AssignPipe(pipi,pipo);
   ret:=AssignPipe(pipi,pipo);
-
   if ret=-1 then
   if ret=-1 then
    exit(-1);
    exit(-1);
   pid:=fpfork;
   pid:=fpfork;
@@ -1082,7 +1080,7 @@ begin
  POpen:=0;
  POpen:=0;
 end;
 end;
 
 
-Function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : longint;
+Function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : cint;
 {
 {
   Starts the program in 'Prog' and makes its input and output the
   Starts the program in 'Prog' and makes its input and output the
   other end of two pipes, which are the stdin and stdout of a program
   other end of two pipes, which are the stdin and stdout of a program
@@ -1100,16 +1098,13 @@ var
   pid  : longint;
   pid  : longint;
   pl   : ^Longint;
   pl   : ^Longint;
 begin
 begin
-  LinuxError:=0;
   AssignStream:=-1;
   AssignStream:=-1;
-  AssignPipe(streamin,pipo);
-  if Linuxerror<>0 then
-   exit;
-  AssignPipe(pipi,streamout);
-  if Linuxerror<>0 then
-   exit;
+  if AssignPipe(streamin,pipo)=-1 Then
+   exit(-1);
+  if AssignPipe(pipi,streamout)=-1 Then // shouldn't this close streamin and pipo?
+   exit(-1);
   pid:=fpfork;
   pid:=fpfork;
-  if linuxerror<>0 then
+  if pid=-1 then
    begin
    begin
      close(pipi);
      close(pipi);
      close(pipo);
      close(pipo);
@@ -1123,12 +1118,10 @@ begin
      { Close what we don't need }
      { Close what we don't need }
      close(streamout);
      close(streamout);
      close(streamin);
      close(streamin);
-     fpdup2(pipi,input);
-     if linuxerror<>0 then
+     if fpdup2(pipi,input)=-1 Then
       halt(127);
       halt(127);
      close(pipi);
      close(pipi);
-     fpdup2(pipo,output);
-     if linuxerror<>0 then
+     If fpdup2(pipo,output)=-1 Then
        halt (127);
        halt (127);
      close(pipo);
      close(pipo);
      Execl(Prog);
      Execl(Prog);
@@ -1169,40 +1162,39 @@ var
   pid: LongInt;
   pid: LongInt;
   pl: ^LongInt;
   pl: ^LongInt;
 begin
 begin
-  LinuxError := 0;
   AssignStream := -1;
   AssignStream := -1;
 
 
   // Assign pipes
   // Assign pipes
-  AssignPipe(StreamIn, PipeOut);
-  if LinuxError <> 0 then exit;
+  if AssignPipe(StreamIn, PipeOut)=-1 Then
+   Exit(-1);
 
 
-  AssignPipe(StreamErr, PipeErr);
-  if LinuxError <> 0 then begin
+  If AssignPipe(StreamErr, PipeErr)=-1 Then
+  begin
     Close(StreamIn);
     Close(StreamIn);
     Close(PipeOut);
     Close(PipeOut);
-    exit;
+    exit(-1);
   end;
   end;
 
 
-  AssignPipe(PipeIn, StreamOut);
-  if LinuxError <> 0 then begin
+  if AssignPipe(PipeIn, StreamOut)=-1 Then
+  begin
     Close(StreamIn);
     Close(StreamIn);
     Close(PipeOut);
     Close(PipeOut);
     Close(StreamErr);
     Close(StreamErr);
     Close(PipeErr);
     Close(PipeErr);
-    exit;
+    exit(-1);
   end;
   end;
 
 
   // Fork
   // Fork
 
 
   pid := fpFork;
   pid := fpFork;
-  if LinuxError <> 0 then begin
+  if pid=-1 then begin
     Close(StreamIn);
     Close(StreamIn);
     Close(PipeOut);
     Close(PipeOut);
     Close(StreamErr);
     Close(StreamErr);
     Close(PipeErr);
     Close(PipeErr);
     Close(PipeIn);
     Close(PipeIn);
     Close(StreamOut);
     Close(StreamOut);
-    exit;
+    exit(-1);
   end;
   end;
 
 
   if pid = 0 then begin
   if pid = 0 then begin
@@ -1212,14 +1204,14 @@ begin
     Close(StreamIn);
     Close(StreamIn);
     Close(StreamErr);
     Close(StreamErr);
     // Connect pipes
     // Connect pipes
-    fpdup2(PipeIn, Input);
-    if LinuxError <> 0 then Halt(127);
+    if fpdup2(PipeIn, Input)=-1 Then
+     Halt(127);
     Close(PipeIn);
     Close(PipeIn);
-    fpdup2(PipeOut, Output);
-    if LinuxError <> 0 then Halt(127);
+    if fpdup2(PipeOut, Output)=-1 Then
+     Halt(127);
     Close(PipeOut);
     Close(PipeOut);
-    fpdup2(PipeErr, StdErr);
-    if LinuxError <> 0 then Halt(127);
+    if fpdup2(PipeErr, StdErr)=-1 Then
+     Halt(127);
     Close(PipeErr);
     Close(PipeErr);
     // Execute program
     // Execute program
     Execl(Prog);
     Execl(Prog);
@@ -1259,8 +1251,6 @@ Function GetDomainName:String;  { linux only!}
 Var
 Var
   Sysn : utsname;
   Sysn : utsname;
 begin
 begin
-//  fpUname(Sysn);
-//  linuxerror:=fpgeterrno;;
   If fpUname(sysn)<>0 then
   If fpUname(sysn)<>0 then
    getdomainname:=''
    getdomainname:=''
   else
   else
@@ -1275,9 +1265,7 @@ Function GetHostName:String;
 Var
 Var
   Sysn : utsname;
   Sysn : utsname;
 begin
 begin
-  fpuname(Sysn);
-  linuxerror:=fpgeterrno;;
-  If linuxerror<>0 then
+  If fpuname(sysn)=-1 then
    gethostname:=''
    gethostname:=''
   else
   else
    gethostname:=strpas(@Sysn.nodename[0]);
    gethostname:=strpas(@Sysn.nodename[0]);
@@ -1735,7 +1723,10 @@ End.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.45  2003-11-13 18:44:06  marco
+  Revision 1.46  2003-11-14 16:44:48  marco
+   * stream functions converted to work without linuxerror
+
+  Revision 1.45  2003/11/13 18:44:06  marco
    * small fi
    * small fi
 
 
   Revision 1.44  2003/11/12 22:19:45  marco
   Revision 1.44  2003/11/12 22:19:45  marco