📄 tcgetattr.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>tcgetattr</title></head><body bgcolor="white"><basefont size="3"> <a name="tcgetattr"></a> <a name="tag_03_764"></a><!-- tcgetattr --> <!--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_764_01"></a>NAME</h4><blockquote>tcgetattr - get the parameters associated with the terminal</blockquote><h4><a name="tag_03_764_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include <<a href="../basedefs/termios.h.html">termios.h</a>><br><br> int tcgetattr(int</tt> <i>fildes</i><tt>, struct termios *</tt><i>termios_p</i><tt>);<br></tt></code></p></blockquote><h4><a name="tag_03_764_03"></a>DESCRIPTION</h4><blockquote><p>The <i>tcgetattr</i>() function shall get the parameters associated with the terminal referred to by <i>fildes</i> and storethem in the <b>termios</b> structure referenced by <i>termios_p</i>. The <i>fildes</i> argument is an open file descriptorassociated with a terminal.</p><p>The <i>termios_p</i> argument is a pointer to a <b>termios</b> structure.</p><p>The <i>tcgetattr</i>() operation is allowed from any process.</p><p>If the terminal device supports different input and output baud rates, the baud rates stored in the <b>termios</b> structurereturned by <i>tcgetattr</i>() shall reflect the actual baud rates, even if they are equal. If differing baud rates are notsupported, the rate returned as the output baud rate shall be the actual baud rate. If the terminal device does not support splitbaud rates, the input baud rate stored in the <b>termios</b> structure shall be the output rate (as one of the symbolicvalues).</p></blockquote><h4><a name="tag_03_764_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_764_05"></a>ERRORS</h4><blockquote><p>The <i>tcgetattr</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>[ENOTTY]</dt><dd>The file associated with <i>fildes</i> is not a terminal.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_764_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_764_07"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_764_08"></a>RATIONALE</h4><blockquote><p>Care must be taken when changing the terminal attributes. Applications should always do a <i>tcgetattr</i>(), save the<b>termios</b> structure values returned, and then do a <a href="../functions/tcsetattr.html"><i>tcsetattr</i>()</a>, changing onlythe necessary fields. The application should use the values saved from the <i>tcgetattr</i>() to reset the terminal state wheneverit is done with the terminal. This is necessary because terminal attributes apply to the underlying port and not to each individualopen instance; that is, all processes that have used the terminal see the latest attribute changes.</p><p>A program that uses these functions should be written to catch all signals and take other appropriate actions to ensure thatwhen the program terminates, whether planned or not, the terminal device's state is restored to its original state.</p><p>Existing practice dealing with error returns when only part of a request can be honored is based on calls to the <a href="../functions/ioctl.html"><i>ioctl</i>()</a> function. In historical BSD and System V implementations, the corresponding <a href="../functions/ioctl.html"><i>ioctl</i>()</a> returns zero if the requested actions were semantically correct, even if some of therequested changes could not be made. Many existing applications assume this behavior and would no longer work correctly if thereturn value were changed from zero to -1 in this case.</p><p>Note that either specification has a problem. When zero is returned, it implies everything succeeded even if some of the changeswere not made. When -1 is returned, it implies everything failed even though some of the changes were made.</p><p>Applications that need all of the requested changes made to work properly should follow <a href="../functions/tcsetattr.html"><i>tcsetattr</i>()</a> with a call to <i>tcgetattr</i>() and compare the appropriate fieldvalues.</p></blockquote><h4><a name="tag_03_764_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_764_10"></a>SEE ALSO</h4><blockquote><p><a href="tcsetattr.html"><i>tcsetattr</i>()</a>, the Base Definitions volume 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></p></blockquote><h4><a name="tag_03_764_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_764_12"></a>Issue 6</h4><blockquote><p>In the DESCRIPTION, the rate returned as the input baud rate shall be the output rate. Previously, the number zero was alsoallowed but was obsolescent.</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 + -