فهرست منبع

* Do_IsDevice treats pipes and sockets the same way as character devices

git-svn-id: trunk@46863 -
Tomas Hajny 4 سال پیش
والد
کامیت
288c7e3c9e
12فایلهای تغییر یافته به همراه72 افزوده شده و 63 حذف شده
  1. 8 3
      rtl/aix/sysos.inc
  2. 8 11
      rtl/beos/sysos.inc
  3. 7 11
      rtl/bsd/sysos.inc
  4. 1 1
      rtl/emx/sysfile.inc
  5. 8 1
      rtl/gba/sysfile.inc
  6. 8 10
      rtl/haiku/sysos.inc
  7. 7 19
      rtl/linux/sysos.inc
  8. 8 2
      rtl/nds/sysfile.inc
  9. 4 1
      rtl/os2/sysfile.inc
  10. 8 3
      rtl/solaris/sysos.inc
  11. 4 1
      rtl/win/sysfile.inc
  12. 1 0
      rtl/win16/sysfile.inc

+ 8 - 3
rtl/aix/sysos.inc

@@ -96,10 +96,15 @@ end;
 *****************************************************************************}
 
 function do_isdevice(handle:longint):boolean;
+var
+  StatRec: Stat;
 begin
-  do_isdevice:= (handle=StdInputHandle) or
-                (handle=StdOutputHandle) or
-                (handle=StdErrorHandle);
+  fpFStat (Handle, StatRec);
+  case StatRec.st_Mode and S_IFMT of
+   S_IFCHR, S_IFIFO, S_IFSOCK: Do_IsDevice := true
+  else
+   Do_IsDevice := false;
+  end;
 end;
 
 

+ 8 - 11
rtl/beos/sysos.inc

@@ -132,17 +132,14 @@ end;
 *****************************************************************************}
 
 Function Do_IsDevice(Handle:Longint):boolean;
-{
-  Interface to Unix ioctl call.
-  Performs various operations on the filedescriptor Handle.
-  Ndx describes the operation to perform.
-  Data points to data needed for the Ndx function. The structure of this
-  data is function-dependent.
-}
-CONST
-  IOCtl_TCGETS=$5401;
 var
-  Data : array[0..255] of byte; {Large enough for termios info}
+  StatRec: Stat;
 begin
-  Do_IsDevice:=(Fpioctl(handle,IOCTL_TCGETS,@data)<>-1);
+  fpFStat (Handle, StatRec);
+  case StatRec.st_Mode and S_IFMT of
+(* S_IFSOCK supposedly not available under BeOS, thus omitted *)
+   S_IFCHR, S_IFIFO: Do_IsDevice := true
+  else
+   Do_IsDevice := false;
+  end;
 end;

+ 7 - 11
rtl/bsd/sysos.inc

@@ -156,19 +156,15 @@ end;
 *****************************************************************************}
 
 Function Do_IsDevice(Handle:Longint):boolean;
-{
-  Interface to Unix ioctl call.
-  Performs various operations on the filedescriptor Handle.
-  Ndx describes the operation to perform.
-  Data points to data needed for the Ndx function. The structure of this
-  data is function-dependent.
-}
-CONST
-  IOCtl_TCGETS=$40000000+$2C7400+ 19;
 var
-  Data : array[0..255] of byte; {Large enough for termios info}
+  StatRec: Stat;
 begin
-  Do_IsDevice:=(Fpioctl(handle,IOCTL_TCGETS,@data)<>-1);
+  fpFStat (Handle, StatRec);
+  case StatRec.st_Mode and S_IFMT of
+   S_IFCHR, S_IFIFO, S_IFSOCK: Do_IsDevice := true
+  else
+   Do_IsDevice := false;
+  end;
 end;
 
 

+ 1 - 1
rtl/emx/sysfile.inc

@@ -397,7 +397,7 @@ asm
     call syscall
     mov eax, 1
     jc @IsDevEnd
-    test edx, 80h           { verify if it is a file  }
+    test edx, 80h           { bit 7 is set if it is a device or a pipe }
     jnz @IsDevEnd
     dec eax                 { nope, so result is zero }
 @IsDevEnd:

+ 8 - 1
rtl/gba/sysfile.inc

@@ -74,7 +74,14 @@ begin
 end;
 
 function do_isdevice(handle: longint): boolean;
+var
+  StatRec: TStat;
 begin
-  result := false;
+  FStat (Handle, StatRec);
+  case StatRec.st_Mode and _IFMT of
+   _IFCHR, _IFIFO, _IFSOCK: Do_IsDevice := true
+  else
+   Do_IsDevice := false;
+  end;
 end;
 

+ 8 - 10
rtl/haiku/sysos.inc

@@ -108,15 +108,13 @@ end;
 *****************************************************************************}
 
 Function Do_IsDevice(Handle:Longint):boolean;
-{
-  Interface to Unix ioctl call.
-  Performs various operations on the filedescriptor Handle.
-  Ndx describes the operation to perform.
-  Data points to data needed for the Ndx function. The structure of this
-  data is function-dependent.
-}
+var
+  StatRec: Stat;
 begin
-  do_isdevice:= (handle=StdInputHandle) or
-                (handle=StdOutputHandle) or
-                (handle=StdErrorHandle);
+  fpFStat (Handle, StatRec);
+  case StatRec.st_Mode and S_IFMT of
+   S_IFCHR, S_IFIFO, S_IFSOCK: Do_IsDevice := true
+  else
+   Do_IsDevice := false;
+  end;
 end;

+ 7 - 19
rtl/linux/sysos.inc

@@ -137,27 +137,15 @@ end;
 *****************************************************************************}
 
 Function Do_IsDevice(Handle:THandle):boolean;
-{
-  Interface to Unix ioctl call.
-  Performs various operations on the filedescriptor Handle.
-  Ndx describes the operation to perform.
-  Data points to data needed for the Ndx function. The structure of this
-  data is function-dependent.
-}
-const
-{$if defined(cpupowerpc) or defined(cpupowerpc64)}
-  IOCtl_TCGETS=$402c7413;
-{$else}
-{$if defined(cpusparc) or defined(cpusparc64)}
-  IOCtl_TCGETS=$40245408;
-{$else}
-  IOCtl_TCGETS=$5401; // TCGETS is also in termios.inc, but the sysunix needs only this
-{$endif}
-{$endif}
 var
-  Data : array[0..255] of byte; {Large enough for termios info}
+  StatRec: Stat;
 begin
-  Do_IsDevice:=(Fpioctl(handle,IOCTL_TCGETS,@data)<>-1);
+  fpFStat (Handle, StatRec);
+  case StatRec.st_Mode and S_IFMT of
+   S_IFCHR, S_IFIFO, S_IFSOCK: Do_IsDevice := true
+  else
+   Do_IsDevice := false;
+  end;
 end;
 
 

+ 8 - 2
rtl/nds/sysfile.inc

@@ -296,9 +296,15 @@ end;
 
 
 function do_isdevice(handle: THandle): boolean;
+var
+  StatRec: TStat;
 begin
-  //result :=  (isatty(fileno(P_FILE(handle))) > 0);
-  do_isdevice := (_isatty(handle) > 0);
+  FStat (Handle, StatRec);
+  case StatRec.st_Mode and _IFMT of
+   _IFCHR, _IFIFO, _IFSOCK: Do_IsDevice := true
+  else
+   Do_IsDevice := false;
+  end;
 end;
 
 

+ 4 - 1
rtl/os2/sysfile.inc

@@ -343,6 +343,9 @@ function do_isdevice (Handle: THandle): boolean;
 var
   HT, Attr: cardinal;
   RC: cardinal;
+const
+  dhDevice = 1;
+  dhPipe = 2;
 begin
   do_isdevice:=false;
   RC := DosQueryHType(Handle, HT, Attr);
@@ -351,7 +354,7 @@ begin
     OSErrorWatch (RC);
     Exit;
    end;
-  if ht=1 then
+  if (HT = dhDevice) or (HT = dhPipe) then
    do_isdevice:=true;
 end;
 {$ASMMODE ATT}

+ 8 - 3
rtl/solaris/sysos.inc

@@ -97,10 +97,15 @@ end;
 *****************************************************************************}
 
 function do_isdevice(handle:longint):boolean;
+var
+  StatRec: Stat;
 begin
-  do_isdevice:= (handle=StdInputHandle) or
-                (handle=StdOutputHandle) or
-                (handle=StdErrorHandle);
+  fpFStat (Handle, StatRec);
+  case StatRec.st_Mode and S_IFMT of
+   S_IFCHR, S_IFIFO, S_IFSOCK: Do_IsDevice := true
+  else
+   Do_IsDevice := false;
+  end;
 end;
 
 

+ 4 - 1
rtl/win/sysfile.inc

@@ -19,8 +19,11 @@
 *****************************************************************************}
 
 function do_isdevice(handle:thandle):boolean;
+var
+  HT: dword;
 begin
-  do_isdevice:=(handle = StdInputHandle) or (handle = StdOutputHandle) or (handle = StdErrorHandle);
+  HT := GetFileType (Handle);
+  Do_IsDevice := (HT = FILE_TYPE_CHAR) or (HT = FILE_TYPE_PIPE);
 end;
 
 

+ 1 - 0
rtl/win16/sysfile.inc

@@ -404,6 +404,7 @@ function do_isdevice(handle:THandle):boolean;
 var
   regs: Registers;
 begin
+(* Is this explicit check for the first three handles appropriate here??? *)
   if (handle=StdInputHandle) or (handle=StdOutputHandle) or (handle=StdErrorHandle) then
     begin
       do_isdevice:=true;