9330 stack overflow when creating a deeply nested dataset
[unleashed.git] / usr / src / man / man3c / posix_openpt.3c
blob716778eb212813841ef93bf51fc4750139552f25
1 .\"
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/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
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.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
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.
30 .\"
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.
35 .\"
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]
41 .\"
42 .\"
43 .\" Copyright (c) 2001, The IEEE and The Open Group.  All Rights Reserved.
44 .\" Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
45 .\"
46 .TH POSIX_OPENPT 3C "Dec 1, 2003"
47 .SH NAME
48 posix_openpt \- open a pseudo terminal device
49 .SH SYNOPSIS
50 .LP
51 .nf
52 #include <stdlib.h>
53 #include <fcntl.h>
55 \fBint\fR \fBposix_openpt\fR(\fBint\fR \fIoflag\fR);
56 .fi
58 .SH DESCRIPTION
59 .sp
60 .LP
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.
64 .sp
65 .LP
66 The file status flags and file access modes of the open file description are
67 set according to the value of \fIoflag\fR.
68 .sp
69 .LP
70 Values for \fIoflag\fR are constructed by a bitwise-inclusive OR of flags from
71 the following list, defined in <\fBfcntl.h\fR>.
72 .sp
73 .ne 2
74 .na
75 \fB\fBO_RDWR\fR\fR
76 .ad
77 .RS 12n
78 Open for reading and writing.
79 .RE
81 .sp
82 .ne 2
83 .na
84 \fB\fBO_NOCTTY\fR\fR
85 .ad
86 .RS 12n
87 If set, \fBposix_openpt()\fR does not cause the terminal device to become the
88 controlling terminal for the process.
89 .RE
91 .sp
92 .LP
93 The behavior of other values for the \fIoflag\fR argument is unspecified.
94 .SH RETURN VALUES
95 .sp
96 .LP
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.
101 .SH ERRORS
104 The \fBposix_openpt()\fR function will fail if:
106 .ne 2
108 \fB\fBEMFILE\fR\fR
110 .RS 10n
111 {\fBOPEN_MAX\fR} file descriptors are currently open in the calling process.
115 .ne 2
117 \fB\fBENFILE\fR\fR
119 .RS 10n
120 The maximum allowable number of files is currently open in the system.
125 The \fBposix_openpt()\fR function may fail if:
127 .ne 2
129 \fB\fBEINVAL\fR\fR
131 .RS 10n
132 The value of \fIoflag\fR is not valid.
136 .ne 2
138 \fB\fBEAGAIN\fR\fR
140 .RS 10n
141 Out of pseudo-terminal resources.
145 .ne 2
147 \fB\fBENOSR\fR\fR
149 .RS 10n
150 Out of STREAMS resources.
153 .SH EXAMPLES
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.
162 .in +2
164 #include fcntl.h>
165 #include stdio.h>
167 int masterfd, slavefd;
168 char *slavedevice;
170 masterfd = posix_openpt(O_RDWR|O_NOCTTY);
172 if (masterfd == -1
173       || grantpt (masterfd) == -1
174       || unlockpt (masterfd) == -1
175       || (slavedevice = ptsname (masterfd)) == NULL)
176       return -1;
178 printf("slave device is: %s\en", slavedevice);
180 slavefd = open(slave, O_RDWR|O_NOCTTY);
181 if (slavefd < 0)
182       return -1;
184 .in -2
186 .SH USAGE
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.
193 .SH ATTRIBUTES
196 See \fBattributes\fR(5) for descriptions of the following attributes:
201 box;
202 c | c
203 l | l .
204 ATTRIBUTE TYPE  ATTRIBUTE VALUE
206 Interface Stability     Standard
208 MT-Level        MT-Safe
211 .SH SEE ALSO
214 \fBopen\fR(2), \fBgrantpt\fR(3C), \fBptsname\fR(3C), \fBunlockpt\fR(3C),
215 \fBattributes\fR(5), \fBstandards\fR(5)