2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
43 .\" Copyright (c) 2001, The IEEE and The Open Group. All Rights Reserved.
44 .\" Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
46 .TH POSIX_OPENPT 3C "Dec 1, 2003"
48 posix_openpt \- open a pseudo terminal device
55 \fBint\fR \fBposix_openpt\fR(\fBint\fR \fIoflag\fR);
61 The \fBposix_openpt()\fR function establishes a connection between a master
62 device for a pseudo-terminal and a file descriptor. The file descriptor is used
63 by other I/O functions that refer to that pseudo-terminal.
66 The file status flags and file access modes of the open file description are
67 set according to the value of \fIoflag\fR.
70 Values for \fIoflag\fR are constructed by a bitwise-inclusive OR of flags from
71 the following list, defined in <\fBfcntl.h\fR>.
78 Open for reading and writing.
87 If set, \fBposix_openpt()\fR does not cause the terminal device to become the
88 controlling terminal for the process.
93 The behavior of other values for the \fIoflag\fR argument is unspecified.
97 Upon successful completion, the \fBposix_openpt()\fR function opens a master
98 pseudo-terminal device and returns a non-negative integer representing the
99 lowest numbered unused file descriptor. Otherwise, -1 is returned and
100 \fBerrno\fR is set to indicate the error.
104 The \fBposix_openpt()\fR function will fail if:
111 {\fBOPEN_MAX\fR} file descriptors are currently open in the calling process.
120 The maximum allowable number of files is currently open in the system.
125 The \fBposix_openpt()\fR function may fail if:
132 The value of \fIoflag\fR is not valid.
141 Out of pseudo-terminal resources.
150 Out of STREAMS resources.
155 \fBExample 1 \fROpen a pseudo-terminal.
158 The following example opens a pseudo-terminal and returns the name of the slave
159 device and a file descriptor.
167 int masterfd, slavefd;
170 masterfd = posix_openpt(O_RDWR|O_NOCTTY);
173 || grantpt (masterfd) == -1
174 || unlockpt (masterfd) == -1
175 || (slavedevice = ptsname (masterfd)) == NULL)
178 printf("slave device is: %s\en", slavedevice);
180 slavefd = open(slave, O_RDWR|O_NOCTTY);
189 This function provides a method for portably obtaining a file descriptor of a
190 master terminal device for a pseudo-terminal. The \fBgrantpt\fR(3C) and
191 \fBptsname\fR(3C) functions can be used to manipulate mode and ownership
192 permissions and to obtain the name of the slave device, respectively.
196 See \fBattributes\fR(5) for descriptions of the following attributes:
204 ATTRIBUTE TYPE ATTRIBUTE VALUE
206 Interface Stability Standard
214 \fBopen\fR(2), \fBgrantpt\fR(3C), \fBptsname\fR(3C), \fBunlockpt\fR(3C),
215 \fBattributes\fR(5), \fBstandards\fR(5)