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

📄 posix_openpt.html

📁 posix标准英文,html格式
💻 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>posix_openpt</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="posix_openpt"></a> <a name="tag_03_426"></a><!-- posix_openpt --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2004 Edition<br>Copyright &copy; 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_426_01"></a>NAME</h4><blockquote>posix_openpt - open a pseudo-terminal device</blockquote><h4><a name="tag_03_426_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include &lt;<a href="../basedefs/stdlib.h.html">stdlib.h</a>&gt;<br> #include &lt;<a href="../basedefs/fcntl.h.html">fcntl.h</a>&gt;<br><br> int posix_openpt(int</tt> <i>oflag</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_426_03"></a>DESCRIPTION</h4><blockquote><p>The <i>posix_openpt</i>() function shall establish a connection between a master device for a pseudo-terminal and a filedescriptor. The file descriptor is used by other I/O functions that refer to that pseudo-terminal.</p><p>The file status flags and file access modes of the open file description shall be set according to the value of<i>oflag</i>.</p><p>Values for <i>oflag</i> are constructed by a bitwise-inclusive OR of flags from the following list, defined in <a href="../basedefs/fcntl.h.html"><i>&lt;fcntl.h&gt;</i></a>:</p><dl compact><dt>O_RDWR</dt><dd>Open for reading and writing.</dd><dt>O_NOCTTY</dt><dd>If set <i>posix_openpt</i>() shall not cause the terminal device to become the controlling terminal for the process.</dd></dl><p>The behavior of other values for the <i>oflag</i> argument is unspecified.</p></blockquote><h4><a name="tag_03_426_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, the <i>posix_openpt</i>() function shall open a master pseudo-terminal device and return anon-negative integer representing the lowest numbered unused file descriptor. Otherwise, -1 shall be returned and <i>errno</i> setto indicate the error.</p></blockquote><h4><a name="tag_03_426_05"></a>ERRORS</h4><blockquote><p>The <i>posix_openpt</i>() function shall fail if:</p><dl compact><dt>[EMFILE]</dt><dd>{OPEN_MAX} file descriptors are currently open in the calling process.</dd><dt>[ENFILE]</dt><dd>The maximum allowable number of files is currently open in the system.</dd></dl><p>The <i>posix_openpt</i>() function may fail if:</p><dl compact><dt>[EINVAL]</dt><dd>The value of <i>oflag</i> is not valid.</dd><dt>[EAGAIN]</dt><dd>Out of pseudo-terminal resources.</dd><dt>[ENOSR]</dt><dd><sup>[<a href="javascript:open_code('XSR')">XSR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Out of STREAMS resources. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_426_06"></a>EXAMPLES</h4><blockquote><h5><a name="tag_03_426_06_01"></a>Opening a Pseudo-Terminal and Returning the Name of the Slave Device and a File Descriptor</h5><pre><tt>#include &lt;fcntl.h&gt;#include &lt;stdio.h&gt;<br>int masterfd, slavefd;char *slavedevice;<br>masterfd = posix_openpt(O_RDWR|O_NOCTTY);<br>if (masterfd == -1    || grantpt (masterfd) == -1    || unlockpt (masterfd) == -1    || (slavedevice = ptsname (masterfd)) == NULL)    return -1;<br>printf("slave device is: %s\n", slavedevice);<br>slavefd = open(slave, O_RDWR|O_NOCTTY);if (slavefd &lt; 0)    return -1;</tt></pre></blockquote><h4><a name="tag_03_426_07"></a>APPLICATION USAGE</h4><blockquote><p>This function is a method for portably obtaining a file descriptor of a master terminal device for a pseudo-terminal. The <ahref="../functions/grantpt.html"><i>grantpt</i>()</a> and <a href="../functions/ptsname.html"><i>ptsname</i>()</a> functions can beused to manipulate mode and ownership permissions, and to obtain the name of the slave device, respectively.</p></blockquote><h4><a name="tag_03_426_08"></a>RATIONALE</h4><blockquote><p>The standard developers considered the matter of adding a special device for cloning master pseudo-terminals: the<b>/dev/ptmx</b> device. However, consensus could not be reached, and it was felt that adding a new function would permit otherimplementations. The <i>posix_openpt</i>() function is designed to complement the <a href="../functions/grantpt.html"><i>grantpt</i>()</a>, <a href="../functions/ptsname.html"><i>ptsname</i>()</a>, and <a href="../functions/unlockpt.html"><i>unlockpt</i>()</a> functions.</p><p>On implementations supporting the <b>/dev/ptmx</b> clone device, opening the master device of a pseudo-terminal is simply:</p><pre><tt>mfdp = open("/dev/ptmx", oflag );if (mfdp &lt; 0)    return -1;</tt></pre></blockquote><h4><a name="tag_03_426_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_426_10"></a>SEE ALSO</h4><blockquote><p><a href="grantpt.html"><i>grantpt</i>()</a>, <a href="open.html"><i>open</i>()</a>, <a href="ptsname.html"><i>ptsname</i>()</a>, <a href="unlockpt.html"><i>unlockpt</i>()</a>, the Base Definitions volume ofIEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/fcntl.h.html"><i>&lt;fcntl.h&gt;</i></a></p></blockquote><h4><a name="tag_03_426_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 6.</p></blockquote><div class="box"><em>End of informative text.</em></div><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 + -