2 .\" Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved.
3 .\" Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
4 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
7 .\" This notice shall appear on any product containing this material.
8 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
9 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
10 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
11 .TH POSIX_OPENPT 3C "Dec 1, 2003"
13 posix_openpt \- open a pseudo terminal device
20 \fBint\fR \fBposix_openpt\fR(\fBint\fR \fIoflag\fR);
26 The \fBposix_openpt()\fR function establishes a connection between a master
27 device for a pseudo-terminal and a file descriptor. The file descriptor is used
28 by other I/O functions that refer to that pseudo-terminal.
31 The file status flags and file access modes of the open file description are
32 set according to the value of \fIoflag\fR.
35 Values for \fIoflag\fR are constructed by a bitwise-inclusive OR of flags from
36 the following list, defined in <\fBfcntl.h\fR>.
43 Open for reading and writing.
52 If set, \fBposix_openpt()\fR does not cause the terminal device to become the
53 controlling terminal for the process.
58 The behavior of other values for the \fIoflag\fR argument is unspecified.
62 Upon successful completion, the \fBposix_openpt()\fR function opens a master
63 pseudo-terminal device and returns a non-negative integer representing the
64 lowest numbered unused file descriptor. Otherwise, -1 is returned and
65 \fBerrno\fR is set to indicate the error.
69 The \fBposix_openpt()\fR function will fail if:
76 {\fBOPEN_MAX\fR} file descriptors are currently open in the calling process.
85 The maximum allowable number of files is currently open in the system.
90 The \fBposix_openpt()\fR function may fail if:
97 The value of \fIoflag\fR is not valid.
106 Out of pseudo-terminal resources.
115 Out of STREAMS resources.
120 \fBExample 1 \fROpen a pseudo-terminal.
123 The following example opens a pseudo-terminal and returns the name of the slave
124 device and a file descriptor.
132 int masterfd, slavefd;
135 masterfd = posix_openpt(O_RDWR|O_NOCTTY);
138 || grantpt (masterfd) == -1
139 || unlockpt (masterfd) == -1
140 || (slavedevice = ptsname (masterfd)) == NULL)
143 printf("slave device is: %s\en", slavedevice);
145 slavefd = open(slave, O_RDWR|O_NOCTTY);
154 This function provides a method for portably obtaining a file descriptor of a
155 master terminal device for a pseudo-terminal. The \fBgrantpt\fR(3C) and
156 \fBptsname\fR(3C) functions can be used to manipulate mode and ownership
157 permissions and to obtain the name of the slave device, respectively.
161 See \fBattributes\fR(5) for descriptions of the following attributes:
169 ATTRIBUTE TYPE ATTRIBUTE VALUE
171 Interface Stability Standard
179 \fBopen\fR(2), \fBgrantpt\fR(3C), \fBptsname\fR(3C), \fBunlockpt\fR(3C),
180 \fBattributes\fR(5), \fBstandards\fR(5)