📄 library_16.html
字号:
<A NAME="IDX1159"></A>
<U>Function:</U> speed_t <B>cfgetospeed</B> <I>(const struct termios *<VAR>termios_p</VAR>)</I><P>
This function returns the output line speed stored in the structure
<CODE>*<VAR>termios_p</VAR></CODE>.
<P>
<A NAME="IDX1160"></A>
<U>Function:</U> speed_t <B>cfgetispeed</B> <I>(const struct termios *<VAR>termios_p</VAR>)</I><P>
This function returns the input line speed stored in the structure
<CODE>*<VAR>termios_p</VAR></CODE>.
<P>
<A NAME="IDX1161"></A>
<U>Function:</U> int <B>cfsetospeed</B> <I>(struct termios *<VAR>termios_p</VAR>, speed_t <VAR>speed</VAR>)</I><P>
This function stores <VAR>speed</VAR> in <CODE>*<VAR>termios_p</VAR></CODE> as the output
speed. The normal return value is <CODE>0</CODE>; a value of <CODE>-1</CODE>
indicates an error. If <VAR>speed</VAR> is not a speed, <CODE>cfsetospeed</CODE>
returns <CODE>-1</CODE>.
<P>
<A NAME="IDX1162"></A>
<U>Function:</U> int <B>cfsetispeed</B> <I>(struct termios *<VAR>termios_p</VAR>, speed_t <VAR>speed</VAR>)</I><P>
This function stores <VAR>speed</VAR> in <CODE>*<VAR>termios_p</VAR></CODE> as the input
speed. The normal return value is <CODE>0</CODE>; a value of <CODE>-1</CODE>
indicates an error. If <VAR>speed</VAR> is not a speed, <CODE>cfsetospeed</CODE>
returns <CODE>-1</CODE>.
<P>
<A NAME="IDX1163"></A>
<U>Function:</U> int <B>cfsetspeed</B> <I>(struct termios *<VAR>termios_p</VAR>, speed_t <VAR>speed</VAR>)</I><P>
This function stores <VAR>speed</VAR> in <CODE>*<VAR>termios_p</VAR></CODE> as both the
input and output speeds. The normal return value is <CODE>0</CODE>; a value
of <CODE>-1</CODE> indicates an error. If <VAR>speed</VAR> is not a speed,
<CODE>cfsetspeed</CODE> returns <CODE>-1</CODE>. This function is an extension in
4.4 BSD.
<P>
<A NAME="IDX1164"></A>
<U>Data Type:</U> <B>speed_t</B><P>
The <CODE>speed_t</CODE> type is an unsigned integer data type used to
represent line speeds.
<P>
The functions <CODE>cfsetospeed</CODE> and <CODE>cfsetispeed</CODE> report errors
only for speed values that the system simply cannot handle. If you
specify a speed value that is basically acceptable, then those functions
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</CODE>
to set the speed of a particular device to a value that it cannot
handle, <CODE>tcsetattr</CODE> returns <CODE>-1</CODE>.
<P>
<STRONG>Portability note:</STRONG> In the GNU library, 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
one of the following symbols to represent the speed; their precise
numeric values are system-dependent, but each name has a fixed meaning:
<CODE>B110</CODE> stands for 110 bps, <CODE>B300</CODE> for 300 bps, and so on.
There is no portable way to represent any speed but these, but these are
the only speeds that typical serial lines can support.
<A NAME="IDX1165"></A>
<A NAME="IDX1166"></A>
<A NAME="IDX1167"></A>
<A NAME="IDX1168"></A>
<A NAME="IDX1169"></A>
<A NAME="IDX1170"></A>
<A NAME="IDX1171"></A>
<A NAME="IDX1172"></A>
<A NAME="IDX1173"></A>
<A NAME="IDX1174"></A>
<A NAME="IDX1175"></A>
<A NAME="IDX1176"></A>
<A NAME="IDX1177"></A>
<A NAME="IDX1178"></A>
<A NAME="IDX1179"></A>
<A NAME="IDX1180"></A>
<P>
<PRE>
B0 B50 B75 B110 B134 B150 B200
B300 B600 B1200 B1800 B2400 B4800
B9600 B19200 B38400
</PRE>
<A NAME="IDX1181"></A>
<A NAME="IDX1182"></A>
<P>
BSD defines two additional speed symbols as aliases: <CODE>EXTA</CODE> is an
alias for <CODE>B19200</CODE> and <CODE>EXTB</CODE> is an alias for <CODE>B38400</CODE>.
These aliases are obsolete.
<P>
<A NAME="IDX1183"></A>
<U>Function:</U> int <B>cfmakeraw</B> <I>(struct termios *<VAR>termios_p</VAR>)</I><P>
<PRE>
t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
|INLCR|IGNCR|ICRNL|IXON);
t->c_oflag &= ~OPOST;
t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
t->c_cflag &= ~(CSIZE|PARENB);
t->c_cflag |= CS8;
</PRE>
<P>
<H3><A NAME="SEC281" HREF="library_toc.html#SEC281" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC281">Special Characters</A></H3>
<P>
In canonical input, the terminal driver recognizes a number of special
characters which perform various control functions. These include the
ERASE character (usually <KBD>DEL</KBD>) for editing input, and other editing
characters. The INTR character (normally <KBD>C-c</KBD>) for sending a
<CODE>SIGINT</CODE> signal, and other signal-raising characters, may be
available in either canonical or noncanonical input mode. All these
characters are described in this section.
<P>
The particular characters used are specified in the <CODE>c_cc</CODE> member
of the <CODE>struct termios</CODE> 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</CODE> is the index of the element that specifies the INTR
character, so storing <CODE>'='</CODE> in <CODE><VAR>termios</VAR>.c_cc[INTR]</CODE>
specifies <SAMP>`='</SAMP> as the INTR character.
<A NAME="IDX1184"></A>
<P>
On some systems, you can disable a particular special character function
by specifying the value <CODE>_POSIX_VDISABLE</CODE> for that role. This
value is unequal to any possible character code. See section <A HREF="library_27.html#SEC464" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_27.html#SEC464">Optional Features in File Support</A>, for more information about how to tell whether the operating
system you are using supports <CODE>_POSIX_VDISABLE</CODE>.
<P>
<H4><A NAME="SEC282" HREF="library_toc.html#SEC282" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC282">Characters for Input Editing</A></H4>
<P>
These special characters are active only in canonical input mode.
See section <A HREF="library_16.html#SEC271" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_16.html#SEC271">Two Styles of Input: Canonical or Not</A>.
<P>
<A NAME="IDX1185"></A>
<A NAME="IDX1186"></A>
<U>Macro:</U> int <B>VEOF</B><P>
This is the subscript for the EOF character in the special control
character array. <CODE><VAR>termios</VAR>.c_cc[VEOF]</CODE> holds the character
itself.
<P>
The EOF character is recognized only in canonical input mode. It acts
as a line terminator in the same way as a newline character, but if the
EOF character is typed at the beginning of a line it causes <CODE>read</CODE>
to return a byte count of zero, indicating end-of-file. The EOF
character itself is discarded.
<P>
Usually, the EOF character is <KBD>C-d</KBD>.
<P>
<A NAME="IDX1187"></A>
<A NAME="IDX1188"></A>
<U>Macro:</U> int <B>VEOL</B><P>
This is the subscript for the EOL character in the special control
character array. <CODE><VAR>termios</VAR>.c_cc[VEOL]</CODE> holds the character
itself.
<P>
The EOL character is recognized only in canonical input mode. It acts
as a line terminator, just like a newline character. The EOL character
is not discarded; it is read as the last character in the input line.
<P>
You don't need to use the EOL character to make <KBD>RET</KBD> end a line.
Just set the ICRNL flag. In fact, this is the default state of
affairs.
<P>
<A NAME="IDX1189"></A>
<A NAME="IDX1190"></A>
<U>Macro:</U> int <B>VERASE</B><P>
This is the subscript for the ERASE character in the special control
character array. <CODE><VAR>termios</VAR>.c_cc[VERASE]</CODE> holds the
character itself.
<P>
The ERASE character is recognized only in canonical input mode. When
the user types the erase character, the previous character typed is
discarded. (If the terminal generates multibyte character sequences,
this may cause more than one byte of input to be discarded.) This
cannot be used to erase past the beginning of the current line of text.
The ERASE character itself is discarded.
<P>
Usually, the ERASE character is <KBD>DEL</KBD>.
<P>
<A NAME="IDX1191"></A>
<A NAME="IDX1192"></A>
<U>Macro:</U> int <B>VKILL</B><P>
This is the subscript for the KILL character in the special control
character array. <CODE><VAR>termios</VAR>.c_cc[VKILL]</CODE> holds the character
itself.
<P>
The KILL character is recognized only in canonical input mode. When the
user types the kill character, the entire contents of the current line
of input are discarded. The kill character itself is discarded too.
<P>
The KILL character is usually <KBD>C-u</KBD>.
<P>
<H4><A NAME="SEC283" HREF="library_toc.html#SEC283" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC283">BSD Extensions to Editing Characters</A></H4>
<P>
These special characters are active only in canonical input mode.
See section <A HREF="library_16.html#SEC271" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_16.html#SEC271">Two Styles of Input: Canonical or Not</A>. They are BSD extensions; the GNU library
defines the symbols on any system if you ask for them, but the
characters you specify don't actually <EM>do</EM> anything except on a BSD
system.
<P>
<A NAME="IDX1193"></A>
<A NAME="IDX1194"></A>
<U>Macro:</U> int <B>VEOL2</B><P>
This is the subscript for the EOL2 character in the special control
character array. <CODE><VAR>termios</VAR>.c_cc[VEOL2]</CODE> holds the character
itself.
<P>
The EOL2 character works just like the EOL character (see above), but it
can be a different character. Thus, you can specify two characters to
terminate an input line, but setting EOL to one of them and EOL2 to the
other.
<P>
<A NAME="IDX1195"></A>
<A NAME="IDX1196"></A>
<U>Macro:</U> int <B>VWERASE</B><P>
This is the subscript for the WERASE character in the special control
character array. <CODE><VAR>termios</VAR>.c_cc[VWERASE]</CODE> holds the character
itself.
<P>
The WERASE character is recognized only in canonical input mode. It
erases an entire word of prior input.
<P>
<A NAME="IDX1197"></A>
<A NAME="IDX1198"></A>
<U>Macro:</U> int <B>VREPRINT</B><P>
This is the subscript for the REPRINT character in the special control
character array. <CODE><VAR>termios</VAR>.c_cc[VREPRINT]</CODE> holds the character
itself.
<P>
The REPRINT character is recognized only in canonical input mode. It
reprints the current input line.
<P>
<A NAME="IDX1199"></A>
<A NAME="IDX1200"></A>
<U>Macro:</U> int <B>VLNEXT</B><P>
This is the subscript for the LNEXT character in the special control
character array. <CODE><VAR>termios</VAR>.c_cc[VLNEXT]</CODE> holds the character
itself.
<P>
The LNEXT character is recognized only when <CODE>IEXTEN</CODE> is set. It
disables the editing significance of the next character the user types.
It is the analogue of the <KBD>C-q</KBD> command in Emacs. "LNEXT" stands
for "literal next."
<P>
The LNEXT character is usually <KBD>C-v</KBD>.
<P>
<H4><A NAME="SEC284" HREF="library_toc.html#SEC284" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC284">Characters that Cause Signals</A></H4>
<P>
These special characters may be active in either canonical or noncanonical
input mode, but only when the <CODE>ISIG</CODE> flag is set (see section <A HREF="library_16.html#SEC279" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_16.html#SEC279">Local Modes</A>).
<P>
<A NAME="IDX1201"></A>
<A NAME="IDX1202"></A>
<A NAME="IDX1203"></A>
<U>Macro:</U> int <B>VINTR</B><P>
This is the subscript for the INTR character in the special control
character array. <CODE><VAR>termios</VAR>.c_cc[VINTR]</CODE> holds the character
itself.
<P>
The INTR (interrupt) character raises a <CODE>SIGINT</CODE> signal for all
processes in the foreground job associated with the terminal. The INTR
character itself is then discarded. See section <A HREF="library_21.html#SEC330" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_21.html#SEC330">Signal Handling</A>, for more
information about signals.
<P>
Typically, the INTR character is <KBD>C-c</KBD>.
<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -