mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-16 04:39:38 +02:00
* Initial FPC_USE_LIBC implementation of termios for Linux.
* Removed VER2_0 defines. git-svn-id: trunk@26189 -
This commit is contained in:
parent
559eb81c07
commit
e93413fae7
@ -5,7 +5,9 @@
|
||||
IOCtl and Termios calls
|
||||
******************************************************************************}
|
||||
|
||||
Function TCGetAttr(fd:cint;var tios:TermIOS):cint; {$ifdef VER2_0}inline;{$endif}
|
||||
{$ifndef FPC_USE_LIBC}
|
||||
|
||||
Function TCGetAttr(fd:cint;var tios:TermIOS):cint; inline;
|
||||
begin
|
||||
TCGetAttr:=fpIOCtl(fd,TCGETS,@tios);
|
||||
end;
|
||||
@ -30,13 +32,13 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal); {$ifdef VER2_0}inline;{$endif}
|
||||
Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal); inline;
|
||||
begin
|
||||
tios.c_cflag:=(tios.c_cflag and (not CBAUD)) or speed;
|
||||
end;
|
||||
|
||||
|
||||
Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal); {$ifdef VER2_0}inline;{$endif}
|
||||
Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal); inline;
|
||||
begin
|
||||
CFSetISpeed(tios,speed);
|
||||
end;
|
||||
@ -58,35 +60,35 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
Function TCSendBreak(fd,duration:cint):cint; {$ifdef VER2_0}inline;{$endif}
|
||||
Function TCSendBreak(fd,duration:cint):cint; inline;
|
||||
begin
|
||||
TCSendBreak:=fpIOCtl(fd,TCSBRK,pointer(ptrint(duration)));
|
||||
end;
|
||||
|
||||
|
||||
Function TCSetPGrp(fd,id:cint):cint; {$ifdef VER2_0}inline;{$endif}
|
||||
Function TCSetPGrp(fd,id:cint):cint; inline;
|
||||
begin
|
||||
TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(ptrint(id)));
|
||||
end;
|
||||
|
||||
|
||||
Function TCGetPGrp(fd:cint;var id:cint):cint; {$ifdef VER2_0}inline;{$endif}
|
||||
Function TCGetPGrp(fd:cint;var id:cint):cint; inline;
|
||||
begin
|
||||
TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
|
||||
end;
|
||||
|
||||
Function TCDrain(fd:cint):cint; {$ifdef VER2_0}inline;{$endif}
|
||||
Function TCDrain(fd:cint):cint; inline;
|
||||
begin
|
||||
TCDrain:=fpIOCtl(fd,TCSBRK,pointer(1));
|
||||
end;
|
||||
|
||||
|
||||
Function TCFlow(fd,act:cint):cint; {$ifdef VER2_0}inline;{$endif}
|
||||
Function TCFlow(fd,act:cint):cint; inline;
|
||||
begin
|
||||
TCFlow:=fpIOCtl(fd,TCXONC,pointer(ptrint(act)));
|
||||
end;
|
||||
|
||||
Function TCFlush(fd,qsel:cint):cint; {$ifdef VER2_0}inline;{$endif}
|
||||
Function TCFlush(fd,qsel:cint):cint; inline;
|
||||
begin
|
||||
TCFlush:=fpIOCtl(fd,TCFLSH,pointer(ptrint(qsel)));
|
||||
end;
|
||||
@ -104,8 +106,7 @@ begin
|
||||
IsAtty:=0;
|
||||
end;
|
||||
|
||||
|
||||
Function IsATTY(var f: text):cint; {$ifdef VER2_0}inline;{$endif}
|
||||
Function IsATTY(var f: text):cint; inline;
|
||||
{
|
||||
Idem as previous, only now for text variables.
|
||||
}
|
||||
@ -113,3 +114,107 @@ begin
|
||||
IsATTY:=IsaTTY(textrec(f).handle);
|
||||
end;
|
||||
|
||||
{$else}
|
||||
// We plan to use FPC_USE_LIBC for Debian/kFreeBSD. This means that we need
|
||||
// to avoid IOCTLs, since those go to the kernel and need to be FreeBSD specific.
|
||||
// -> reroute as much as possible to libc.
|
||||
|
||||
function real_tcsendbreak(fd,duration: cint): cint; cdecl; external name 'tcsendbreak';
|
||||
function real_tcdrain(fd: cint): cint; cdecl; external name 'tcdrain';
|
||||
function real_tcflow(fd,act:cint): cint; cdecl; external name 'tcflow';
|
||||
function real_tcflush(fd,qsel: cint): cint; cdecl; external name 'tcflush';
|
||||
Function real_TCSetAttr(fd:cint;OptAct:cint;constref tios:TermIOS):cint; cdecl; external name 'tcsetattr';
|
||||
Function real_TCGetAttr(fd:cint;var tios:TermIOS):cint; cdecl; external name 'tcgetattr';
|
||||
|
||||
function real_tcgetpgrp(fd:cint):pid_t; cdecl; external name 'tcgetpgrp';
|
||||
function real_tcsetpgrp(fd: cint; pgrp: pid_t): cint; cdecl; external name 'tcsetpgrp';
|
||||
|
||||
Function TCGetAttr(fd:cint;var tios:TermIOS):cint; inline;
|
||||
begin
|
||||
TCGetAttr:=real_tcgetattr(fd,tios);
|
||||
end;
|
||||
|
||||
Function TCSetAttr(fd:cint;OptAct:cint;const tios:TermIOS):cint;
|
||||
begin
|
||||
TCSetAttr:=Real_TCSetAttr(fd,OptAct,tios);
|
||||
end;
|
||||
|
||||
Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal); inline;
|
||||
begin
|
||||
tios.c_cflag:=(tios.c_cflag and (not CBAUD)) or speed;
|
||||
end;
|
||||
|
||||
|
||||
Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal); inline;
|
||||
begin
|
||||
CFSetISpeed(tios,speed);
|
||||
end;
|
||||
|
||||
{ checked against glibc 2.3.3 (FK) }
|
||||
Procedure CFMakeRaw(var tios:TermIOS);
|
||||
begin
|
||||
with tios do
|
||||
begin
|
||||
c_iflag:=c_iflag and (not (IGNBRK or BRKINT or PARMRK or ISTRIP or
|
||||
INLCR or IGNCR or ICRNL or IXON));
|
||||
c_oflag:=c_oflag and (not OPOST);
|
||||
c_lflag:=c_lflag and (not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
|
||||
c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or CS8;
|
||||
c_cc[VMIN]:=1;
|
||||
c_cc[VTIME]:=0;
|
||||
end;
|
||||
end;
|
||||
|
||||
Function TCSendBreak(fd,duration:cint):cint; inline;
|
||||
begin
|
||||
TCSendBreak:=real_tcsendbreak(fd,duration);
|
||||
end;
|
||||
|
||||
Function TCSetPGrp(fd,id:cint):cint; inline;
|
||||
begin
|
||||
TCSetPGrp:=real_tcsetpgrp(fd,id);;
|
||||
end;
|
||||
|
||||
Function TCGetPGrp(fd:cint;var id:cint):cint; inline;
|
||||
begin
|
||||
id:=real_tcgetpgrp(fd);
|
||||
tcgetpgrp:=id;
|
||||
end;
|
||||
|
||||
Function TCDrain(fd:cint):cint; inline;
|
||||
begin
|
||||
TCDrain:=real_TCDrain(fd);
|
||||
end;
|
||||
|
||||
|
||||
Function TCFlow(fd,act:cint):cint; inline;
|
||||
begin
|
||||
TCFlow:=real_tcflow(fd,act);
|
||||
end;
|
||||
|
||||
Function TCFlush(fd,qsel:cint):cint; inline;
|
||||
begin
|
||||
TCFlush:=real_tcflush(fd,qsel);
|
||||
end;
|
||||
|
||||
Function IsATTY (Handle:cint):cint;
|
||||
{
|
||||
Check if the filehandle described by 'handle' is a TTY (Terminal)
|
||||
}
|
||||
var
|
||||
t : Termios;
|
||||
begin
|
||||
if TCGetAttr(Handle,t)=0 then
|
||||
IsAtty:=1
|
||||
else
|
||||
IsAtty:=0;
|
||||
end;
|
||||
|
||||
Function IsATTY(var f: text):cint; inline;
|
||||
{
|
||||
Idem as previous, only now for text variables.
|
||||
}
|
||||
begin
|
||||
IsATTY:=IsaTTY(textrec(f).handle);
|
||||
end;
|
||||
{$endif}
|
||||
|
Loading…
Reference in New Issue
Block a user