199 lines
6.6 KiB
HTML
199 lines
6.6 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>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-2001<br>
|
|
Copyright © 2001 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 <<a href="../basedefs/stdlib.h.html">stdlib.h</a>><br>
|
|
#include <<a href="../basedefs/fcntl.h.html">fcntl.h</a>><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 file
|
|
descriptor. 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><fcntl.h></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 a
|
|
non-negative integer representing the lowest numbered unused file descriptor. Otherwise, -1 shall be returned and <i>errno</i> set
|
|
to 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 <fcntl.h>
|
|
#include <stdio.h>
|
|
<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 < 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 <a
|
|
href="../functions/grantpt.html"><i>grantpt</i>()</a> and <a href="../functions/ptsname.html"><i>ptsname</i>()</a> functions can be
|
|
used 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 other
|
|
implementations. 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 < 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 of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/fcntl.h.html"><i><fcntl.h></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>
|
|
<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>
|
|
|