]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - manual/terminal.texi
test-container: Fix "unused code" warnings on HURD
[thirdparty/glibc.git] / manual / terminal.texi
index 7e0f9852202deba9a1bcd99a64e42a0e26345466..7293bfb393337f8c1334fab3fa0a5e5f0d0a4f24 100644 (file)
@@ -1,4 +1,5 @@
-@node Low-Level Terminal Interface
+@node Low-Level Terminal Interface, Syslog, Sockets, Top
+@c %MENU% How to change the characteristics of a terminal device
 @chapter Low-Level Terminal Interface
 
 This chapter describes functions that are specific to terminal devices.
@@ -18,10 +19,13 @@ descriptor is and how to open a file descriptor for a terminal device.
 * Canonical or Not::            Two basic styles of input processing.
 * Terminal Modes::              How to examine and modify flags controlling
                                 details of terminal I/O: echoing,
-                                 signals, editing.
+                                 signals, editing.  Posix.
+* BSD Terminal Modes::          BSD compatible terminal mode setting
 * Line Control::                Sending break sequences, clearing
                                  terminal buffers @dots{}
 * Noncanon Example::            How to read single characters without echo.
+* getpass::                     Prompting the user for a passphrase.
+* Pseudo-Terminals::            How to open a pseudo-terminal.
 @end menu
 
 @node Is It a Terminal
@@ -35,23 +39,38 @@ descriptor is associated with a terminal by using the @code{isatty}
 function.
 
 @pindex unistd.h
-Prototypes for both @code{isatty} and @code{ttyname} are declared in
-the header file @file{unistd.h}.
+Prototypes for the functions in this section are declared in the header
+file @file{unistd.h}.
 
-@comment unistd.h
-@comment POSIX.1
 @deftypefun int isatty (int @var{filedes})
+@standards{POSIX.1, unistd.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+@c isatty ok
+@c  tcgetattr dup ok
 This function returns @code{1} if @var{filedes} is a file descriptor
-associated with an open terminal device, and @code{0} otherwise.
+associated with an open terminal device, and @math{0} otherwise.
 @end deftypefun
 
 If a file descriptor is associated with a terminal, you can get its
 associated file name using the @code{ttyname} function.  See also the
 @code{ctermid} function, described in @ref{Identifying the Terminal}.
 
-@comment unistd.h
-@comment POSIX.1
 @deftypefun {char *} ttyname (int @var{filedes})
+@standards{POSIX.1, unistd.h}
+@safety{@prelim{}@mtunsafe{@mtasurace{:ttyname}}@asunsafe{@ascuheap{} @asulock{}}@acunsafe{@aculock{} @acsfd{} @acsmem{}}}
+@c ttyname @mtasurace:ttyname @ascuheap @asulock @aculock @acsmem @acsfd
+@c  isatty dup ok
+@c  fstat dup ok
+@c  memcpy dup ok
+@c  getttyname @mtasurace:ttyname @ascuheap @asulock @aculock @acsmem @acsfd
+@c   opendir @ascuheap @acsmem @acsfd
+@c   readdir ok [protected by exclusive access]
+@c   strcmp dup ok
+@c   free dup @asulock @aculock @acsfd @acsmem
+@c   malloc dup @asulock @aculock @acsfd @acsmem
+@c   closedir @ascuheap @acsmem @acsfd
+@c   mempcpy dup ok
+@c   stat dup ok
 If the file descriptor @var{filedes} is associated with a terminal
 device, the @code{ttyname} function returns a pointer to a
 statically-allocated, null-terminated string containing the file name of
@@ -59,6 +78,46 @@ the terminal file.  The value is a null pointer if the file descriptor
 isn't associated with a terminal, or the file name cannot be determined.
 @end deftypefun
 
+@deftypefun int ttyname_r (int @var{filedes}, char *@var{buf}, size_t @var{len})
+@standards{POSIX.1, unistd.h}
+@safety{@prelim{}@mtsafe{}@asunsafe{@ascuheap{}}@acunsafe{@acsmem{} @acsfd{}}}
+@c ttyname_r @ascuheap @acsmem @acsfd
+@c  isatty dup ok
+@c  fstat dup ok
+@c  memcpy dup ok
+@c  getttyname_r @ascuheap @acsmem @acsfd
+@c   opendir @ascuheap @acsmem @acsfd
+@c   readdir ok [protected by exclusive access]
+@c   strcmp dup ok
+@c   closedir @ascuheap @acsmem @acsfd
+@c   stpncpy dup ok
+@c   stat dup ok
+The @code{ttyname_r} function is similar to the @code{ttyname} function
+except that it places its result into the user-specified buffer starting
+at @var{buf} with length @var{len}.
+
+The normal return value from @code{ttyname_r} is @math{0}.  Otherwise an
+error number is returned to indicate the error.  The following
+@code{errno} error conditions are defined for this function:
+
+@table @code
+@item EBADF
+The @var{filedes} argument is not a valid file descriptor.
+
+@item ENOTTY
+The @var{filedes} is not associated with a terminal.
+
+@item ERANGE
+The buffer length @var{len} is too small to store the string to be
+returned.
+
+@item ENODEV
+The @var{filedes} is associated with a terminal device that is a slave
+pseudo-terminal, but the file name associated with that device could
+not be determined.  This is a GNU extension.
+@end table
+@end deftypefun
+
 @node I/O Queues
 @section I/O Queues
 
@@ -73,25 +132,24 @@ The @dfn{terminal input queue} is also sometimes referred to as its
 @dfn{typeahead buffer}.  It holds the characters that have been received
 from the terminal but not yet read by any process.
 
-The size of the terminal's input queue is described by the
-@code{MAX_INPUT} and @w{@code{_POSIX_MAX_INPUT}} parameters; see @ref{Limits
-for Files}.  You are guaranteed a queue size of at least
-@code{MAX_INPUT}, but the queue might be larger, and might even
-dynamically change size.  If input flow control is enabled by setting
-the @code{IXOFF} input mode bit (@pxref{Input Modes}), the terminal
-driver transmits STOP and START characters to the terminal when
-necessary to prevent the queue from overflowing.  Otherwise, input may
-be lost if it comes in too fast from the terminal.  In canonical mode,
-all input stays in the queue until a newline character is received, so
-the terminal input queue can fill up when you type a very long line.
-@xref{Canonical or Not}.
+The size of the input queue is described by the @code{MAX_INPUT} and
+@w{@code{_POSIX_MAX_INPUT}} parameters; see @ref{Limits for Files}.  You
+are guaranteed a queue size of at least @code{MAX_INPUT}, but the queue
+might be larger, and might even dynamically change size.  If input flow
+control is enabled by setting the @code{IXOFF} input mode bit
+(@pxref{Input Modes}), the terminal driver transmits STOP and START
+characters to the terminal when necessary to prevent the queue from
+overflowing.  Otherwise, input may be lost if it comes in too fast from
+the terminal.  In canonical mode, all input stays in the queue until a
+newline character is received, so the terminal input queue can fill up
+when you type a very long line.  @xref{Canonical or Not}.
 
 @cindex terminal output queue
 The @dfn{terminal output queue} is like the input queue, but for output;
 it contains characters that have been written by processes, but not yet
 transmitted to the terminal.  If output flow control is enabled by
 setting the @code{IXON} input mode bit (@pxref{Input Modes}), the
-terminal driver obeys STOP and STOP characters sent by the terminal to
+terminal driver obeys START and STOP characters sent by the terminal to
 stop and restart transmission of output.
 
 @dfn{Clearing} the terminal input queue means discarding any characters
@@ -145,7 +203,11 @@ The choice of canonical or noncanonical input is controlled by the
 This section describes the various terminal attributes that control how
 input and output are done.  The functions, data structures, and symbolic
 constants are all declared in the header file @file{termios.h}.
-@c !!! should mention terminal attributes are distinct from file attributes
+
+Don't confuse terminal attributes with file attributes.  A device special
+file which is associated with a terminal has file attributes as described
+in @ref{File Attributes}.  These are unrelated to the attributes of the
+terminal device itself, which are discussed in this section.
 
 @menu
 * Mode Data Types::             The data type @code{struct termios} and
@@ -173,10 +235,9 @@ structure of type @code{struct termios}.  This structure is used
 with the functions @code{tcgetattr} and @code{tcsetattr} to read
 and set the attributes.
 
-@comment termios.h
-@comment POSIX.1
 @deftp {Data Type} {struct termios}
-Structure that records all the I/O attributes of a terminal.  The
+@standards{POSIX.1, termios.h}
+A @code{struct termios} records all the I/O attributes of a terminal.  The
 structure includes at least the following members:
 
 @table @code
@@ -206,23 +267,20 @@ speed values.
 The following sections describe the details of the members of the
 @code{struct termios} structure.
 
-@comment termios.h
-@comment POSIX.1
 @deftp {Data Type} tcflag_t
+@standards{POSIX.1, termios.h}
 This is an unsigned integer type used to represent the various
 bit masks for terminal flags.
 @end deftp
 
-@comment termios.h
-@comment POSIX.1
 @deftp {Data Type} cc_t
+@standards{POSIX.1, termios.h}
 This is an unsigned integer type used to represent characters associated
 with various terminal control functions.
 @end deftp
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro int NCCS
+@standards{POSIX.1, termios.h}
 The value of this macro is the number of elements in the @code{c_cc}
 array.
 @end deftypevr
@@ -231,14 +289,16 @@ array.
 @subsection Terminal Mode Functions
 @cindex terminal mode functions
 
-@comment termios.h
-@comment POSIX.1
 @deftypefun int tcgetattr (int @var{filedes}, struct termios *@var{termios-p})
+@standards{POSIX.1, termios.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+@c Converting the kernel-returned termios data structure to the userland
+@c format does not ensure atomic or consistent writing.
 This function is used to examine the attributes of the terminal
 device with file descriptor @var{filedes}.  The attributes are returned
 in the structure that @var{termios-p} points to.
 
-If successful, @code{tcgetattr} returns @code{0}.  A return value of @code{-1}
+If successful, @code{tcgetattr} returns @math{0}.  A return value of @math{-1}
 indicates an error.  The following @code{errno} error conditions are
 defined for this function:
 
@@ -251,9 +311,11 @@ The @var{filedes} is not associated with a terminal.
 @end table
 @end deftypefun
 
-@comment termios.h
-@comment POSIX.1
 @deftypefun int tcsetattr (int @var{filedes}, int @var{when}, const struct termios *@var{termios-p})
+@standards{POSIX.1, termios.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+@c Converting the incoming termios data structure to the kernel format
+@c does not ensure atomic or consistent reading.
 This function sets the attributes of the terminal device with file
 descriptor @var{filedes}.  The new attributes are taken from the
 structure that @var{termios-p} points to.
@@ -261,40 +323,32 @@ structure that @var{termios-p} points to.
 The @var{when} argument specifies how to deal with input and output
 already queued.  It can be one of the following values:
 
-@table @code
-@comment termios.h
-@comment POSIX.1
+@vtable @code
 @item TCSANOW
-@vindex TCSANOW
+@standards{POSIX.1, termios.h}
 Make the change immediately.
 
-@comment termios.h
-@comment POSIX.1
 @item TCSADRAIN
-@vindex TCSADRAIN
+@standards{POSIX.1, termios.h}
 Make the change after waiting until all queued output has been written.
 You should usually use this option when changing parameters that affect
 output.
 
-@comment termios.h
-@comment POSIX.1
 @item TCSAFLUSH
-@vindex TCSAFLUSH
+@standards{POSIX.1, termios.h}
 This is like @code{TCSADRAIN}, but also discards any queued input.
 
-@comment termios.h
-@comment BSD
 @item TCSASOFT
-@vindex TCSASOFT
+@standards{BSD, termios.h}
 This is a flag bit that you can add to any of the above alternatives.
 Its meaning is to inhibit alteration of the state of the terminal
 hardware.  It is a BSD extension; it is only supported on BSD systems
-and the GNU system.
+and @gnuhurdsystems{}.
 
 Using @code{TCSASOFT} is exactly the same as setting the @code{CIGNORE}
 bit in the @code{c_cflag} member of the structure @var{termios-p} points
 to.  @xref{Control Modes}, for a description of @code{CIGNORE}.
-@end table
+@end vtable
 
 If this function is called from a background process on its controlling
 terminal, normally all processes in the process group are sent a
@@ -303,8 +357,8 @@ write to the terminal.  The exception is if the calling process itself
 is ignoring or blocking @code{SIGTTOU} signals, in which case the
 operation is performed and no signal is sent.  @xref{Job Control}.
 
-If successful, @code{tcsetattr} returns @code{0}.  A return value of
-@code{-1} indicates an error.  The following @code{errno} error
+If successful, @code{tcsetattr} returns @math{0}.  A return value of
+@math{-1} indicates an error.  The following @code{errno} error
 conditions are defined for this function:
 
 @table @code
@@ -393,8 +447,8 @@ set_istrip (int desc, int value)
   result = tcsetattr (desc, TCSANOW, &settings);
   if (result < 0)
     @{
-      perror ("error in tcgetattr");
-      return;
+      perror ("error in tcsetattr");
+      return 0;
    @}
   return 1;
 @}
@@ -415,9 +469,8 @@ try to specify the entire value for @code{c_iflag}---instead, change
 only specific flags and leave the rest untouched (@pxref{Setting
 Modes}).
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t INPCK
+@standards{POSIX.1, termios.h}
 @cindex parity checking
 If this bit is set, input parity checking is enabled.  If it is not set,
 no checking at all is done for parity errors on input; the
@@ -435,16 +488,14 @@ of these bits are set, a byte with a parity error is passed to the
 application as a @code{'\0'} character.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t IGNPAR
+@standards{POSIX.1, termios.h}
 If this bit is set, any byte with a framing or parity error is ignored.
 This is only useful if @code{INPCK} is also set.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t PARMRK
+@standards{POSIX.1, termios.h}
 If this bit is set, input bytes with parity or framing errors are marked
 when passed to the program.  This bit is meaningful only when
 @code{INPCK} is set and @code{IGNPAR} is not set.
@@ -459,16 +510,14 @@ parity error.  So a valid byte @code{0377} is passed to the program as
 two bytes, @code{0377} @code{0377}, in this case.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t ISTRIP
+@standards{POSIX.1, termios.h}
 If this bit is set, valid input bytes are stripped to seven bits;
 otherwise, all eight bits are available for programs to read.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t IGNBRK
+@standards{POSIX.1, termios.h}
 If this bit is set, break conditions are ignored.
 
 @cindex break condition, detecting
@@ -477,9 +526,8 @@ serial data transmission as a series of zero-value bits longer than a
 single byte.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t BRKINT
+@standards{POSIX.1, termios.h}
 If this bit is set and @code{IGNBRK} is not set, a break condition
 clears the terminal input and output queues and raises a @code{SIGINT}
 signal for the foreground process group associated with the terminal.
@@ -490,33 +538,29 @@ passed to the application as a single @code{'\0'} character if
 @code{'\377'}, @code{'\0'}, @code{'\0'}.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t IGNCR
+@standards{POSIX.1, termios.h}
 If this bit is set, carriage return characters (@code{'\r'}) are
 discarded on input.  Discarding carriage return may be useful on
 terminals that send both carriage return and linefeed when you type the
 @key{RET} key.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t ICRNL
+@standards{POSIX.1, termios.h}
 If this bit is set and @code{IGNCR} is not set, carriage return characters
 (@code{'\r'}) received as input are passed to the application as newline
 characters (@code{'\n'}).
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t INLCR
+@standards{POSIX.1, termios.h}
 If this bit is set, newline characters (@code{'\n'}) received as input
 are passed to the application as carriage return characters (@code{'\r'}).
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t IXOFF
+@standards{POSIX.1, termios.h}
 If this bit is set, start/stop control on input is enabled.  In other
 words, the computer sends STOP and START characters as necessary to
 prevent input from coming in faster than programs are reading it.  The
@@ -525,9 +569,8 @@ data responds to a STOP character by suspending transmission, and to a
 START character by resuming transmission.  @xref{Start/Stop Characters}.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t IXON
+@standards{POSIX.1, termios.h}
 If this bit is set, start/stop control on output is enabled.  In other
 words, if the computer receives a STOP character, it suspends output
 until a START character is received.  In this case, the STOP and START
@@ -537,19 +580,18 @@ not set, then START and STOP can be read as ordinary characters.
 @c !!! mention this interferes with using C-s and C-q for programs like emacs
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t IXANY
+@standards{BSD, termios.h}
 If this bit is set, any input character restarts output when output has
 been suspended with the STOP character.  Otherwise, only the START
 character restarts output.
 
-This is a BSD extension; it exists only on BSD systems and the GNU system.
+This is a BSD extension; it exists only on BSD systems and
+@gnulinuxhurdsystems{}.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t IMAXBEL
+@standards{BSD, termios.h}
 If this bit is set, then filling up the terminal input buffer sends a
 BEL character (code @code{007}) to the terminal to ring the bell.
 
@@ -570,9 +612,8 @@ try to specify the entire value for @code{c_oflag}---instead, change
 only specific flags and leave the rest untouched (@pxref{Setting
 Modes}).
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t OPOST
+@standards{POSIX.1, termios.h}
 If this bit is set, output data is processed in some unspecified way so
 that it is displayed appropriately on the terminal device.  This
 typically includes mapping newline characters (@code{'\n'}) onto
@@ -581,29 +622,27 @@ carriage return and linefeed pairs.
 If this bit isn't set, the characters are transmitted as-is.
 @end deftypevr
 
-The following three bits are BSD features, and they exist only BSD
-systems and the GNU system.  They are effective only if @code{OPOST} is
-set.
+The following three bits are effective only if @code{OPOST} is set.
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t ONLCR
+@standards{POSIX.1, termios.h}
 If this bit is set, convert the newline character on output into a pair
 of characters, carriage return followed by linefeed.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t OXTABS
+@standards{BSD, termios.h (optional)}
 If this bit is set, convert tab characters on output into the appropriate
-number of spaces to emulate a tab stop every eight columns.
+number of spaces to emulate a tab stop every eight columns.  This bit
+exists only on BSD systems and @gnuhurdsystems{}; on
+@gnulinuxsystems{} it is available as @code{XTABS}.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t ONOEOT
+@standards{BSD, termios.h (optional)}
 If this bit is set, discard @kbd{C-d} characters (code @code{004}) on
 output.  These characters cause many dial-up terminals to disconnect.
+This bit exists only on BSD systems and @gnuhurdsystems{}.
 @end deftypevr
 
 @node Control Modes
@@ -622,9 +661,8 @@ try to specify the entire value for @code{c_cflag}---instead, change
 only specific flags and leave the rest untouched (@pxref{Setting
 Modes}).
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t CLOCAL
+@standards{POSIX.1, termios.h}
 If this bit is set, it indicates that the terminal is connected
 ``locally'' and that the modem status lines (such as carrier detect)
 should be ignored.
@@ -645,30 +683,26 @@ clear the condition.
 @cindex modem disconnect
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t HUPCL
+@standards{POSIX.1, termios.h}
 If this bit is set, a modem disconnect is generated when all processes
 that have the terminal device open have either closed the file or exited.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t CREAD
+@standards{POSIX.1, termios.h}
 If this bit is set, input can be read from the terminal.  Otherwise,
 input is discarded when it arrives.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t CSTOPB
+@standards{POSIX.1, termios.h}
 If this bit is set, two stop bits are used.  Otherwise, only one stop bit
 is used.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t PARENB
+@standards{POSIX.1, termios.h}
 If this bit is set, generation and detection of a parity bit are enabled.
 @xref{Input Modes}, for information on how input parity errors are handled.
 
@@ -676,9 +710,8 @@ If this bit is not set, no parity bit is added to output characters, and
 input characters are not checked for correct parity.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t PARODD
+@standards{POSIX.1, termios.h}
 This bit is only useful if @code{PARENB} is set.  If @code{PARODD} is set,
 odd parity is used, otherwise even parity is used.
 @end deftypevr
@@ -687,62 +720,53 @@ The control mode flags also includes a field for the number of bits per
 character.  You can use the @code{CSIZE} macro as a mask to extract the
 value, like this: @code{settings.c_cflag & CSIZE}.
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t CSIZE
+@standards{POSIX.1, termios.h}
 This is a mask for the number of bits per character.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t CS5
+@standards{POSIX.1, termios.h}
 This specifies five bits per byte.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t CS6
+@standards{POSIX.1, termios.h}
 This specifies six bits per byte.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t CS7
+@standards{POSIX.1, termios.h}
 This specifies seven bits per byte.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t CS8
+@standards{POSIX.1, termios.h}
 This specifies eight bits per byte.
 @end deftypevr
 
-The following four bits are BSD extensions; this exist only on BSD
-systems and the GNU system.
+The following four bits are BSD extensions; these exist only on BSD
+systems and @gnuhurdsystems{}.
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t CCTS_OFLOW
+@standards{BSD, termios.h}
 If this bit is set, enable flow control of output based on the CTS wire
 (RS232 protocol).
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t CRTS_IFLOW
+@standards{BSD, termios.h}
 If this bit is set, enable flow control of input based on the RTS wire
 (RS232 protocol).
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t MDMBUF
+@standards{BSD, termios.h}
 If this bit is set, enable carrier-based flow control of output.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t CIGNORE
+@standards{BSD, termios.h}
 If this bit is set, it says to ignore the control modes and line speed
 values entirely.  This is only meaningful in a call to @code{tcsetattr}.
 
@@ -771,24 +795,21 @@ try to specify the entire value for @code{c_lflag}---instead, change
 only specific flags and leave the rest untouched (@pxref{Setting
 Modes}).
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t ICANON
+@standards{POSIX.1, termios.h}
 This bit, if set, enables canonical input processing mode.  Otherwise,
 input is processed in noncanonical mode.  @xref{Canonical or Not}.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t ECHO
+@standards{POSIX.1, termios.h}
 If this bit is set, echoing of input characters back to the terminal
 is enabled.
 @cindex echo of terminal input
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t ECHOE
+@standards{POSIX.1, termios.h}
 If this bit is set, echoing indicates erasure of input with the ERASE
 character by erasing the last character in the current line from the
 screen.  Otherwise, the character erased is re-echoed to show what has
@@ -799,23 +820,21 @@ itself controls actual recognition of the ERASE character and erasure of
 input, without which @code{ECHOE} is simply irrelevant.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t ECHOPRT
-This bit is like @code{ECHOE}, enables display of the ERASE character in
+@standards{BSD, termios.h}
+This bit, like @code{ECHOE}, enables display of the ERASE character in
 a way that is geared to a hardcopy terminal.  When you type the ERASE
 character, a @samp{\} character is printed followed by the first
 character erased.  Typing the ERASE character again just prints the next
 character erased.  Then, the next time you type a normal character, a
 @samp{/} character is printed before the character echoes.
 
-This is a BSD extension, and exists only in BSD systems and the
-GNU system.
+This is a BSD extension, and exists only in BSD systems and
+@gnulinuxhurdsystems{}.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t ECHOK
+@standards{POSIX.1, termios.h}
 This bit enables special display of the KILL character by moving to a
 new line after echoing the KILL character normally.  The behavior of
 @code{ECHOKE} (below) is nicer to look at.
@@ -830,43 +849,39 @@ itself controls actual recognition of the KILL character and erasure of
 input, without which @code{ECHOK} is simply irrelevant.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t ECHOKE
+@standards{BSD, termios.h}
 This bit is similar to @code{ECHOK}.  It enables special display of the
 KILL character by erasing on the screen the entire line that has been
-killed.  This is a BSD extension, and exists only in BSD systems and the
-GNU system.
+killed.  This is a BSD extension, and exists only in BSD systems and
+@gnulinuxhurdsystems{}.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t ECHONL
+@standards{POSIX.1, termios.h}
 If this bit is set and the @code{ICANON} bit is also set, then the
 newline (@code{'\n'}) character is echoed even if the @code{ECHO} bit
 is not set.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t ECHOCTL
+@standards{BSD, termios.h}
 If this bit is set and the @code{ECHO} bit is also set, echo control
 characters with @samp{^} followed by the corresponding text character.
 Thus, control-A echoes as @samp{^A}.  This is usually the preferred mode
 for interactive input, because echoing a control character back to the
 terminal could have some undesired effect on the terminal.
 
-This is a BSD extension, and exists only in BSD systems and the
-GNU system.
+This is a BSD extension, and exists only in BSD systems and
+@gnulinuxhurdsystems{}.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t ISIG
+@standards{POSIX.1, termios.h}
 This bit controls whether the INTR, QUIT, and SUSP characters are
 recognized.  The functions associated with these characters are performed
 if and only if this bit is set.  Being in canonical or noncanonical
-input mode has no affect on the interpretation of these characters.
+input mode has no effect on the interpretation of these characters.
 
 You should use caution when disabling recognition of these characters.
 Programs that cannot be interrupted interactively are very
@@ -878,38 +893,35 @@ signals associated with these characters, or to escape from the program.
 @xref{Signal Characters}.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t IEXTEN
+@standards{POSIX.1, termios.h}
 POSIX.1 gives @code{IEXTEN} implementation-defined meaning,
 so you cannot rely on this interpretation on all systems.
 
-On BSD systems and the GNU system, it enables the LNEXT and DISCARD characters.
+On BSD systems and @gnulinuxhurdsystems{}, it enables the LNEXT and
+DISCARD characters.
 @xref{Other Special}.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t NOFLSH
+@standards{POSIX.1, termios.h}
 Normally, the INTR, QUIT, and SUSP characters cause input and output
 queues for the terminal to be cleared.  If this bit is set, the queues
 are not cleared.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro tcflag_t TOSTOP
+@standards{POSIX.1, termios.h}
 If this bit is set and the system supports job control, then
 @code{SIGTTOU} signals are generated by background processes that
 attempt to write to the terminal.  @xref{Access to the Terminal}.
 @end deftypevr
 
-The following bits are BSD extensions; they exist only in BSD systems
-and the GNU system.
+The following bits are BSD extensions; they exist only on BSD systems
+and @gnuhurdsystems{}.
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t ALTWERASE
+@standards{BSD, termios.h}
 This bit determines how far the WERASE character should erase.  The
 WERASE character erases back to the beginning of a word; the question
 is, where do words begin?
@@ -922,23 +934,20 @@ a character which is none of those.
 @xref{Editing Characters}, for more information about the WERASE character.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t FLUSHO
+@standards{BSD, termios.h}
 This is the bit that toggles when the user types the DISCARD character.
 While this bit is set, all output is discarded.  @xref{Other Special}.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t NOKERNINFO
+@standards{BSD, termios.h (optional)}
 Setting this bit disables handling of the STATUS character.
 @xref{Other Special}.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro tcflag_t PENDIN
+@standards{BSD, termios.h}
 If this bit is set, it indicates that there is a line of input that
 needs to be reprinted.  Typing the REPRINT character sets this bit; the
 bit remains set until reprinting is finished.  @xref{Editing Characters}.
@@ -980,51 +989,60 @@ don't try to access them in the @code{struct termios} structure
 directly.  Instead, you should use the following functions to read and
 store them:
 
-@comment termios.h
-@comment POSIX.1
 @deftypefun speed_t cfgetospeed (const struct termios *@var{termios-p})
+@standards{POSIX.1, termios.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+@c Direct access to a single termios field, except on Linux, where
+@c multiple accesses may take place.  No worries either way, callers
+@c must ensure mutual exclusion on such non-opaque types.
 This function returns the output line speed stored in the structure
 @code{*@var{termios-p}}.
 @end deftypefun
 
-@comment termios.h
-@comment POSIX.1
 @deftypefun speed_t cfgetispeed (const struct termios *@var{termios-p})
+@standards{POSIX.1, termios.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
 This function returns the input line speed stored in the structure
 @code{*@var{termios-p}}.
 @end deftypefun
 
-@comment termios.h
-@comment POSIX.1
 @deftypefun int cfsetospeed (struct termios *@var{termios-p}, speed_t @var{speed})
+@standards{POSIX.1, termios.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
 This function stores @var{speed} in @code{*@var{termios-p}} as the output
-speed.  The normal return value is @code{0}; a value of @code{-1}
+speed.  The normal return value is @math{0}; a value of @math{-1}
 indicates an error.  If @var{speed} is not a speed, @code{cfsetospeed}
-returns @code{-1}.
+returns @math{-1}.
 @end deftypefun
 
-@comment termios.h
-@comment POSIX.1
 @deftypefun int cfsetispeed (struct termios *@var{termios-p}, speed_t @var{speed})
+@standards{POSIX.1, termios.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
 This function stores @var{speed} in @code{*@var{termios-p}} as the input
-speed.  The normal return value is @code{0}; a value of @code{-1}
+speed.  The normal return value is @math{0}; a value of @math{-1}
 indicates an error.  If @var{speed} is not a speed, @code{cfsetospeed}
-returns @code{-1}.
+returns @math{-1}.
 @end deftypefun
 
-@comment termios.h
-@comment BSD
 @deftypefun int cfsetspeed (struct termios *@var{termios-p}, speed_t @var{speed})
+@standards{BSD, termios.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+@c There's no guarantee that the two calls are atomic, but since this is
+@c not an opaque type, callers ought to ensure mutual exclusion to the
+@c termios object.
+
+@c cfsetspeed ok
+@c  cfsetispeed ok
+@c  cfsetospeed ok
 This function stores @var{speed} in @code{*@var{termios-p}} as both the
-input and output speeds.  The normal return value is @code{0}; a value
-of @code{-1} indicates an error.  If @var{speed} is not a speed,
-@code{cfsetspeed} returns @code{-1}.  This function is an extension in
+input and output speeds.  The normal return value is @math{0}; a value
+of @math{-1} indicates an error.  If @var{speed} is not a speed,
+@code{cfsetspeed} returns @math{-1}.  This function is an extension in
 4.4 BSD.
 @end deftypefun
 
-@comment termios.h
-@comment POSIX.1
 @deftp {Data Type} speed_t
+@standards{POSIX.1, termios.h}
 The @code{speed_t} type is an unsigned integer data type used to
 represent line speeds.
 @end deftp
@@ -1036,9 +1054,9 @@ will succeed.  But they do not check that a particular hardware device
 can actually support the specified speeds---in fact, they don't know
 which device you plan to set the speed for.  If you use @code{tcsetattr}
 to set the speed of a particular device to a value that it cannot
-handle, @code{tcsetattr} returns @code{-1}.
+handle, @code{tcsetattr} returns @math{-1}.
 
-@strong{Portability note:} In the GNU library, the functions above
+@strong{Portability note:} In @theglibc{}, the functions above
 accept speeds measured in bits per second as input, and return speed
 values measured in bits per second.  Other libraries require speeds to
 be indicated by special codes.  For POSIX.1 portability, you must use
@@ -1096,10 +1114,23 @@ the only speeds that typical serial lines can support.
 @comment termios.h
 @comment POSIX.1
 @vindex B38400
+@comment termios.h
+@comment GNU
+@vindex B57600
+@comment termios.h
+@comment GNU
+@vindex B115200
+@comment termios.h
+@comment GNU
+@vindex B230400
+@comment termios.h
+@comment GNU
+@vindex B460800
 @smallexample
 B0  B50  B75  B110  B134  B150  B200
 B300  B600  B1200  B1800  B2400  B4800
-B9600  B19200  B38400
+B9600  B19200  B38400  B57600  B115200
+B230400  B460800
 @end smallexample
 
 @vindex EXTA
@@ -1123,8 +1154,8 @@ The particular characters used are specified in the @code{c_cc} member
 of the @code{struct termios} structure.  This member is an array; each
 element specifies the character for a particular role.  Each element has
 a symbolic constant that stands for the index of that element---for
-example, @code{INTR} is the index of the element that specifies the INTR
-character, so storing @code{'='} in @code{@var{termios}.c_cc[INTR]}
+example, @code{VINTR} is the index of the element that specifies the INTR
+character, so storing @code{'='} in @code{@var{termios}.c_cc[VINTR]}
 specifies @samp{=} as the INTR character.
 
 @vindex _POSIX_VDISABLE
@@ -1151,9 +1182,8 @@ system you are using supports @code{_POSIX_VDISABLE}.
 These special characters are active only in canonical input mode.
 @xref{Canonical or Not}.
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro int VEOF
+@standards{POSIX.1, termios.h}
 @cindex EOF character
 This is the subscript for the EOF character in the special control
 character array.  @code{@var{termios}.c_cc[VEOF]} holds the character
@@ -1168,9 +1198,8 @@ character itself is discarded.
 Usually, the EOF character is @kbd{C-d}.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro int VEOL
+@standards{POSIX.1, termios.h}
 @cindex EOL character
 This is the subscript for the EOL character in the special control
 character array.  @code{@var{termios}.c_cc[VEOL]} holds the character
@@ -1188,9 +1217,8 @@ Just set the ICRNL flag.  In fact, this is the default state of
 affairs.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro int VEOL2
+@standards{BSD, termios.h}
 @cindex EOL2 character
 This is the subscript for the EOL2 character in the special control
 character array.  @code{@var{termios}.c_cc[VEOL2]} holds the character
@@ -1202,12 +1230,11 @@ terminate an input line, by setting EOL to one of them and EOL2 to the
 other.
 
 The EOL2 character is a BSD extension; it exists only on BSD systems
-and the GNU system.
+and @gnulinuxhurdsystems{}.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro int VERASE
+@standards{POSIX.1, termios.h}
 @cindex ERASE character
 This is the subscript for the ERASE character in the special control
 character array.  @code{@var{termios}.c_cc[VERASE]} holds the
@@ -1224,9 +1251,8 @@ The ERASE character itself is discarded.
 Usually, the ERASE character is @key{DEL}.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro int VWERASE
+@standards{BSD, termios.h}
 @cindex WERASE character
 This is the subscript for the WERASE character in the special control
 character array.  @code{@var{termios}.c_cc[VWERASE]} holds the character
@@ -1251,9 +1277,8 @@ The WERASE character is usually @kbd{C-w}.
 This is a BSD extension.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro int VKILL
+@standards{POSIX.1, termios.h}
 @cindex KILL character
 This is the subscript for the KILL character in the special control
 character array.  @code{@var{termios}.c_cc[VKILL]} holds the character
@@ -1266,9 +1291,8 @@ of input are discarded.  The kill character itself is discarded too.
 The KILL character is usually @kbd{C-u}.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro int VREPRINT
+@standards{BSD, termios.h}
 @cindex REPRINT character
 This is the subscript for the REPRINT character in the special control
 character array.  @code{@var{termios}.c_cc[VREPRINT]} holds the character
@@ -1290,9 +1314,8 @@ These special characters may be active in either canonical or noncanonical
 input mode, but only when the @code{ISIG} flag is set (@pxref{Local
 Modes}).
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro int VINTR
+@standards{POSIX.1, termios.h}
 @cindex INTR character
 @cindex interrupt character
 This is the subscript for the INTR character in the special control
@@ -1307,9 +1330,8 @@ information about signals.
 Typically, the INTR character is @kbd{C-c}.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro int VQUIT
+@standards{POSIX.1, termios.h}
 @cindex QUIT character
 This is the subscript for the QUIT character in the special control
 character array.  @code{@var{termios}.c_cc[VQUIT]} holds the character
@@ -1323,9 +1345,8 @@ about signals.
 Typically, the QUIT character is @kbd{C-\}.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro int VSUSP
+@standards{POSIX.1, termios.h}
 @cindex SUSP character
 @cindex suspend character
 This is the subscript for the SUSP character in the special control
@@ -1348,9 +1369,8 @@ mechanism, the program should send a @code{SIGTSTP} signal to the
 process group of the process, not just to the process itself.
 @xref{Signaling Another Process}.
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro int VDSUSP
+@standards{BSD, termios.h}
 @cindex DSUSP character
 @cindex delayed suspend character
 This is the subscript for the DSUSP character in the special control
@@ -1361,7 +1381,7 @@ The DSUSP (suspend) character is recognized only if the implementation
 supports job control (@pxref{Job Control}).  It sends a @code{SIGTSTP}
 signal, like the SUSP character, but not right away---only when the
 program tries to read it as input.  Not all systems with job control
-support DSUSP; only BSD-compatible systems (including the GNU system).
+support DSUSP; only BSD-compatible systems do (including @gnuhurdsystems{}).
 
 @xref{Signal Handling}, for more information about signals.
 
@@ -1375,9 +1395,8 @@ These special characters may be active in either canonical or noncanonical
 input mode, but their use is controlled by the flags @code{IXON} and
 @code{IXOFF} (@pxref{Input Modes}).
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro int VSTART
+@standards{POSIX.1, termios.h}
 @cindex START character
 This is the subscript for the START character in the special control
 character array.  @code{@var{termios}.c_cc[VSTART]} holds the
@@ -1388,7 +1407,7 @@ input modes.  If @code{IXON} is set, receiving a START character resumes
 suspended output; the START character itself is discarded.  If
 @code{IXANY} is set, receiving any character at all resumes suspended
 output; the resuming character is not discarded unless it is the START
-character.  @code{IXOFF} is set, the system may also transmit START
+character.  If @code{IXOFF} is set, the system may also transmit START
 characters to the terminal.
 
 The usual value for the START character is @kbd{C-q}.  You may not be
@@ -1396,9 +1415,8 @@ able to change this value---the hardware may insist on using @kbd{C-q}
 regardless of what you specify.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro int VSTOP
+@standards{POSIX.1, termios.h}
 @cindex STOP character
 This is the subscript for the STOP character in the special control
 character array.  @code{@var{termios}.c_cc[VSTOP]} holds the character
@@ -1418,11 +1436,8 @@ regardless of what you specify.
 @node Other Special
 @subsubsection Other Special Characters
 
-These special characters exist only in BSD systems and the GNU system.
-
-@comment termios.h
-@comment BSD
 @deftypevr Macro int VLNEXT
+@standards{BSD, termios.h}
 @cindex LNEXT character
 This is the subscript for the LNEXT character in the special control
 character array.  @code{@var{termios}.c_cc[VLNEXT]} holds the character
@@ -1436,11 +1451,12 @@ signal, it is read as a plain character.  This is the analogue of the
 @kbd{C-q} command in Emacs.  ``LNEXT'' stands for ``literal next.''
 
 The LNEXT character is usually @kbd{C-v}.
+
+This character is available on BSD systems and @gnulinuxhurdsystems{}.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro int VDISCARD
+@standards{BSD, termios.h}
 @cindex DISCARD character
 This is the subscript for the DISCARD character in the special control
 character array.  @code{@var{termios}.c_cc[VDISCARD]} holds the character
@@ -1451,11 +1467,12 @@ in both canonical and noncanonical mode.  Its effect is to toggle the
 discard-output flag.  When this flag is set, all program output is
 discarded.  Setting the flag also discards all output currently in the
 output buffer.  Typing any other character resets the flag.
+
+This character is available on BSD systems and @gnulinuxhurdsystems{}.
 @end deftypevr
 
-@comment termios.h
-@comment BSD
 @deftypevr Macro int VSTATUS
+@standards{BSD, termios.h}
 @cindex STATUS character
 This is the subscript for the STATUS character in the special control
 character array.  @code{@var{termios}.c_cc[VSTATUS]} holds the character
@@ -1466,6 +1483,8 @@ the current process is running.
 
 The STATUS character is recognized only in canonical mode, and only if
 @code{NOKERNINFO} is not set.
+
+This character is available only on BSD systems and @gnuhurdsystems{}.
 @end deftypevr
 
 @node Noncanonical Input
@@ -1488,12 +1507,11 @@ The MIN and TIME are stored in elements of the @code{c_cc} array, which
 is a member of the @w{@code{struct termios}} structure.  Each element of
 this array has a particular role, and each element has a symbolic
 constant that stands for the index of that element.  @code{VMIN} and
-@code{VMAX} are the names for the indices in the array of the MIN and
+@code{VTIME} are the names for the indices in the array of the MIN and
 TIME slots.
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro int VMIN
+@standards{POSIX.1, termios.h}
 @cindex MIN termios slot
 This is the subscript for the MIN slot in the @code{c_cc} array.  Thus,
 @code{@var{termios}.c_cc[VMIN]} is the value itself.
@@ -1503,9 +1521,8 @@ specifies the minimum number of bytes that must be available in the
 input queue in order for @code{read} to return.
 @end deftypevr
 
-@comment termios.h
-@comment POSIX.1
 @deftypevr Macro int VTIME
+@standards{POSIX.1, termios.h}
 @cindex TIME termios slot
 This is the subscript for the TIME slot in the @code{c_cc} array.  Thus,
 @code{@var{termios}.c_cc[VTIME]} is the value itself.
@@ -1569,12 +1586,15 @@ system for a subsequent call to @code{read}.
 actually the same as the EOF and EOL slots.  This causes no serious
 problem because the MIN and TIME slots are used only in noncanonical
 input and the EOF and EOL slots are used only in canonical input, but it
-isn't very clean.  The GNU library allocates separate slots for these
+isn't very clean.  @Theglibc{} allocates separate slots for these
 uses.
 
-@comment termios.h
-@comment BSD
-@deftypefun int cfmakeraw (struct termios *@var{termios-p})
+@deftypefun void cfmakeraw (struct termios *@var{termios-p})
+@standards{BSD, termios.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+@c There's no guarantee the changes are atomic, but since this is not an
+@c opaque type, callers ought to ensure mutual exclusion to the termios
+@c object.
 This function provides an easy way to set up @code{*@var{termios-p}} for
 what has traditionally been called ``raw mode'' in BSD.  This uses
 noncanonical input, and turns off most processing to give an unmodified
@@ -1591,6 +1611,60 @@ It does exactly this:
 @end smallexample
 @end deftypefun
 
+
+@node BSD Terminal Modes
+@section BSD Terminal Modes
+@cindex terminal modes, BSD
+
+The usual way to get and set terminal modes is with the functions described
+in @ref{Terminal Modes}.  However, on some systems you can use the
+BSD-derived functions in this section to do some of the same things.  On
+many systems, these functions do not exist.  Even with @theglibc{},
+the functions simply fail with @code{errno} = @code{ENOSYS} with many
+kernels, including Linux.
+
+The symbols used in this section are declared in @file{sgtty.h}.
+
+@deftp {Data Type} {struct sgttyb}
+@standards{BSD, termios.h}
+This structure is an input or output parameter list for @code{gtty} and
+@code{stty}.
+
+@table @code
+@item char sg_ispeed
+Line speed for input
+@item char sg_ospeed
+Line speed for output
+@item char sg_erase
+Erase character
+@item char sg_kill
+Kill character
+@item int sg_flags
+Various flags
+@end table
+@end deftp
+
+@deftypefun int gtty (int @var{filedes}, struct sgttyb *@var{attributes})
+@standards{BSD, sgtty.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+@c Direct ioctl, BSD only.
+This function gets the attributes of a terminal.
+
+@code{gtty} sets *@var{attributes} to describe the terminal attributes
+of the terminal which is open with file descriptor @var{filedes}.
+@end deftypefun
+
+@deftypefun int stty (int @var{filedes}, const struct sgttyb *@var{attributes})
+@standards{BSD, sgtty.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+@c Direct ioctl, BSD only.
+
+This function sets the attributes of a terminal.
+
+@code{stty} sets the terminal attributes of the terminal which is open with
+file descriptor @var{filedes} to those described by *@var{attributes}.
+@end deftypefun
+
 @node Line Control
 @section Line Control Functions
 @cindex terminal line control functions
@@ -1604,9 +1678,14 @@ itself is ignoring or blocking @code{SIGTTOU} signals, in which case the
 operation is performed and no signal is sent.  @xref{Job Control}.
 
 @cindex break condition, generating
-@comment termios.h
-@comment POSIX.1
 @deftypefun int tcsendbreak (int @var{filedes}, int @var{duration})
+@standards{POSIX.1, termios.h}
+@safety{@prelim{}@mtunsafe{@mtasurace{:tcattr(filedes)/bsd}}@asunsafe{}@acunsafe{@acucorrupt{/bsd}}}
+@c On Linux, this calls just one out of two ioctls; on BSD, it's two
+@c ioctls with a select (for the delay only) in between, the first
+@c setting and the latter clearing the break status.  The BSD
+@c implementation may leave the break enabled if cancelled, and threads
+@c and signals may cause the break to be interrupted before requested.
 This function generates a break condition by transmitting a stream of
 zero bits on the terminal associated with the file descriptor
 @var{filedes}.  The duration of the break is controlled by the
@@ -1617,7 +1696,7 @@ This function does nothing if the terminal is not an asynchronous serial
 data port.
 
 The return value is normally zero.  In the event of an error, a value
-of @code{-1} is returned.  The following @code{errno} error conditions
+of @math{-1} is returned.  The following @code{errno} error conditions
 are defined for this function:
 
 @table @code
@@ -1632,22 +1711,23 @@ The @var{filedes} is not associated with a terminal device.
 
 @cindex flushing terminal output queue
 @cindex terminal output queue, flushing
-@comment termios.h
-@comment POSIX.1
 @deftypefun int tcdrain (int @var{filedes})
+@standards{POSIX.1, termios.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+@c Direct ioctl.
 The @code{tcdrain} function waits until all queued
 output to the terminal @var{filedes} has been transmitted.
 
-This function is a cancelation point in multi-threaded programs.  This
+This function is a cancellation point in multi-threaded programs.  This
 is a problem if the thread allocates some resources (like memory, file
 descriptors, semaphores or whatever) at the time @code{tcdrain} is
 called.  If the thread gets canceled these resources stay allocated
 until the program ends.  To avoid this calls to @code{tcdrain} should be
-protected using cancelation handlers.
+protected using cancellation handlers.
 @c ref pthread_cleanup_push / pthread_cleanup_pop
 
 The return value is normally zero.  In the event of an error, a value
-of @code{-1} is returned.  The following @code{errno} error conditions
+of @math{-1} is returned.  The following @code{errno} error conditions
 are defined for this function:
 
 @table @code
@@ -1666,34 +1746,32 @@ The operation was interrupted by delivery of a signal.
 
 @cindex clearing terminal input queue
 @cindex terminal input queue, clearing
-@comment termios.h
-@comment POSIX.1
 @deftypefun int tcflush (int @var{filedes}, int @var{queue})
+@standards{POSIX.1, termios.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+@c Direct ioctl.
 The @code{tcflush} function is used to clear the input and/or output
 queues associated with the terminal file @var{filedes}.  The @var{queue}
 argument specifies which queue(s) to clear, and can be one of the
 following values:
 
 @c Extra blank lines here make it look better.
-@table @code
-@vindex TCIFLUSH
+@vtable @code
 @item TCIFLUSH
 
 Clear any input data received, but not yet read.
 
-@vindex TCOFLUSH
 @item TCOFLUSH
 
 Clear any output data written, but not yet transmitted.
 
-@vindex TCIOFLUSH
 @item TCIOFLUSH
 
 Clear both queued input and output.
-@end table
+@end vtable
 
 The return value is normally zero.  In the event of an error, a value
-of @code{-1} is returned.  The following @code{errno} error conditions
+of @math{-1} is returned.  The following @code{errno} error conditions
 are defined for this function:
 
 @table @code
@@ -1716,38 +1794,38 @@ from POSIX and we cannot change it.
 
 @cindex flow control, terminal
 @cindex terminal flow control
-@comment termios.h
-@comment POSIX.1
 @deftypefun int tcflow (int @var{filedes}, int @var{action})
+@standards{POSIX.1, termios.h}
+@safety{@prelim{}@mtunsafe{@mtasurace{:tcattr(filedes)/bsd}}@asunsafe{}@acsafe{}}
+@c Direct ioctl on Linux.  On BSD, the TCO* actions are a single ioctl,
+@c whereas the TCI actions first call tcgetattr and then write to the fd
+@c the c_cc character corresponding to the action; there's a window for
+@c another thread to change the xon/xoff characters.
 The @code{tcflow} function is used to perform operations relating to
 XON/XOFF flow control on the terminal file specified by @var{filedes}.
 
 The @var{action} argument specifies what operation to perform, and can
 be one of the following values:
 
-@table @code
-@vindex TCOOFF
+@vtable @code
 @item TCOOFF
 Suspend transmission of output.
 
-@vindex TCOON
 @item TCOON
 Restart transmission of output.
 
-@vindex TCIOFF
 @item TCIOFF
 Transmit a STOP character.
 
-@vindex TCION
 @item TCION
 Transmit a START character.
-@end table
+@end vtable
 
 For more information about the STOP and START characters, see @ref{Special
 Characters}.
 
 The return value is normally zero.  In the event of an error, a value
-of @code{-1} is returned.  The following @code{errno} error conditions
+of @math{-1} is returned.  The following @code{errno} error conditions
 are defined for this function:
 
 @table @code
@@ -1793,3 +1871,366 @@ a process is stopped or continued; see @ref{Job Control}.  But some
 existing shells do not actually do this, so you may wish to establish
 handlers for job control signals that reset terminal modes.  The above
 example does so.
+
+@node getpass
+@section Reading Passphrases
+
+When reading in a passphrase, it is desirable to avoid displaying it on
+the screen, to help keep it secret.  The following function handles this
+in a convenient way.
+
+@deftypefun {char *} getpass (const char *@var{prompt})
+@standards{BSD, unistd.h}
+@safety{@prelim{}@mtunsafe{@mtasuterm{}}@asunsafe{@ascuheap{} @asulock{} @asucorrupt{}}@acunsafe{@acuterm{} @aculock{} @acucorrupt{}}}
+@c This function will attempt to create a stream for terminal I/O, but
+@c will fallback to stdio/stderr.  It attempts to change the terminal
+@c mode in a thread-unsafe way, write out the prompt, read the passphrase,
+@c then restore the terminal mode.  It has a cleanup to close the stream
+@c in case of (synchronous) cancellation, but not to restore the
+@c terminal mode.
+
+@code{getpass} outputs @var{prompt}, then reads a string in from the
+terminal without echoing it.  It tries to connect to the real terminal,
+@file{/dev/tty}, if possible, to encourage users not to put plaintext
+passphrases in files; otherwise, it uses @code{stdin} and @code{stderr}.
+@code{getpass} also disables the INTR, QUIT, and SUSP characters on the
+terminal using the @code{ISIG} terminal attribute (@pxref{Local Modes}).
+The terminal is flushed before and after @code{getpass}, so that
+characters of a mistyped passphrase are not accidentally visible.
+
+In other C libraries, @code{getpass} may only return the first
+@code{PASS_MAX} bytes of a passphrase.  @Theglibc{} has no limit, so
+@code{PASS_MAX} is undefined.
+
+The prototype for this function is in @file{unistd.h}.  @code{PASS_MAX}
+would be defined in @file{limits.h}.
+@end deftypefun
+
+This precise set of operations may not suit all possible situations.  In
+this case, it is recommended that users write their own @code{getpass}
+substitute.  For instance, a very simple substitute is as follows:
+
+@smallexample
+@include mygetpass.c.texi
+@end smallexample
+
+The substitute takes the same parameters as @code{getline}
+(@pxref{Line Input}); the user must print any prompt desired.
+
+@node Pseudo-Terminals
+@section Pseudo-Terminals
+@cindex pseudo-terminals
+
+A @dfn{pseudo-terminal} is a special interprocess communication channel
+that acts like a terminal.  One end of the channel is called the
+@dfn{master} side or @dfn{master pseudo-terminal device}, the other side
+is called the @dfn{slave} side.  Data written to the master side is
+received by the slave side as if it was the result of a user typing at
+an ordinary terminal, and data written to the slave side is sent to the
+master side as if it was written on an ordinary terminal.
+
+Pseudo terminals are the way programs like @code{xterm} and @code{emacs}
+implement their terminal emulation functionality.
+
+@menu
+* Allocation::             Allocating a pseudo terminal.
+* Pseudo-Terminal Pairs::  How to open both sides of a
+                            pseudo-terminal in a single operation.
+@end menu
+
+@node Allocation
+@subsection Allocating Pseudo-Terminals
+@cindex allocating pseudo-terminals
+
+@pindex stdlib.h
+This subsection describes functions for allocating a pseudo-terminal,
+and for making this pseudo-terminal available for actual use.  These
+functions are declared in the header file @file{stdlib.h}.
+
+@deftypefun int getpt (void)
+@standards{GNU, stdlib.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{@acsfd{}}}
+@c On BSD, tries to open multiple potential pty names, returning on the
+@c first success.  On Linux, try posix_openpt first, then fallback to
+@c the BSD implementation.  The posix implementation opens the ptmx
+@c device, checks with statfs that /dev/pts is a devpts or that /dev is
+@c a devfs, and returns the fd; static variables devpts_mounted and
+@c have_no_dev_ptmx are safely initialized so as to avoid repeated
+@c tests.
+The @code{getpt} function returns a new file descriptor for the next
+available master pseudo-terminal.  The normal return value from
+@code{getpt} is a non-negative integer file descriptor.  In the case of
+an error, a value of @math{-1} is returned instead.  The following
+@code{errno} conditions are defined for this function:
+
+@table @code
+@item ENOENT
+There are no free master pseudo-terminals available.
+@end table
+
+This function is a GNU extension.
+@end deftypefun
+
+@deftypefun int grantpt (int @var{filedes})
+@standards{SVID, stdlib.h}
+@standards{XPG4.2, stdlib.h}
+@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@ascudlopen{} @ascuplugin{} @ascuheap{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsfd{} @acsmem{}}}
+@c grantpt @mtslocale @ascudlopen @ascuplugin @ascuheap @asulock @acucorrupt @aculock @acsfd @acsmem
+@c  unix/grantpt:pts_name @acsuheap @acsmem
+@c   ptsname_internal dup ok (but this is Linux-only!)
+@c   memchr dup ok
+@c   realloc dup @acsuheap @acsmem
+@c   malloc dup @acsuheap @acsmem
+@c   free dup @acsuheap @acsmem
+@c  fcntl dup ok
+@c  getuid dup ok
+@c  chown dup ok
+@c  sysconf(_SC_GETGR_R_SIZE_MAX) ok
+@c  getgrnam_r @mtslocale @ascudlopen @ascuplugin @ascuheap @asulock @acucorrupt @aculock @acsfd @acsmem
+@c  getgid dup ok
+@c  chmod dup ok
+@c  fork dup @aculock
+@c  [child]
+@c   setrlimit
+@c   dup2
+@c   CLOSE_ALL_FDS
+@c   execle
+@c   _exit
+@c  waitpid dup ok
+@c  WIFEXITED dup ok
+@c  WEXITSTATUS dup ok
+@c  free dup @ascuheap @acsmem
+The @code{grantpt} function changes the ownership and access permission
+of the slave pseudo-terminal device corresponding to the master
+pseudo-terminal device associated with the file descriptor
+@var{filedes}.  The owner is set from the real user ID of the calling
+process (@pxref{Process Persona}), and the group is set to a special
+group (typically @dfn{tty}) or from the real group ID of the calling
+process.  The access permission is set such that the file is both
+readable and writable by the owner and only writable by the group.
+
+On some systems this function is implemented by invoking a special
+@code{setuid} root program (@pxref{How Change Persona}).  As a
+consequence, installing a signal handler for the @code{SIGCHLD} signal
+(@pxref{Job Control Signals}) may interfere with a call to
+@code{grantpt}.
+
+The normal return value from @code{grantpt} is @math{0}; a value of
+@math{-1} is returned in case of failure.  The following @code{errno}
+error conditions are defined for this function:
+
+@table @code
+@item EBADF
+The @var{filedes} argument is not a valid file descriptor.
+
+@item EINVAL
+The @var{filedes} argument is not associated with a master pseudo-terminal
+device.
+
+@item EACCES
+The slave pseudo-terminal device corresponding to the master associated
+with @var{filedes} could not be accessed.
+@end table
+
+@end deftypefun
+
+@deftypefun int unlockpt (int @var{filedes})
+@standards{SVID, stdlib.h}
+@standards{XPG4.2, stdlib.h}
+@safety{@prelim{}@mtsafe{}@asunsafe{@ascuheap{/bsd}}@acunsafe{@acsmem{} @acsfd{}}}
+@c unlockpt @ascuheap/bsd @acsmem @acsfd
+@c /bsd
+@c  ptsname_r dup @ascuheap @acsmem @acsfd
+@c  revoke ok (syscall)
+@c /linux
+@c  ioctl dup ok
+The @code{unlockpt} function unlocks the slave pseudo-terminal device
+corresponding to the master pseudo-terminal device associated with the
+file descriptor @var{filedes}.  On many systems, the slave can only be
+opened after unlocking, so portable applications should always call
+@code{unlockpt} before trying to open the slave.
+
+The normal return value from @code{unlockpt} is @math{0}; a value of
+@math{-1} is returned in case of failure.  The following @code{errno}
+error conditions are defined for this function:
+
+@table @code
+@item EBADF
+The @var{filedes} argument is not a valid file descriptor.
+
+@item EINVAL
+The @var{filedes} argument is not associated with a master pseudo-terminal
+device.
+@end table
+@end deftypefun
+
+@deftypefun {char *} ptsname (int @var{filedes})
+@standards{SVID, stdlib.h}
+@standards{XPG4.2, stdlib.h}
+@safety{@prelim{}@mtunsafe{@mtasurace{:ptsname}}@asunsafe{@ascuheap{/bsd}}@acunsafe{@acsmem{} @acsfd{}}}
+@c ptsname @mtasurace:ptsname @ascuheap/bsd @acsmem @acsfd
+@c  ptsname_r dup @ascuheap/bsd @acsmem @acsfd
+If the file descriptor @var{filedes} is associated with a
+master pseudo-terminal device, the @code{ptsname} function returns a
+pointer to a statically-allocated, null-terminated string containing the
+file name of the associated slave pseudo-terminal file.  This string
+might be overwritten by subsequent calls to @code{ptsname}.
+@end deftypefun
+
+@deftypefun int ptsname_r (int @var{filedes}, char *@var{buf}, size_t @var{len})
+@standards{GNU, stdlib.h}
+@safety{@prelim{}@mtsafe{}@asunsafe{@ascuheap{/bsd}}@acunsafe{@acsmem{} @acsfd{}}}
+@c ptsname_r @ascuheap/bsd @acsmem @acsfd
+@c /hurd
+@c  term_get_peername ok
+@c  strlen dup ok
+@c  memcpy dup ok
+@c /bsd
+@c  isatty dup ok
+@c  strlen dup ok
+@c  ttyname_r dup @ascuheap @acsmem @acsfd
+@c  stat dup ok
+@c /linux
+@c  ptsname_internal ok
+@c   isatty dup ok
+@c   ioctl dup ok
+@c   strlen dup ok
+@c   itoa_word dup ok
+@c   stpcpy dup ok
+@c   memcpy dup ok
+@c   fxstat64 dup ok
+@c   MASTER_P ok
+@c    major ok
+@c     gnu_dev_major ok
+@c    minor ok
+@c     gnu_dev_minor ok
+@c   minor dup ok
+@c   xstat64 dup ok
+@c   S_ISCHR dup ok
+@c   SLAVE_P ok
+@c    major dup ok
+@c    minor dup ok
+The @code{ptsname_r} function is similar to the @code{ptsname} function
+except that it places its result into the user-specified buffer starting
+at @var{buf} with length @var{len}.
+
+This function is a GNU extension.
+@end deftypefun
+
+Typical usage of these functions is illustrated by the following example:
+@smallexample
+int
+open_pty_pair (int *amaster, int *aslave)
+@{
+  int master, slave;
+  char *name;
+
+  master = getpt ();
+  if (master < 0)
+    return 0;
+
+  if (grantpt (master) < 0 || unlockpt (master) < 0)
+    goto close_master;
+  name = ptsname (master);
+  if (name == NULL)
+    goto close_master;
+
+  slave = open (name, O_RDWR);
+  if (slave == -1)
+    goto close_master;
+
+  *amaster = master;
+  *aslave = slave;
+  return 1;
+
+close_slave:
+  close (slave);
+
+close_master:
+  close (master);
+  return 0;
+@}
+@end smallexample
+
+@node Pseudo-Terminal Pairs
+@subsection Opening a Pseudo-Terminal Pair
+@cindex opening a pseudo-terminal pair
+
+These functions, derived from BSD, are available in the separate
+@file{libutil} library, and declared in @file{pty.h}.
+
+@deftypefun int openpty (int *@var{amaster}, int *@var{aslave}, char *@var{name}, const struct termios *@var{termp}, const struct winsize *@var{winp})
+@standards{BSD, pty.h}
+@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@ascudlopen{} @ascuplugin{} @ascuheap{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsfd{} @acsmem{}}}
+@c openpty @mtslocale @ascudlopen @ascuplugin @ascuheap @asulock @acucorrupt @aculock @acsfd @acsmem
+@c  getpt @acsfd
+@c  grantpt @mtslocale @ascudlopen @ascuplugin @ascuheap @asulock @acucorrupt @aculock @acsfd @acsmem
+@c  unlockpt dup @ascuheap/bsd @acsmem @acsfd
+@c  openpty:pts_name @acsuheap @acsmem @acsfd
+@c   ptsname_r dup @ascuheap/bsd @acsmem @acsfd
+@c   realloc dup @acsuheap @acsmem
+@c   malloc dup @acsuheap @acsmem
+@c   free dup @acsuheap @acsmem
+@c  open dup @acsfd
+@c  free dup @acsuheap @acsmem
+@c  tcsetattr dup ok
+@c  ioctl dup ok
+@c  strcpy dup ok
+@c  close dup @acsfd
+This function allocates and opens a pseudo-terminal pair, returning the
+file descriptor for the master in @var{*amaster}, and the file
+descriptor for the slave in @var{*aslave}.  If the argument @var{name}
+is not a null pointer, the file name of the slave pseudo-terminal
+device is stored in @code{*name}.  If @var{termp} is not a null pointer,
+the terminal attributes of the slave are set to the ones specified in
+the structure that @var{termp} points to (@pxref{Terminal Modes}).
+Likewise, if @var{winp} is not a null pointer, the screen size of
+the slave is set to the values specified in the structure that
+@var{winp} points to.
+
+The normal return value from @code{openpty} is @math{0}; a value of
+@math{-1} is returned in case of failure.  The following @code{errno}
+conditions are defined for this function:
+
+@table @code
+@item ENOENT
+There are no free pseudo-terminal pairs available.
+@end table
+
+@strong{Warning:} Using the @code{openpty} function with @var{name} not
+set to @code{NULL} is @strong{very dangerous} because it provides no
+protection against overflowing the string @var{name}.  You should use
+the @code{ttyname} function on the file descriptor returned in
+@var{*slave} to find out the file name of the slave pseudo-terminal
+device instead.
+@end deftypefun
+
+@deftypefun int forkpty (int *@var{amaster}, char *@var{name}, const struct termios *@var{termp}, const struct winsize *@var{winp})
+@standards{BSD, pty.h}
+@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@ascudlopen{} @ascuplugin{} @ascuheap{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsfd{} @acsmem{}}}
+@c forkpty @mtslocale @ascudlopen @ascuplugin @ascuheap @asulock @acucorrupt @aculock @acsfd @acsmem
+@c  openpty dup @mtslocale @ascudlopen @ascuplugin @ascuheap @asulock @acucorrupt @aculock @acsfd @acsmem
+@c  fork dup @aculock
+@c  close dup @acsfd
+@c  /child
+@c   close dup @acsfd
+@c   login_tty dup @mtasurace:ttyname @ascuheap @asulock @aculock @acsmem @acsfd
+@c   _exit dup ok
+@c  close dup @acsfd
+This function is similar to the @code{openpty} function, but in
+addition, forks a new process (@pxref{Creating a Process}) and makes the
+newly opened slave pseudo-terminal device the controlling terminal
+(@pxref{Controlling Terminal}) for the child process.
+
+If the operation is successful, there are then both parent and child
+processes and both see @code{forkpty} return, but with different values:
+it returns a value of @math{0} in the child process and returns the child's
+process ID in the parent process.
+
+If the allocation of a pseudo-terminal pair or the process creation
+failed, @code{forkpty} returns a value of @math{-1} in the parent
+process.
+
+@strong{Warning:} The @code{forkpty} function has the same problems with
+respect to the @var{name} argument as @code{openpty}.
+@end deftypefun