Seth Woolley's Man Viewer

termios(3) - cfgetispeed, cfgetospeed, cfmakeraw, cfsetispeed, cfsetospeed, tcdrain, tcflow, tcflush, tcgetattr, tcsendbreak, tcsetattr, termios, cfgetispeed, cfgetospeed, cfmakeraw, cfsetispeed, cfsetospeed, cfsetspeed, tcdrain, tcflow, tcflush, tcgetattr, tcsendbreak, tcsetattr, termios - get and set terminal attributes, line control, get and set baud rate - man 3 termios

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

TERMIOS(3)                 Linux Programmer's Manual                TERMIOS(3)



NAME
       termios,  tcgetattr,  tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow,
       cfmakeraw, cfgetospeed, cfgetispeed, cfsetispeed,  cfsetospeed,  cfset-
       speed - get and set(7,n,1 builtins) terminal attributes, line control, get and set(7,n,1 builtins) baud
       rate

SYNOPSIS
       #include <termios.h>
       #include <unistd.h>

       int tcgetattr(int fd, struct termios *termios_p);

       int tcsetattr(int fd, int optional_actions, const struct termios
       *termios_p);

       int tcsendbreak(int fd, int duration);

       int tcdrain(int fd);

       int tcflush(int fd, int queue_selector);

       int tcflow(int fd, int action);

       void cfmakeraw(struct termios *termios_p);

       speed_t cfgetispeed(const struct termios *termios_p);

       speed_t cfgetospeed(const struct termios *termios_p);

       int cfsetispeed(struct termios *termios_p, speed_t speed);

       int cfsetospeed(struct termios *termios_p, speed_t speed);

DESCRIPTION
       The  termios  functions  describe  a general terminal interface that is
       provided to control asynchronous communications ports.

       Many of the functions described here have a termios_p argument that  is
       a pointer to a termios structure.  This structure contains at least the
       following members:

              tcflag_t c_iflag;      /* input modes */
              tcflag_t c_oflag;      /* output modes */
              tcflag_t c_cflag;      /* control modes */
              tcflag_t c_lflag;      /* local modes */
              cc_t c_cc[NCCS];       /* control chars */

       c_iflag flag constants:

       IGNBRK Ignore BREAK condition on input.

       BRKINT If IGNBRK is set(7,n,1 builtins), a BREAK is ignored.  If  it  is  not  set(7,n,1 builtins)  but
              BRKINT  is  set(7,n,1 builtins), then a BREAK causes the input and output queues
              to be flushed, and if(3,n) the terminal is the  controlling  terminal
              of a foreground process group, it will cause a SIGINT to be sent
              to this foreground  process  group.   When  neither  IGNBRK  nor
              BRKINT  are  set(7,n,1 builtins),  a BREAK reads as a NUL character, except when
              PARMRK is set(7,n,1 builtins), in(1,8) which case it reads as the  sequence  \377  \0
              \0.

       IGNPAR Ignore framing errors and parity errors.

       PARMRK If  IGNPAR is not set(7,n,1 builtins), prefix a character with a parity error(8,n) or
              framing error(8,n) with \377 \0.  If neither  IGNPAR  nor  PARMRK  is
              set(7,n,1 builtins),  read(2,n,1 builtins)  a  character with a parity error(8,n) or framing error(8,n) as
              \0.

       INPCK  Enable input parity checking.

       ISTRIP Strip off eighth bit.

       INLCR  Translate NL to CR on input.

       IGNCR  Ignore carriage return on input.

       ICRNL  Translate carriage return to newline on input (unless  IGNCR  is
              set(7,n,1 builtins)).

       IUCLC  (not in(1,8) POSIX) Map uppercase characters to lowercase on input.

       IXON   Enable XON/XOFF flow control on output.

       IXANY  (not in(1,8) POSIX.1; XSI) Enable any character to restart output.

       IXOFF  Enable XON/XOFF flow control on input.

       IMAXBEL
              (not  in(1,8)  POSIX) Ring bell when input queue(1,3) is full.  Linux does
              not implement this bit, and acts as if(3,n) it is always set.

       c_oflag flag constants defined in(1,8) POSIX.1:

       OPOST  Enable implementation-defined output processing.

       The remaining c_oflag flag constants are defined in(1,8) POSIX  1003.1-2001,
       unless marked otherwise.

       OLCUC  (not  in(1,8) POSIX) Map lowercase characters to uppercase on output.

       ONLCR  (XSI) Map NL to CR-NL on output.

       OCRNL  Map CR to NL on output.

       ONOCR  Don't output CR at column 0.

       ONLRET Don't output CR.

       OFILL  Send fill characters for a delay,  rather  than  using  a  timed
              delay.

       OFDEL  (not  in(1,8)  POSIX)  Fill character is ASCII DEL (0177).  If unset,
              fill character is ASCII NUL.

       NLDLY  Newline delay mask.  Values are NL0 and NL1.

       CRDLY  Carriage return delay mask.  Values are CR0, CR1, CR2, or CR3.

       TABDLY Horizontal tab delay mask.  Values are TAB0,  TAB1,  TAB2,  TAB3
              (or  XTABS).   A  value of TAB3, that is, XTABS, expands tabs to
              spaces (with tab stops every eight columns).

       BSDLY  Backspace delay mask.  Values are BS0 or BS1.  (Has  never  been
              implemented.)

       VTDLY  Vertical tab delay mask.  Values are VT0 or VT1.

       FFDLY  Form feed delay mask.  Values are FF0 or FF1.

       c_cflag flag constants:

       CBAUD  (not in(1,8) POSIX) Baud speed mask (4+1 bits).

       CBAUDEX
              (not in(1,8) POSIX) Extra baud speed mask (1 bit), included in(1,8) CBAUD.

       (POSIX says that the baud speed is  stored  in(1,8)  the  termios  structure
       without  specifying  where  precisely,  and  provides cfgetispeed() and
       cfsetispeed() for getting at it. Some  systems  use  bits  selected  by
       CBAUD  in(1,8)  c_cflag,  other systems use separate fields, e.g.  sg_ispeed
       and sg_ospeed.)

       CSIZE  Character size mask.  Values are CS5, CS6, CS7, or CS8.

       CSTOPB Set two stop bits, rather than one.

       CREAD  Enable receiver.

       PARENB Enable parity generation  on  output  and  parity  checking  for
              input.

       PARODD Parity for input and output is odd.

       HUPCL  Lower  modem  control lines after last process closes the device
              (hang up).

       CLOCAL Ignore modem control lines.

       LOBLK  (not in(1,8) POSIX) Block output from a noncurrent shell layer.  (For
              use by shl.)

       CIBAUD (not  in(1,8) POSIX) Mask for input speeds. The values for the CIBAUD
              bits are the same as the values for the CBAUD bits, shifted left
              IBSHIFT bits.

       CRTSCTS
              (not in(1,8) POSIX) Enable RTS/CTS (hardware) flow control.

       c_lflag flag constants:

       ISIG   When  any  of  the  characters  INTR,  QUIT,  SUSP, or DSUSP are
              received, generate the corresponding signal.

       ICANON Enable canonical mode.  This enables the special characters EOF,
              EOL,  EOL2, ERASE, KILL, LNEXT, REPRINT, STATUS, and WERASE, and
              buffers by lines.

       XCASE  (not in(1,8) POSIX; not supported under Linux) If ICANON is also set(7,n,1 builtins),
              terminal  is  uppercase  only.  Input is converted to lowercase,
              except for characters preceded by \.  On output, uppercase char-
              acters  are preceded by \ and lowercase characters are converted
              to uppercase.

       ECHO   Echo input characters.

       ECHOE  If ICANON is also set(7,n,1 builtins), the ERASE character erases the  preceding
              input character, and WERASE erases the preceding word.

       ECHOK  If  ICANON  is  also  set(7,n,1 builtins), the KILL character erases the current
              line.

       ECHONL If ICANON is also set(7,n,1 builtins), echo(1,3x,1 builtins) the NL character even if(3,n) ECHO is not
              set.

       ECHOCTL
              (not  in(1,8) POSIX) If ECHO is also set(7,n,1 builtins), ASCII control signals other
              than TAB, NL, START, and STOP are echoed as ^X, where X  is  the
              character  with ASCII code 0x40 greater than the control signal.
              For example, character 0x08 (BS) is echoed as ^H.

       ECHOPRT
              (not in(1,8) POSIX) If ICANON and IECHO are also set(7,n,1 builtins), characters  are
              printed as they are being erased.

       ECHOKE (not  in(1,8) POSIX) If ICANON is also set(7,n,1 builtins), KILL is echoed by erasing
              each character on the line, as specified by ECHOE and ECHOPRT.

       DEFECHO
              (not in(1,8) POSIX) Echo only when a process is reading.

       FLUSHO (not in(1,8) POSIX;  not  supported  under  Linux)  Output  is  being
              flushed.   This flag is toggled by typing the DISCARD character.

       NOFLSH Disable flushing the input and output queues when generating the
              SIGINT, SIGQUIT and SIGSUSP signals.

       TOSTOP Send  the  SIGTTOU  signal(2,7)  to the process group of a background
              process which tries to write(1,2) to its controlling terminal.

       PENDIN (not in(1,8) POSIX; not supported under Linux) All characters in(1,8)  the
              input  queue(1,3)  are  reprinted  when  the  next character is read.
              (bash handles typeahead this way.)

       IEXTEN Enable implementation-defined input processing.  This  flag,  as
              well as ICANON must be enabled for  the special characters EOL2,
              LNEXT, REPRINT, WERASE to be interpreted, and for the IUCLC flag
              to be effective.

       The  c_cc  array  defines the special control characters.  The symbolic
       indices (initial values) and meaning are:

       VINTR  (003, ETX, Ctrl-C, or also 0177, DEL, rubout) Interrupt  charac-
              ter.  Send  a  SIGINT  signal.  Recognized when ISIG is set(7,n,1 builtins), and
              then not passed as input.

       VQUIT  (034, FS, Ctrl-\) Quit character. Send SIGQUIT  signal.   Recog-
              nized when ISIG is set(7,n,1 builtins), and then not passed as input.

       VERASE (0177, DEL, rubout, or 010, BS, Ctrl-H, or also #) Erase charac-
              ter. This erases the previous not-yet-erased character, but does
              not erase past EOF or beginning-of-line.  Recognized when ICANON
              is set(7,n,1 builtins), and then not passed as input.

       VKILL  (025, NAK, Ctrl-U, or Ctrl-X, or also @)  Kill  character.  This
              erases  the input since the last EOF or beginning-of-line.  Rec-
              ognized when ICANON is set(7,n,1 builtins), and then not passed as input.

       VEOF   (004, EOT, Ctrl-D) End-of-file character.  More precisely:  this
              character  causes the pending tty(1,4) buffer to be sent to the wait-
              ing user program without waiting for end-of-line.  If it is  the
              first  character  of  the  line,  the read(2,n,1 builtins)() in(1,8) the user program
              returns 0, which signifies end-of-file.  Recognized when  ICANON
              is set(7,n,1 builtins), and then not passed as input.

       VMIN   Minimum number of characters for non-canonical read.

       VEOL   (0,  NUL)  Additional  end-of-line  character.   Recognized when
              ICANON is set.

       VTIME  Timeout in(1,8) deciseconds for non-canonical read.

       VEOL2  (not in(1,8) POSIX; 0, NUL) Yet another end-of-line character.   Rec-
              ognized when ICANON is set.

       VSWTCH (not in(1,8) POSIX; not supported under Linux; 0, NUL) Switch charac-
              ter. (Used by shl only.)

       VSTART (021, DC1, Ctrl-Q) Start character. Restarts output  stopped  by
              the  Stop  character.  Recognized when IXON is set(7,n,1 builtins), and then not
              passed as input.

       VSTOP  (023, DC3, Ctrl-S) Stop character. Stop output until Start char-
              acter  typed.   Recognized when IXON is set(7,n,1 builtins), and then not passed
              as input.

       VSUSP  (032, SUB, Ctrl-Z) Suspend character. Send SIGTSTP signal.  Rec-
              ognized when ISIG is set(7,n,1 builtins), and then not passed as input.

       VDSUSP (not  in(1,8)  POSIX;  not  supported  under  Linux; 031, EM, Ctrl-Y)
              Delayed suspend character: send(2,n) SIGTSTP signal(2,7) when the  charac-
              ter  is  read(2,n,1 builtins)  by  the user program.  Recognized when IEXTEN and
              ISIG are set(7,n,1 builtins), and the system supports job control, and then  not
              passed as input.

       VLNEXT (not  in(1,8)  POSIX; 026, SYN, Ctrl-V) Literal next. Quotes the next
              input character, depriving it of  a  possible  special  meaning.
              Recognized when IEXTEN is set(7,n,1 builtins), and then not passed as input.

       VWERASE
              (not  in(1,8)  POSIX;  027, ETB, Ctrl-W) Word erase.  Recognized when
              ICANON and IEXTEN are set(7,n,1 builtins), and then not passed as input.

       VREPRINT
              (not in(1,8) POSIX; 022,  DC2,  Ctrl-R)  Reprint  unread  characters.
              Recognized  when  ICANON and IEXTEN are set(7,n,1 builtins), and then not passed
              as input.

       VDISCARD
              (not in(1,8) POSIX; not supported under Linux; 017, SI, Ctrl-O)  Tog-
              gle: start/stop discarding pending output.  Recognized when IEX-
              TEN is set(7,n,1 builtins), and then not passed as input.

       VSTATUS
              (not in(1,8) POSIX; not supported under Linux; status  request:  024,
              DC4, Ctrl-T).

       These  symbolic  subscript values are all different, except that VTIME,
       VMIN may have the same value as VEOL,  VEOF,  respectively.   (In  non-
       canonical mode the special character meaning is replaced by the timeout(1,3x,3x cbreak)
       meaning. MIN represents the minimum number of characters that should be
       received  to  satisfy the read. TIME is a decisecond-valued timer. When
       both are set(7,n,1 builtins), a read(2,n,1 builtins) will wait until at least one  character  has  been
       received,  and  then  return as soon as either MIN characters have been
       received or time(1,2,n) TIME has passed since the last character was received.
       If only MIN is set(7,n,1 builtins), the read(2,n,1 builtins) will not return before MIN characters have
       been received. If only TIME is set(7,n,1 builtins), the read(2,n,1 builtins) will  return  as  soon  as
       either  at  least  one  character has been received, or the timer times
       out. If neither is set(7,n,1 builtins), the read(2,n,1 builtins) will return immediately,  only  giving
       the currently already available characters.)

       tcgetattr()  gets(3,n) the parameters associated with the object referred by
       fd and stores them in(1,8) the termios structure  referenced  by  termios_p.
       This  function  may  be invoked from a background process; however, the
       terminal  attributes  may  be  subsequently  changed  by  a  foreground
       process.

       tcsetattr()  sets  the  parameters associated with the terminal (unless
       support is required from the underlying hardware that is not available)
       from  the termios structure referred to by termios_p.  optional_actions
       specifies when the changes take effect:

       TCSANOW
              the change occurs immediately.

       TCSADRAIN
              the change occurs after all output written to fd has been trans-
              mitted.   This  function should be used when changing parameters
              that affect output.

       TCSAFLUSH
              the change  occurs  after  all  output  written  to  the  object
              referred by fd has been transmitted, and all input that has been
              received but not read(2,n,1 builtins) will be discarded  before  the  change  is
              made.

       tcsendbreak()  transmits  a continuous stream of zero-valued bits for a
       specific duration, if(3,n) the terminal is using  asynchronous  serial  data
       transmission.   If  duration is zero, it transmits zero-valued bits for
       at least 0.25 seconds, and not more that 0.5 seconds.  If  duration  is
       not  zero,  it  sends  zero-valued bits for some implementation-defined
       length of time.

       If the terminal is not using  asynchronous  serial  data  transmission,
       tcsendbreak() returns without taking any action.

       tcdrain()  waits  until all output written to the object referred to by
       fd has been transmitted.

       tcflush() discards data written to the object referred to by fd but not
       transmitted,  or  data received but not read(2,n,1 builtins), depending on the value of
       queue_selector:

       TCIFLUSH
              flushes data received but not read.

       TCOFLUSH
              flushes data written but not transmitted.

       TCIOFLUSH
              flushes both data received but not read(2,n,1 builtins), and  data  written  but
              not transmitted.

       tcflow()  suspends  transmission  or  reception  of  data on the object
       referred to by fd, depending on the value of action:

       TCOOFF suspends output.

       TCOON  restarts suspended output.

       TCIOFF transmits a STOP character, which stops the terminal device from
              transmitting data to the system.

       TCION  transmits  a  START  character, which starts the terminal device
              transmitting data to the system.

       The default on open(2,3,n) of a terminal file(1,n) is that neither  its  input  nor
       its output is suspended.

       The baud rate functions are provided for getting and setting the values
       of the input and output baud rates in(1,8) the termios structure.   The  new
       values do not take effect until tcsetattr() is successfully called.

       Setting  the  speed to B0 instructs the modem to "hang up".  The actual
       bit rate corresponding to B38400 may be altered with setserial(8).

       The input and output baud rates are stored in(1,8) the termios structure.

       cfmakeraw sets the terminal attributes as follows:
                   termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
                                   |INLCR|IGNCR|ICRNL|IXON);
                   termios_p->c_oflag &= ~OPOST;
                   termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
                   termios_p->c_cflag &= ~(CSIZE|PARENB);
                   termios_p->c_cflag |= CS8;

       cfgetospeed() returns the output baud rate stored in(1,8) the termios struc-
       ture pointed to by termios_p.

       cfsetospeed() sets the output baud rate stored in(1,8) the termios structure
       pointed to by termios_p to speed, which must be one of these constants:
            B0
            B50
            B75
            B110
            B134
            B150
            B200
            B300
            B600
            B1200
            B1800
            B2400
            B4800
            B9600
            B19200
            B38400
            B57600
            B115200
            B230400
       The  zero baud rate, B0, is used to terminate the connection.  If B0 is
       specified, the modem control lines shall no longer be  asserted.   Nor-
       mally, this will disconnect the line.  CBAUDEX is a mask for the speeds
       beyond those defined in(1,8) POSIX.1 (57600  and  above).   Thus,  B57600  &
       CBAUDEX is nonzero.

       cfgetispeed()  returns the input baud rate stored in(1,8) the termios struc-
       ture.

       cfsetispeed() sets the input baud rate stored in(1,8) the termios  structure
       to  speed.   If the input baud rate is set(7,n,1 builtins) to zero, the input baud rate
       will be equal to the output baud rate.

       cfsetspeed() is a 4.4 BSD extension. It will set(7,n,1 builtins) both input and  output
       speed.

RETURN VALUE
       cfgetispeed()  returns the input baud rate stored in(1,8) the termios struc-
       ture.

       cfgetospeed() returns the output baud rate stored in(1,8) the termios struc-
       ture.

       All other functions return:

       0      on success.

       -1     on failure and set(7,n,1 builtins) errno to indicate the error.

       Note  that  tcsetattr() returns success if(3,n) any of the requested changes
       could be successfully carried out.   Therefore,  when  making  multiple
       changes  it may be necessary to follow this call with a further call to
       tcgetattr() to check that all changes have been performed successfully.


NOTES
       Unix V7 and several later systems have a list of baud rates where after
       the fourteen values B0, ..., B9600 one finds the  two  constants  EXTA,
       EXTB  ("External  A"  and  "External B").  Many systems extend the list
       with much higher baud rates.

       The effect of a nonzero duration with tcsendbreak varies.  SunOS speci-
       fies  a  break of duration*N seconds, where N is at least 0.25, and not
       more than 0.5.  Linux, AIX, DU, Tru64 send(2,n) a  break  of  duration  mil-
       liseconds.   FreeBSD and NetBSD and HP-UX and MacOS ignore the value of
       duration.  Under Solaris and Unixware, tcsendbreak with  nonzero  dura-
       tion behaves like tcdrain.

SEE ALSO
       stty(1), setserial(8)



Linux                             2004-10-31                        TERMIOS(3)

References for this manual (incoming links)