166492cf0SYuri Pankov.\" 266492cf0SYuri Pankov.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for 366492cf0SYuri Pankov.\" permission to reproduce portions of its copyrighted documentation. 466492cf0SYuri Pankov.\" Original documentation from The Open Group can be obtained online at 5c10c16deSRichard Lowe.\" http://www.opengroup.org/bookstore/. 666492cf0SYuri Pankov.\" 766492cf0SYuri Pankov.\" The Institute of Electrical and Electronics Engineers and The Open 866492cf0SYuri Pankov.\" Group, have given us permission to reprint portions of their 966492cf0SYuri Pankov.\" documentation. 1066492cf0SYuri Pankov.\" 1166492cf0SYuri Pankov.\" In the following statement, the phrase ``this text'' refers to portions 1266492cf0SYuri Pankov.\" of the system documentation. 1366492cf0SYuri Pankov.\" 1466492cf0SYuri Pankov.\" Portions of this text are reprinted and reproduced in electronic form 1566492cf0SYuri Pankov.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, 1666492cf0SYuri Pankov.\" Standard for Information Technology -- Portable Operating System 1766492cf0SYuri Pankov.\" Interface (POSIX), The Open Group Base Specifications Issue 6, 1866492cf0SYuri Pankov.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics 1966492cf0SYuri Pankov.\" Engineers, Inc and The Open Group. In the event of any discrepancy 2066492cf0SYuri Pankov.\" between these versions and the original IEEE and The Open Group 2166492cf0SYuri Pankov.\" Standard, the original IEEE and The Open Group Standard is the referee 2266492cf0SYuri Pankov.\" document. The original Standard can be obtained online at 2366492cf0SYuri Pankov.\" http://www.opengroup.org/unix/online.html. 2466492cf0SYuri Pankov.\" 25c10c16deSRichard Lowe.\" This notice shall appear on any product containing this material. 2666492cf0SYuri Pankov.\" 2766492cf0SYuri Pankov.\" The contents of this file are subject to the terms of the 2866492cf0SYuri Pankov.\" Common Development and Distribution License (the "License"). 2966492cf0SYuri Pankov.\" You may not use this file except in compliance with the License. 3066492cf0SYuri Pankov.\" 3166492cf0SYuri Pankov.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 3266492cf0SYuri Pankov.\" or http://www.opensolaris.org/os/licensing. 3366492cf0SYuri Pankov.\" See the License for the specific language governing permissions 3466492cf0SYuri Pankov.\" and limitations under the License. 3566492cf0SYuri Pankov.\" 3666492cf0SYuri Pankov.\" When distributing Covered Code, include this CDDL HEADER in each 3766492cf0SYuri Pankov.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. 3866492cf0SYuri Pankov.\" If applicable, add the following below this CDDL HEADER, with the 3966492cf0SYuri Pankov.\" fields enclosed by brackets "[]" replaced with your own identifying 4066492cf0SYuri Pankov.\" information: Portions Copyright [yyyy] [name of copyright owner] 4166492cf0SYuri Pankov.\" 4266492cf0SYuri Pankov.\" 4366492cf0SYuri Pankov.\" Copyright (c) 2001, The IEEE and The Open Group. All Rights Reserved. 4466492cf0SYuri Pankov.\" Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved. 451fa2a664SJoshua M. Clulow.\" Copyright 2022 Oxide Computer Company 4666492cf0SYuri Pankov.\" 471fa2a664SJoshua M. Clulow.Dd February 5, 2022 481fa2a664SJoshua M. Clulow.Dt POSIX_OPENPT 3C 491fa2a664SJoshua M. Clulow.Os 501fa2a664SJoshua M. Clulow.Sh NAME 511fa2a664SJoshua M. Clulow.Nm posix_openpt 521fa2a664SJoshua M. Clulow.Nd open a pseudo-terminal manager device 531fa2a664SJoshua M. Clulow.Sh SYNOPSIS 541fa2a664SJoshua M. Clulow.In stdlib.h 551fa2a664SJoshua M. Clulow.In fcntl.h 561fa2a664SJoshua M. Clulow.Ft int 571fa2a664SJoshua M. Clulow.Fo posix_openpt 581fa2a664SJoshua M. Clulow.Fa "int oflag" 591fa2a664SJoshua M. Clulow.Fc 601fa2a664SJoshua M. Clulow.Sh DESCRIPTION 611fa2a664SJoshua M. ClulowThe 621fa2a664SJoshua M. Clulow.Fn posix_openpt 631fa2a664SJoshua M. Clulowfunction establishes a connection between a manager device for a 641fa2a664SJoshua M. Clulowpseudo-terminal and a file descriptor. 651fa2a664SJoshua M. ClulowThe file descriptor is used by other I/O functions that refer to that 661fa2a664SJoshua M. Clulowpseudo-terminal. 671fa2a664SJoshua M. Clulow.Pp 68c10c16deSRichard LoweThe file status flags and file access modes of the open file description are 691fa2a664SJoshua M. Clulowset according to the value of 701fa2a664SJoshua M. Clulow.Fa oflag . 711fa2a664SJoshua M. Clulow.Pp 721fa2a664SJoshua M. ClulowValues for 731fa2a664SJoshua M. Clulow.Fa oflag 741fa2a664SJoshua M. Cluloware constructed by a bitwise-inclusive OR of flags from 751fa2a664SJoshua M. Clulowthe following list, defined in 761fa2a664SJoshua M. Clulow.Xr fcntl.h 3HEAD : 771fa2a664SJoshua M. Clulow.Bl -tag -width Ds 781fa2a664SJoshua M. Clulow.It Dv O_RDWR 79c10c16deSRichard LoweOpen for reading and writing. 801fa2a664SJoshua M. Clulow.It Dv O_NOCTTY 811fa2a664SJoshua M. ClulowIf set, 821fa2a664SJoshua M. Clulow.Fn posix_openpt 831fa2a664SJoshua M. Clulowdoes not cause the terminal device to become the controlling terminal for the 841fa2a664SJoshua M. Clulowprocess. 851fa2a664SJoshua M. Clulow.El 861fa2a664SJoshua M. Clulow.Pp 871fa2a664SJoshua M. ClulowThe behavior of other values for the 881fa2a664SJoshua M. Clulow.Fa oflag 891fa2a664SJoshua M. Clulowargument is unspecified. 901fa2a664SJoshua M. Clulow.Sh RETURN VALUES 911fa2a664SJoshua M. ClulowThe 921fa2a664SJoshua M. Clulow.Fn posix_getopt 931fa2a664SJoshua M. Clulowfunction opens a manager pseudo-terminal device and, if successful, returns a 941fa2a664SJoshua M. Clulownon-negative integer representing the lowest numbered unused file descriptor ; 951fa2a664SJoshua M. Clulowotherwise, the value 961fa2a664SJoshua M. Clulow.Sy -1 971fa2a664SJoshua M. Clulowis returned and the global variable 981fa2a664SJoshua M. Clulow.Va errno 991fa2a664SJoshua M. Clulowis set to indicate the error. 1001fa2a664SJoshua M. Clulow.Sh EXAMPLES 1011fa2a664SJoshua M. Clulow.Sy Example 1 1021fa2a664SJoshua M. ClulowOpen a pseudo-terminal. 1031fa2a664SJoshua M. Clulow.Pp 1041fa2a664SJoshua M. ClulowThe following example opens a pseudo-terminal and returns the name of the 1051fa2a664SJoshua M. Clulowsubsidiary device and a file descriptor. 1061fa2a664SJoshua M. Clulow.Bd -literal -offset Ds 107c432de9cSPeter Tribble#include <fcntl.h> 108c432de9cSPeter Tribble#include <stdio.h> 1091fa2a664SJoshua M. Clulow#include <err.h> 110c10c16deSRichard Lowe 1111fa2a664SJoshua M. Clulowint managerfd, subsidiaryfd; 1121fa2a664SJoshua M. Clulowchar *subsidiarydevice; 113c10c16deSRichard Lowe 1141fa2a664SJoshua M. Clulowif ((managerfd = posix_openpt(O_RDWR|O_NOCTTY)) < 0) { 1151fa2a664SJoshua M. Clulow err(1, "opening pseudo-terminal manager"); 1161fa2a664SJoshua M. Clulow} 117c10c16deSRichard Lowe 1181fa2a664SJoshua M. Clulowif (grantpt(managerfd) != 0 || 1191fa2a664SJoshua M. Clulow unlockpt(managerfd) != 0 || 1201fa2a664SJoshua M. Clulow (subsidiarydevice = ptsname(managerfd)) == NULL) { 1211fa2a664SJoshua M. Clulow (void) close(managerfd); 1221fa2a664SJoshua M. Clulow err(1, "locating pseudo-terminal subsidiary"); 1231fa2a664SJoshua M. Clulow} 124c10c16deSRichard Lowe 1251fa2a664SJoshua M. Clulowprintf("subsidiary device is: %s\en", subsidiarydevice); 126c10c16deSRichard Lowe 1271fa2a664SJoshua M. Clulowif ((subsidiaryfd = open(subsidiary, O_RDWR|O_NOCTTY)) < 0) { 1281fa2a664SJoshua M. Clulow err(1, "opening pseudo-terminal subsidiary"); 1291fa2a664SJoshua M. Clulow} 1301fa2a664SJoshua M. Clulow.Ed 1311fa2a664SJoshua M. Clulow.Sh ERRORS 1321fa2a664SJoshua M. ClulowThe 1331fa2a664SJoshua M. Clulow.Fn posix_openpt 1341fa2a664SJoshua M. Clulowfunction will fail if: 1351fa2a664SJoshua M. Clulow.Bl -tag -width Er 1361fa2a664SJoshua M. Clulow.It Er EMFILE 1371fa2a664SJoshua M. Clulow.Brq Dv OPEN_MAX 1381fa2a664SJoshua M. Clulowfile descriptors are currently open in the calling process. 1391fa2a664SJoshua M. Clulow.It Er ENFILE 1401fa2a664SJoshua M. ClulowThe maximum allowable number of files is currently open in the system. 1411fa2a664SJoshua M. Clulow.El 1421fa2a664SJoshua M. Clulow.Pp 1431fa2a664SJoshua M. ClulowThe 1441fa2a664SJoshua M. Clulow.Fn posix_openpt 1451fa2a664SJoshua M. Clulowfunction may fail if: 1461fa2a664SJoshua M. Clulow.Bl -tag -width Er 1471fa2a664SJoshua M. Clulow.It Er EINVAL 1481fa2a664SJoshua M. ClulowThe value of 1491fa2a664SJoshua M. Clulow.Fa oflag 1501fa2a664SJoshua M. Clulowis not valid. 1511fa2a664SJoshua M. Clulow.It Er EAGAIN 1521fa2a664SJoshua M. ClulowThe system has run out of pseudo-terminal resources. 1531fa2a664SJoshua M. Clulow.It Er ENOSR 1541fa2a664SJoshua M. ClulowThe system has run out of STREAMS resources. 1551fa2a664SJoshua M. Clulow.El 1561fa2a664SJoshua M. Clulow.Sh USAGE 1571fa2a664SJoshua M. ClulowThis function provides a portable method for obtaining the file descriptor of a 1581fa2a664SJoshua M. Clulowmanager terminal device for a pseudo-terminal, as opposed to using 1591fa2a664SJoshua M. Clulow.Xr open 2 1601fa2a664SJoshua M. Clulowon the 161*bbf21555SRichard Lowe.Xr ptm 4D 1621fa2a664SJoshua M. Clulowdevice which is system-specific. 1631fa2a664SJoshua M. Clulow.Pp 1641fa2a664SJoshua M. ClulowThe 1651fa2a664SJoshua M. Clulow.Xr grantpt 3C 1661fa2a664SJoshua M. Clulowfunction can be used to manipulate the mode and ownership permissions 1671fa2a664SJoshua M. Clulowof the subsidiary device. 1681fa2a664SJoshua M. ClulowThe 1691fa2a664SJoshua M. Clulow.Xr ptsname 3C 1701fa2a664SJoshua M. Clulowfunction can be used to obtain the name of the subsidiary device. 1711fa2a664SJoshua M. Clulow.Sh INTERFACE STABILITY 1721fa2a664SJoshua M. Clulow.Sy Committed 1731fa2a664SJoshua M. Clulow.Sh MT LEVEL 1741fa2a664SJoshua M. Clulow.Sy MT-Safe 1751fa2a664SJoshua M. Clulow.Sh SEE ALSO 1761fa2a664SJoshua M. Clulow.Xr open 2 , 1771fa2a664SJoshua M. Clulow.Xr grantpt 3C , 1781fa2a664SJoshua M. Clulow.Xr ptsname 3C , 1791fa2a664SJoshua M. Clulow.Xr unlockpt 3C , 180*bbf21555SRichard Lowe.Xr ptm 4D , 181*bbf21555SRichard Lowe.Xr pts 4D , 182*bbf21555SRichard Lowe.Xr attributes 7 , 183*bbf21555SRichard Lowe.Xr standards 7 184