⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctermid.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 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-2003 The Open Group, All Rights Reserved --><title>ctermid</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="ctermid"></a> <a name="tag_03_102"></a><!-- ctermid --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_102_01"></a>NAME</h4><blockquote>ctermid - generate a pathname for the controlling terminal</blockquote><h4><a name="tag_03_102_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include &lt;<a href="../basedefs/stdio.h.html">stdio.h</a>&gt;<br><br> char *ctermid(char *</tt><i>s</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_102_03"></a>DESCRIPTION</h4><blockquote><p>The <i>ctermid</i>() function shall generate a string that, when used as a pathname, refers to the current controlling terminalfor the current process. If <i>ctermid</i>() returns a pathname, access to the file is not guaranteed.</p><p>If the application uses any of the _POSIX_THREAD_SAFE_FUNCTIONS or _POSIX_THREADS functions, it shall ensure that the<i>ctermid</i>() function is called with a non-NULL parameter.</p></blockquote><h4><a name="tag_03_102_04"></a>RETURN VALUE</h4><blockquote><p>If <i>s</i> is a null pointer, the string shall be generated in an area that may be static (and therefore may be overwritten byeach call), the address of which shall be returned. Otherwise, <i>s</i> is assumed to point to a character array of at leastL_ctermid bytes; the string is placed in this array and the value of <i>s</i> shall be returned. The symbolic constant L_ctermid isdefined in <a href="../basedefs/stdio.h.html"><i>&lt;stdio.h&gt;</i></a>, and shall have a value greater than 0.</p><p>The <i>ctermid</i>() function shall return an empty string if the pathname that would refer to the controlling terminal cannotbe determined, or if the function is unsuccessful.</p></blockquote><h4><a name="tag_03_102_05"></a>ERRORS</h4><blockquote><p>No errors are defined.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_102_06"></a>EXAMPLES</h4><blockquote><h5><a name="tag_03_102_06_01"></a>Determining the Controlling Terminal for the Current Process</h5><p>The following example returns a pointer to a string that identifies the controlling terminal for the current process. Thepathname for the terminal is stored in the array pointed to by the <i>ptr</i> argument, which has a size of L_ctermid bytes, asindicated by the <i>term</i> argument.</p><pre><tt>#include &lt;stdio.h&gt;...char term[L_ctermid];char *ptr;<br>ptr = ctermid(term);</tt></pre></blockquote><h4><a name="tag_03_102_07"></a>APPLICATION USAGE</h4><blockquote><p>The difference between <i>ctermid</i>() and <a href="../functions/ttyname.html"><i>ttyname</i>()</a> is that <a href="../functions/ttyname.html"><i>ttyname</i>()</a> must be handed a file descriptor and return a path of the terminal associated withthat file descriptor, while <i>ctermid</i>() returns a string (such as <tt>"/dev/tty"</tt> ) that refers to the current controllingterminal if used as a pathname.</p></blockquote><h4><a name="tag_03_102_08"></a>RATIONALE</h4><blockquote><p>L_ctermid must be defined appropriately for a given implementation and must be greater than zero so that array declarationsusing it are accepted by the compiler. The value includes the terminating null byte.</p><p>Conforming applications that use threads cannot call <i>ctermid</i>() with NULL as the parameter if either_POSIX_THREAD_SAFE_FUNCTIONS or _POSIX_THREADS is defined. If <i>s</i> is not NULL, the <i>ctermid</i>() function generates astring that, when used as a pathname, refers to the current controlling terminal for the current process. If <i>s</i> is NULL, thereturn value of <i>ctermid</i>() is undefined.</p><p>There is no additional burden on the programmer-changing to use a hypothetical thread-safe version of <i>ctermid</i>() alongwith allocating a buffer is more of a burden than merely allocating a buffer. Application code should not assume that the returnedstring is short, as some implementations have more than two pathname components before reaching a logical device name.</p></blockquote><h4><a name="tag_03_102_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_102_10"></a>SEE ALSO</h4><blockquote><p><a href="ttyname.html"><i>ttyname</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/stdio.h.html"><i>&lt;stdio.h&gt;</i></a></p></blockquote><h4><a name="tag_03_102_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 1. Derived from Issue 1 of the SVID.</p></blockquote><h4><a name="tag_03_102_12"></a>Issue 5</h4><blockquote><p>The DESCRIPTION is updated for alignment with the POSIX Threads Extension.</p></blockquote><h4><a name="tag_03_102_13"></a>Issue 6</h4><blockquote><p>The DESCRIPTION is updated to avoid use of the term &quot;must&quot; for application requirements.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX &reg; is a registered Trademark of The Open Group.<br>POSIX &reg; 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 + -