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 "June 18, 2021"
47 .SH NAME
48 posix_openpt \- open a pseudo terminal device
49 .SH SYNOPSIS
50 .nf
51 #include <stdlib.h>
52 #include <fcntl.h>
53
54 \fBint\fR \fBposix_openpt\fR(\fBint\fR \fIoflag\fR);
55 .fi
56
57 .SH DESCRIPTION
58 The \fBposix_openpt()\fR function establishes a connection between a master
59 device for a pseudo-terminal and a file descriptor. The file descriptor is used
60 by other I/O functions that refer to that pseudo-terminal.
61 .sp
62 .LP
63 The file status flags and file access modes of the open file description are
64 set according to the value of \fIoflag\fR.
65 .sp
66 .LP
67 Values for \fIoflag\fR are constructed by a bitwise-inclusive OR of flags from
68 the following list, defined in <\fBfcntl.h\fR>.
69 .sp
70 .ne 2
71 .na
72 \fB\fBO_RDWR\fR\fR
73 .ad
74 .RS 12n
75 Open for reading and writing.
76 .RE
77
78 .sp
79 .ne 2
80 .na
81 \fB\fBO_NOCTTY\fR\fR
82 .ad
83 .RS 12n
84 If set, \fBposix_openpt()\fR does not cause the terminal device to become the
85 controlling terminal for the process.
86 .RE
87
88 .sp
89 .LP
90 The behavior of other values for the \fIoflag\fR argument is unspecified.
91 .SH RETURN VALUES
92 Upon successful completion, the \fBposix_openpt()\fR function opens a master
93 pseudo-terminal device and returns a non-negative integer representing the
94 lowest numbered unused file descriptor. Otherwise, -1 is returned and
95 \fBerrno\fR is set to indicate the error.
96 .SH ERRORS
97 The \fBposix_openpt()\fR function will fail if:
98 .sp
99 .ne 2
100 .na
101 \fB\fBEMFILE\fR\fR
102 .ad
103 .RS 10n
104 {\fBOPEN_MAX\fR} file descriptors are currently open in the calling process.
105 .RE
106
107 .sp
108 .ne 2
109 .na
110 \fB\fBENFILE\fR\fR
111 .ad
112 .RS 10n
113 The maximum allowable number of files is currently open in the system.
114 .RE
115
116 .sp
117 .LP
118 The \fBposix_openpt()\fR function may fail if:
119 .sp
120 .ne 2
121 .na
122 \fB\fBEINVAL\fR\fR
123 .ad
124 .RS 10n
125 The value of \fIoflag\fR is not valid.
126 .RE
127
128 .sp
129 .ne 2
130 .na
131 \fB\fBEAGAIN\fR\fR
132 .ad
133 .RS 10n
134 Out of pseudo-terminal resources.
135 .RE
136
137 .sp
138 .ne 2
139 .na
140 \fB\fBENOSR\fR\fR
141 .ad
142 .RS 10n
143 Out of STREAMS resources.
144 .RE
145
146 .SH EXAMPLES
147 \fBExample 1 \fROpen a pseudo-terminal.
148 .sp
149 .LP
150 The following example opens a pseudo-terminal and returns the name of the slave
151 device and a file descriptor.
152
153 .sp
154 .in +2
155 .nf
156 #include <fcntl.h>
157 #include <stdio.h>
158
159 int masterfd, slavefd;
160 char *slavedevice;
161
162 masterfd = posix_openpt(O_RDWR|O_NOCTTY);
163
164 if (masterfd == -1
165 || grantpt (masterfd) == -1
166 || unlockpt (masterfd) == -1
167 || (slavedevice = ptsname (masterfd)) == NULL)
168 return -1;
169
170 printf("slave device is: %s\en", slavedevice);
171
172 slavefd = open(slave, O_RDWR|O_NOCTTY);
173 if (slavefd < 0)
174 return -1;
175 .fi
176 .in -2
177
178 .SH USAGE
179 This function provides a method for portably obtaining a file descriptor of a
180 master terminal device for a pseudo-terminal. The \fBgrantpt\fR(3C) and
181 \fBptsname\fR(3C) functions can be used to manipulate mode and ownership
182 permissions and to obtain the name of the slave device, respectively.
183 .SH ATTRIBUTES
184 See \fBattributes\fR(5) for descriptions of the following attributes:
185 .sp
186
187 .sp
188 .TS
189 box;
190 c | c
191 l | l .
192 ATTRIBUTE TYPE ATTRIBUTE VALUE
193 _
194 Interface Stability Standard
195 _
196 MT-Level MT-Safe
197 .TE
198
199 .SH SEE ALSO
200 \fBopen\fR(2), \fBgrantpt\fR(3C), \fBptsname\fR(3C), \fBunlockpt\fR(3C),
201 \fBattributes\fR(5), \fBstandards\fR(5)
|
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 .\" Copyright 2022 Oxide Computer Company
46 .\"
47 .Dd February 5, 2022
48 .Dt POSIX_OPENPT 3C
49 .Os
50 .Sh NAME
51 .Nm posix_openpt
52 .Nd open a pseudo-terminal manager device
53 .Sh SYNOPSIS
54 .In stdlib.h
55 .In fcntl.h
56 .Ft int
57 .Fo posix_openpt
58 .Fa "int oflag"
59 .Fc
60 .Sh DESCRIPTION
61 The
62 .Fn posix_openpt
63 function establishes a connection between a manager device for a
64 pseudo-terminal and a file descriptor.
65 The file descriptor is used by other I/O functions that refer to that
66 pseudo-terminal.
67 .Pp
68 The file status flags and file access modes of the open file description are
69 set according to the value of
70 .Fa oflag .
71 .Pp
72 Values for
73 .Fa oflag
74 are constructed by a bitwise-inclusive OR of flags from
75 the following list, defined in
76 .Xr fcntl.h 3HEAD :
77 .Bl -tag -width Ds
78 .It Dv O_RDWR
79 Open for reading and writing.
80 .It Dv O_NOCTTY
81 If set,
82 .Fn posix_openpt
83 does not cause the terminal device to become the controlling terminal for the
84 process.
85 .El
86 .Pp
87 The behavior of other values for the
88 .Fa oflag
89 argument is unspecified.
90 .Sh RETURN VALUES
91 The
92 .Fn posix_getopt
93 function opens a manager pseudo-terminal device and, if successful, returns a
94 non-negative integer representing the lowest numbered unused file descriptor ;
95 otherwise, the value
96 .Sy -1
97 is returned and the global variable
98 .Va errno
99 is set to indicate the error.
100 .Sh EXAMPLES
101 .Sy Example 1
102 Open a pseudo-terminal.
103 .Pp
104 The following example opens a pseudo-terminal and returns the name of the
105 subsidiary device and a file descriptor.
106 .Bd -literal -offset Ds
107 #include <fcntl.h>
108 #include <stdio.h>
109 #include <err.h>
110
111 int managerfd, subsidiaryfd;
112 char *subsidiarydevice;
113
114 if ((managerfd = posix_openpt(O_RDWR|O_NOCTTY)) < 0) {
115 err(1, "opening pseudo-terminal manager");
116 }
117
118 if (grantpt(managerfd) != 0 ||
119 unlockpt(managerfd) != 0 ||
120 (subsidiarydevice = ptsname(managerfd)) == NULL) {
121 (void) close(managerfd);
122 err(1, "locating pseudo-terminal subsidiary");
123 }
124
125 printf("subsidiary device is: %s\en", subsidiarydevice);
126
127 if ((subsidiaryfd = open(subsidiary, O_RDWR|O_NOCTTY)) < 0) {
128 err(1, "opening pseudo-terminal subsidiary");
129 }
130 .Ed
131 .Sh ERRORS
132 The
133 .Fn posix_openpt
134 function will fail if:
135 .Bl -tag -width Er
136 .It Er EMFILE
137 .Brq Dv OPEN_MAX
138 file descriptors are currently open in the calling process.
139 .It Er ENFILE
140 The maximum allowable number of files is currently open in the system.
141 .El
142 .Pp
143 The
144 .Fn posix_openpt
145 function may fail if:
146 .Bl -tag -width Er
147 .It Er EINVAL
148 The value of
149 .Fa oflag
150 is not valid.
151 .It Er EAGAIN
152 The system has run out of pseudo-terminal resources.
153 .It Er ENOSR
154 The system has run out of STREAMS resources.
155 .El
156 .Sh USAGE
157 This function provides a portable method for obtaining the file descriptor of a
158 manager terminal device for a pseudo-terminal, as opposed to using
159 .Xr open 2
160 on the
161 .Xr ptm 7D
162 device which is system-specific.
163 .Pp
164 The
165 .Xr grantpt 3C
166 function can be used to manipulate the mode and ownership permissions
167 of the subsidiary device.
168 The
169 .Xr ptsname 3C
170 function can be used to obtain the name of the subsidiary device.
171 .Sh INTERFACE STABILITY
172 .Sy Committed
173 .Sh MT LEVEL
174 .Sy MT-Safe
175 .Sh SEE ALSO
176 .Xr open 2 ,
177 .Xr grantpt 3C ,
178 .Xr ptsname 3C ,
179 .Xr unlockpt 3C ,
180 .Xr attributes 5 ,
181 .Xr standards 5 ,
182 .Xr ptm 7D ,
183 .Xr pts 7D
|