Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/ctermid.html
2024-02-19 00:21:47 -05:00

160 lines
6.3 KiB
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 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-2001<br>
Copyright &copy; 2001 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 terminal
for 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 by
each call), the address of which shall be returned. Otherwise, <i>s</i> is assumed to point to a character array of at least
L_ctermid bytes; the string is placed in this array and the value of <i>s</i> shall be returned. The symbolic constant L_ctermid is
defined 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 cannot
be 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. The
pathname for the terminal is stored in the array pointed to by the <i>ptr</i> argument, which has a size of L_ctermid bytes, as
indicated 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 with
that file descriptor, while <i>ctermid</i>() returns a string (such as <tt>"/dev/tty"</tt> ) that refers to the current controlling
terminal 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 declarations
using 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 a
string that, when used as a pathname, refers to the current controlling terminal for the current process. If <i>s</i> is NULL, the
return 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>() along
with allocating a buffer is more of a burden than merely allocating a buffer. Application code should not assume that the returned
string 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>