📄 tcsetattr.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2004 IEEE and The Open Group, All Rights Reserved --><title>tcsetattr</title></head><body bgcolor="white"><basefont size="3"> <a name="tcsetattr"></a> <a name="tag_03_768"></a><!-- tcsetattr --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2004 Edition<br>Copyright © 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_768_01"></a>NAME</h4><blockquote>tcsetattr - set the parameters associated with the terminal</blockquote><h4><a name="tag_03_768_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include <<a href="../basedefs/termios.h.html">termios.h</a>><br><br> int tcsetattr(int</tt> <i>fildes</i><tt>, int</tt> <i>optional_actions</i><tt>,<br> const struct termios *</tt><i>termios_p</i><tt>);<br></tt></code></p></blockquote><h4><a name="tag_03_768_03"></a>DESCRIPTION</h4><blockquote><p>The <i>tcsetattr</i>() function shall set the parameters associated with the terminal referred to by the open file descriptor<i>fildes</i> (an open file descriptor associated with a terminal) from the <b>termios</b> structure referenced by <i>termios_p</i>as follows:</p><ul><li><p>If <i>optional_actions</i> is TCSANOW, the change shall occur immediately.</p></li><li><p>If <i>optional_actions</i> is TCSADRAIN, the change shall occur after all output written to <i>fildes</i> is transmitted. Thisfunction should be used when changing parameters that affect output.</p></li><li><p>If <i>optional_actions</i> is TCSAFLUSH, the change shall occur after all output written to <i>fildes</i> is transmitted, andall input so far received but not read shall be discarded before the change is made.</p></li></ul><p>If the output baud rate stored in the <b>termios</b> structure pointed to by <i>termios_p</i> is the zero baud rate, B0, themodem control lines shall no longer be asserted. Normally, this shall disconnect the line.</p><p>If the input baud rate stored in the <b>termios</b> structure pointed to by <i>termios_p</i> is 0, the input baud rate given tothe hardware is the same as the output baud rate stored in the <b>termios</b> structure.</p><p>The <i>tcsetattr</i>() function shall return successfully if it was able to perform any of the requested actions, even if someof the requested actions could not be performed. It shall set all the attributes that the implementation supports as requested andleave all the attributes not supported by the implementation unchanged. If no part of the request can be honored, it shall return-1 and set <i>errno</i> to [EINVAL]. If the input and output baud rates differ and are a combination that is not supported, neitherbaud rate shall be changed. A subsequent call to <a href="../functions/tcgetattr.html"><i>tcgetattr</i>()</a> shall return theactual state of the terminal device (reflecting both the changes made and not made in the previous <i>tcsetattr</i>() call). The<i>tcsetattr</i>() function shall not change the values found in the <b>termios</b> structure under any circumstances.</p><p>The effect of <i>tcsetattr</i>() is undefined if the value of the <b>termios</b> structure pointed to by <i>termios_p</i> wasnot derived from the result of a call to <a href="../functions/tcgetattr.html"><i>tcgetattr</i>()</a> on <i>fildes</i>; anapplication should modify only fields and flags defined by this volume of IEEE Std 1003.1-2001 between the call to <ahref="../functions/tcgetattr.html"><i>tcgetattr</i>()</a> and <i>tcsetattr</i>(), leaving all other fields and flagsunmodified.</p><p>No actions defined by this volume of IEEE Std 1003.1-2001, other than a call to <i>tcsetattr</i>() or a close of thelast file descriptor in the system associated with this terminal device, shall cause any of the terminal attributes defined by thisvolume of IEEE Std 1003.1-2001 to change.</p><p>If <i>tcsetattr</i>() is called from a process which is a member of a background process group on a <i>fildes</i> associatedwith its controlling terminal:</p><ul><li><p>If the calling process is blocking or ignoring SIGTTOU signals, the operation completes normally and no signal is sent.</p></li><li><p>Otherwise, a SIGTTOU signal shall be sent to the process group.</p></li></ul></blockquote><h4><a name="tag_03_768_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, 0 shall be returned. Otherwise, -1 shall be returned and <i>errno</i> set to indicate the error.</p></blockquote><h4><a name="tag_03_768_05"></a>ERRORS</h4><blockquote><p>The <i>tcsetattr</i>() function shall fail if:</p><dl compact><dt>[EBADF]</dt><dd>The <i>fildes</i> argument is not a valid file descriptor.</dd><dt>[EINTR]</dt><dd>A signal interrupted <i>tcsetattr</i>().</dd><dt>[EINVAL]</dt><dd>The <i>optional_actions</i> argument is not a supported value, or an attempt was made to change an attribute represented in the<b>termios</b> structure to an unsupported value.</dd><dt>[ENOTTY]</dt><dd>The file associated with <i>fildes</i> is not a terminal.</dd></dl><p>The <i>tcsetattr</i>() function may fail if:</p><dl compact><dt>[EIO]</dt><dd>The process group of the writing process is orphaned, and the writing process is not ignoring or blocking SIGTTOU.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_768_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_768_07"></a>APPLICATION USAGE</h4><blockquote><p>If trying to change baud rates, applications should call <i>tcsetattr</i>() then call <a href="../functions/tcgetattr.html"><i>tcgetattr</i>()</a> in order to determine what baud rates were actually selected.</p></blockquote><h4><a name="tag_03_768_08"></a>RATIONALE</h4><blockquote><p>The <i>tcsetattr</i>() function can be interrupted in the following situations:</p><ul><li><p>It is interrupted while waiting for output to drain.</p></li><li><p>It is called from a process in a background process group and SIGTTOU is caught.</p></li></ul><p>See also the RATIONALE section in <a href="tcgetattr.html"><i>tcgetattr</i>()</a>.</p></blockquote><h4><a name="tag_03_768_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>Using an input baud rate of 0 to set the input rate equal to the output rate may not necessarily be supported in a futureversion of this volume of IEEE Std 1003.1-2001.</p></blockquote><h4><a name="tag_03_768_10"></a>SEE ALSO</h4><blockquote><p><a href="cfgetispeed.html"><i>cfgetispeed</i>()</a>, <a href="tcgetattr.html"><i>tcgetattr</i>()</a>, the Base Definitionsvolume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap11.html#tag_11">Chapter 11, General Terminal Interface</a>,<a href="../basedefs/termios.h.html"><i><termios.h></i></a>, <a href="../basedefs/unistd.h.html"><i><unistd.h></i></a></p></blockquote><h4><a name="tag_03_768_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 3. Included for alignment with the POSIX.1-1988 standard.</p></blockquote><h4><a name="tag_03_768_12"></a>Issue 6</h4><blockquote><p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p><ul><li><p>In the DESCRIPTION, text previously conditional on _POSIX_JOB_CONTROL is now mandated. This is a FIPS requirement.</p></li><li><p>The [EIO] error is added.</p></li></ul><br><p>In the DESCRIPTION, the text describing use of <i>tcsetattr</i>() from a process which is a member of a background process groupis clarified.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -