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

git-svn-id: trunk@46863 -
This commit is contained in:
Tomas Hajny 2020-09-13 22:08:18 +00:00
parent 2c54477807
commit 288c7e3c9e
12 changed files with 72 additions and 63 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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:

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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}

View File

@ -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;

View File

@ -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;

View File

@ -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;