xref: /csrg-svn/lib/libc/gen/tcsetattr.3 (revision 65325)
161111Sbostic.\" Copyright (c) 1991, 1993
261111Sbostic.\"	The Regents of the University of California.  All rights reserved.
351199Smarc.\"
451199Smarc.\" %sccs.include.redist.roff%
551199Smarc.\"
6*65325Sbostic.\"	@(#)tcsetattr.3	8.3 (Berkeley) 01/02/94
751199Smarc.\"
852295Sbostic.Dd ""
951199Smarc.Dt TCSETATTR 3
1051199Smarc.Os
1151199Smarc.Sh NAME
1252295Sbostic.Nm cfgetispeed ,
1352295Sbostic.Nm cfsetispeed ,
1452295Sbostic.Nm cfgetospeed ,
1552295Sbostic.Nm cfsetospeed ,
1652295Sbostic.Nm cfsetspeed ,
1752295Sbostic.Nm cfmakeraw ,
1852295Sbostic.Nm tcgetattr ,
1951199Smarc.Nm tcsetattr
2052295Sbostic.Nd manipulating the termios structure
2152295Sbostic.Sh SYNOPSIS
2252295Sbostic.Fd #include <termios.h>
2352295Sbostic.Ft speed_t
2452295Sbostic.Fn cfgetispeed "struct termios *t"
2552295Sbostic.Ft int
2652295Sbostic.Fn cfsetispeed "struct termios *t" "speed_t speed"
2752295Sbostic.Ft speed_t
2852295Sbostic.Fn cfgetospeed "struct termios *t"
2952295Sbostic.Ft int
3052295Sbostic.Fn cfsetospeed "struct termios *t" "speed_t speed"
31*65325Sbostic.Ft int
3252295Sbostic.Fn cfsetspeed "struct termios *t" "speed_t speed"
3352295Sbostic.Ft void
3452295Sbostic.Fn cfmakeraw "struct termios *t"
3552295Sbostic.Ft int
3652295Sbostic.Fn tcgetattr "int fd" "struct termios *t"
3752295Sbostic.Ft int
3852295Sbostic.Fn tcsetattr "int fd" "int action" "struct termios *t"
3952295Sbostic.Sh DESCRIPTION
4052295SbosticThe
4152295Sbostic.Nm cfmakeraw ,
4252295Sbostic.Nm tcgetattr
4352295Sbosticand
4452295Sbostic.Nm tcsetattr
4552295Sbosticfunctions are provided for getting and setting the termios structure.
4652295Sbostic.Pp
4752295SbosticThe
4852295Sbostic.Nm cfgetispeed ,
4952295Sbostic.Nm cfsetispeed ,
5052295Sbostic.Nm cfgetospeed ,
5152295Sbostic.Nm cfsetospeed
5252295Sbosticand
5352295Sbostic.Nm cfsetspeed
5452295Sbosticfunctions are provided for getting and setting the baud rate values in
5552295Sbosticthe termios structure.
5652295SbosticThe effects of the functions on the terminal as described below
5752295Sbosticdo not become effective, nor are all errors detected, until the
5852295Sbostic.Nm tcsetattr
5952295Sbosticfunction is called.
6052295SbosticCertain values for baud rates set in the termios structure and passed to
6152295Sbostic.Nm tcsetattr
6252295Sbostichave special meanings.
6352295SbosticThese are discussed in the portion of the manual page that describes the
6452295Sbostic.Nm tcsetattr
6552295Sbosticfunction.
6652295Sbostic.Sh GETTING AND SETTING THE BAUD RATE
6752295SbosticThe input and output baud rates are found in the termios structure.
6852295SbosticThe unsigned integer
6952295Sbostic.Li speed_t
7052295Sbosticis typdef'd in the include file
7152295Sbostic.Aq Pa termios.h .
7252295SbosticThe value of the integer corresponds directly to the baud rate being
7352295Sbosticrepresented, however, the following symbolic values are defined.
7452295Sbostic.Bd -literal
7552295Sbostic#define B0	0
7652295Sbostic#define B50	50
7752295Sbostic#define B75	75
7852295Sbostic#define B110	110
7952295Sbostic#define B134	134
8052295Sbostic#define B150	150
8152295Sbostic#define B200	200
8252295Sbostic#define B300	300
8352295Sbostic#define B600	600
8452295Sbostic#define B1200	1200
8552295Sbostic#define	B1800	1800
8652295Sbostic#define B2400	2400
8752295Sbostic#define B4800	4800
8852295Sbostic#define B9600	9600
8952295Sbostic#define B19200	19200
9052295Sbostic#define B38400	38400
9152295Sbostic#ifndef _POSIX_SOURCE
9252295Sbostic#define EXTA	19200
9352295Sbostic#define EXTB	38400
9452295Sbostic#endif  /*_POSIX_SOURCE */
9552295Sbostic.Ed
9652295Sbostic.Pp
9752295SbosticThe
9852295Sbostic.Nm cfgetispeed
9952295Sbosticfunction returns the input baud rate in the termios structure referenced by
10052295Sbostic.Fa tp .
10152295Sbostic.Pp
10252295SbosticThe
10352295Sbostic.Nm cfsetispeed
10452295Sbosticfunction sets the input baud rate in the termios structure referenced by
10552295Sbostic.Fa tp
10652295Sbosticto
10752295Sbostic.Fa speed .
10852295Sbostic.Pp
10952295SbosticThe
11052295Sbostic.Nm cfgetospeed
11152295Sbosticfunction returns the output baud rate in the termios structure referenced by
11252295Sbostic.Fa tp .
11352295Sbostic.Pp
11452295SbosticThe
11552295Sbostic.Nm cfsetospeed
11652295Sbosticfunction sets the output baud rate in the termios structure referenced by
11752295Sbostic.Fa tp
11852295Sbosticto
11952295Sbostic.Fa speed .
12052295Sbostic.Pp
12152295SbosticThe
12252295Sbostic.Nm cfsetspeed
12352295Sbosticfunction sets both the input and output baud rate in the termios structure
12452295Sbosticreferenced by
12552295Sbostic.Fa tp
12652295Sbosticto
12752295Sbostic.Fa speed .
12852295Sbostic.Pp
12952295SbosticUpon successful completion, the functions
13052295Sbostic.Nm cfsetispeed ,
13152295Sbostic.Nm cfsetospeed ,
13252295Sbosticand
13352295Sbostic.Nm cfsetspeed
13452295Sbosticreturn a value of 0.
13552295SbosticOtherwise, a value of -1 is returned and the global variable
13652295Sbostic.Va errno
13752295Sbosticis set to indicate the error.
13852295Sbostic.Sh GETTING AND SETTING THE TERMIOS STATE
13952295SbosticThis section describes the functions that are used to control the general
14052295Sbosticterminal interface.
14152295SbosticUnless otherwise noted for a specific command, these functions are restricted
14252295Sbosticfrom use by background processes.
14352295SbosticAttempts to perform these operations shall cause the process group to be sent
14452295Sbostica SIGTTOU signal.
14552295SbosticIf the calling process is blocking or ignoring SIGTTOU signals, the process
14651199Smarcis allowed to perform the operation and the SIGTTOU signal is not sent.
14752295Sbostic.Pp
14852295SbosticIn all the functions, although
14952295Sbostic.Fa fd
15052295Sbosticis an open file descriptor, the functions affect the underlying terminal
15152295Sbosticfile, not just the open file description associated with the particular
15252295Sbosticfile descriptor.
15352295Sbostic.Pp
15452295SbosticThe
15552295Sbostic.Nm cfmakeraw
15652295Sbosticfunction sets the flags stored in the termios structure to a state disabling
15752295Sbosticall input and output processing, giving a
15852295Sbostic.Dq raw I/O path.
15952295SbosticIt should be noted that there is no function to reverse this effect.
16052295SbosticThis is because there are a variety of processing options that could be
16152295Sbosticre-enabled and the correct method is for an application to snapshot the
16252295Sbosticcurrent terminal state using the function
16352295Sbostic.Nm tcgetattr ,
16452295Sbosticsetting raw mode with
16552295Sbostic.Nm cfmakeraw
16652295Sbosticand the subsequent
16752295Sbostic.Nm tcsetattr ,
16852295Sbosticand then using another
16952295Sbostic.Nm tcsetattr
17052295Sbosticwith the saved state to revert to the previous terminal state.
17152295Sbostic.Pp
17252295SbosticThe
17352295Sbostic.Nm tcgetattr
17452295Sbosticfunction copies the parameters associated with the terminal referenced
17552295Sbosticby
17652295Sbostic.Fa fd
17752295Sbosticin the termios structure referenced by
17852295Sbostic.Fa tp .
17952295SbosticThis function is allowed from a background process, however, the terminal
18052295Sbosticattributes may be subsequently changed by a foreground process.
18152295Sbostic.Pp
18252295SbosticThe
18352295Sbostic.Nm tcsetattr
18452295Sbosticfunction sets the parameters associated with the terminal from the
18552295Sbostictermios structure referenced by
18652295Sbostic.Fa tp .
18752295SbosticThe
18852295Sbostic.Fa action
18952295Sbosticfield is created by
19052295Sbostic.Em or Ns 'ing
19152295Sbosticthe following values, as specified in the include file
19252295Sbostic.Aq Pa termios.h .
19352295Sbostic.Bl -tag -width "TCSADRAIN"
19452295Sbostic.It Fa TCSANOW
19552295SbosticThe change occurs immediately.
19652295Sbostic.It Fa TCSADRAIN
19752295SbosticThe change occurs after all output written to
19852295Sbostic.Fa fd
19952295Sbostichas been transmitted to the terminal.
20052295SbosticThis value of
20152295Sbostic.Fa action
20252295Sbosticshould be used when changing parameters that affect output.
20352295Sbostic.It Fa TCSAFLUSH
20452295SbosticThe change occurs after all output written to
20552295Sbostic.Fa fd
20665099Smckusickhas been transmitted to the terminal.
20752295SbosticAdditionally, any input that has been received but not read is discarded.
20852295Sbostic.It Fa TCSASOFT
20952295SbosticIf this value is
21052295Sbostic.Em or Ns 'ed
21152295Sbosticinto the
21252295Sbostic.Fa action
21352295Sbosticvalue, the values of the
21452295Sbostic.Em c_cflag ,
21552295Sbostic.Em c_ispeed ,
21652295Sbosticand
21752295Sbostic.Em c_ospeed
21852295Sbosticfields are ignored.
21952295Sbostic.El
22052295Sbostic.Pp
22152295SbosticThe 0 baud rate is used to terminate the connection.
22252295SbosticIf 0 is specified as the output speed to the function
22352295Sbostic.Nm tcsetattr ,
22452295Sbosticmodem control will no longer be asserted on the terminal, disconnecting
22552295Sbosticthe terminal.
22652295Sbostic.Pp
22752295SbosticIf zero is specified as the input speed to the function
22852295Sbostic.Nm tcsetattr ,
22952295Sbosticthe input baud rate will be set to the same value as that specified by
23052295Sbosticthe output baud rate.
23152295Sbostic.Pp
23252295SbosticIf
23352295Sbostic.Nm tcsetattr
23465099Smckusickis unable to make any of the requested changes, it returns -1 and
23552295Sbosticsets errno.
23652295SbosticOtherwise, it makes all of the requested changes it can.
23752295SbosticIf the specified input and output baud rates differ and are a combination
23852295Sbosticthat is not supported, neither baud rate is changed.
23952295Sbostic.Pp
24052295SbosticUpon successful completion, the functions
24152295Sbostic.Nm tcgetattr
24252295Sbosticand
24352295Sbostic.Nm tcsetattr
24452295Sbosticreturn a value of 0.
24552295SbosticOtherwise, they
24652295Sbosticreturn -1 and the global variable
24752295Sbostic.Va errno
24852295Sbosticis set to indicate the error, as follows:
24952295Sbostic.Bl -tag -width Er
25052295Sbostic.It Bq Er EBADF
25152295SbosticThe
25252295Sbostic.Fa fd
25352295Sbosticargument to
25452295Sbostic.Nm tcgetattr
25552295Sbosticor
25652295Sbostic.Nm tcsetattr
25752295Sbosticwas not a valid file descriptor.
25852295Sbostic.It Bq Er EINTR
25952295SbosticThe
26052295Sbostic.Nm tcsetattr
26152295Sbosticfunction was interrupted by a signal.
26252295Sbostic.It Bq Er EINVAL
26352295SbosticThe
26452295Sbostic.Fa action
26552295Sbosticargument to the
26652295Sbostic.Nm tcsetattr
26752295Sbosticfunction was not valid, or an attempt was made to change an attribute
26852295Sbosticrepresented in the termios structure to an unsupported value.
26952295Sbostic.It Bq Er ENOTTY
27052295SbosticThe file associated with the
27152295Sbostic.Fa fd
27252295Sbosticargument to
27352295Sbostic.Nm tcgetattr
27452295Sbosticor
27552295Sbostic.Nm tcsetattr
27652295Sbosticis not a terminal.
27752295Sbostic.El
27852295Sbostic.Sh SEE ALSO
27952833Sbostic.Xr tcsendbreak 3 ,
28052295Sbostic.Xr termios 4
28152295Sbostic.Sh STANDARDS
28252295SbosticThe
28352295Sbostic.Nm cfgetispeed ,
28452295Sbostic.Nm cfsetispeed ,
28552295Sbostic.Nm cfgetospeed ,
28652295Sbostic.Nm cfsetospeed ,
28752295Sbostic.Nm tcgetattr
28852295Sbosticand
28952295Sbostic.Nm tcsetattr
29052295Sbosticfunctions are expected to be compliant with the
29152295Sbostic.St -p1003.1-88
29252295Sbosticspecification.
29352295SbosticThe
29452295Sbostic.Nm cfmakeraw
29552295Sbosticand
29652295Sbostic.Nm cfsetspeed
29752295Sbosticfunctions,
29852295Sbosticas well as the
29952295Sbostic.Li TCSASOFT
30052295Sbosticoption to the
30152295Sbostic.Nm tcsetattr
30252295Sbosticfunction are extensions to the
30352295Sbostic.St -p1003.1-88
30452295Sbosticspecification.
305