1*86d7f5d3SJohn Marino.\" 2*86d7f5d3SJohn Marino.\" Copyright (c) 2002 The FreeBSD Project, Inc. 3*86d7f5d3SJohn Marino.\" All rights reserved. 4*86d7f5d3SJohn Marino.\" 5*86d7f5d3SJohn Marino.\" This software includes code contributed to the FreeBSD Project 6*86d7f5d3SJohn Marino.\" by Ryan Younce of North Carolina State University. 7*86d7f5d3SJohn Marino.\" 8*86d7f5d3SJohn Marino.\" Redistribution and use in source and binary forms, with or without 9*86d7f5d3SJohn Marino.\" modification, are permitted provided that the following conditions 10*86d7f5d3SJohn Marino.\" are met: 11*86d7f5d3SJohn Marino.\" 1. Redistributions of source code must retain the above copyright 12*86d7f5d3SJohn Marino.\" notice, this list of conditions and the following disclaimer. 13*86d7f5d3SJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright 14*86d7f5d3SJohn Marino.\" notice, this list of conditions and the following disclaimer in the 15*86d7f5d3SJohn Marino.\" documentation and/or other materials provided with the distribution. 16*86d7f5d3SJohn Marino.\" 3. Neither the name of the FreeBSD Project nor the names of its 17*86d7f5d3SJohn Marino.\" contributors may be used to endorse or promote products derived from 18*86d7f5d3SJohn Marino.\" this software without specific prior written permission. 19*86d7f5d3SJohn Marino.\" 20*86d7f5d3SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT AND CONTRIBUTORS 21*86d7f5d3SJohn Marino.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22*86d7f5d3SJohn Marino.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 23*86d7f5d3SJohn Marino.\" PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT 24*86d7f5d3SJohn Marino.\" OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25*86d7f5d3SJohn Marino.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 26*86d7f5d3SJohn Marino.\" TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27*86d7f5d3SJohn Marino.\" PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28*86d7f5d3SJohn Marino.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29*86d7f5d3SJohn Marino.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30*86d7f5d3SJohn Marino.\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31*86d7f5d3SJohn Marino.\" 32*86d7f5d3SJohn Marino.\" $FreeBSD: src/lib/libc/sys/posix_openpt.2,v 1.1 2008/08/20 08:31:58 ed Exp $ 33*86d7f5d3SJohn Marino.\" 34*86d7f5d3SJohn Marino.Dd September 10, 2009 35*86d7f5d3SJohn Marino.Dt POSIX_OPENPT 3 36*86d7f5d3SJohn Marino.Os 37*86d7f5d3SJohn Marino.Sh NAME 38*86d7f5d3SJohn Marino.Nm posix_openpt 39*86d7f5d3SJohn Marino.Nd "open a pseudo-terminal device" 40*86d7f5d3SJohn Marino.Sh LIBRARY 41*86d7f5d3SJohn Marino.Lb libc 42*86d7f5d3SJohn Marino.Sh SYNOPSIS 43*86d7f5d3SJohn Marino.In stdlib.h 44*86d7f5d3SJohn Marino.In fcntl.h 45*86d7f5d3SJohn Marino.Ft int 46*86d7f5d3SJohn Marino.Fn posix_openpt "int oflag" 47*86d7f5d3SJohn Marino.Sh DESCRIPTION 48*86d7f5d3SJohn MarinoThe 49*86d7f5d3SJohn Marino.Fn posix_openpt 50*86d7f5d3SJohn Marinofunction allocates a new pseudo-terminal and establishes a connection 51*86d7f5d3SJohn Marinowith its master device. 52*86d7f5d3SJohn MarinoA slave device shall be created in 53*86d7f5d3SJohn Marino.Pa /dev/pts . 54*86d7f5d3SJohn MarinoAfter the pseudo-terminal has been allocated, the slave will already 55*86d7f5d3SJohn Marinohave the proper permissions (see 56*86d7f5d3SJohn Marino.Xr grantpt 3 ) 57*86d7f5d3SJohn Marinowithout the need to call 58*86d7f5d3SJohn Marino.Xr grantpt 3 . 59*86d7f5d3SJohn MarinoThe name of the slave device can be determined by calling 60*86d7f5d3SJohn Marino.Xr ptsname 3 . 61*86d7f5d3SJohn Marino.Pp 62*86d7f5d3SJohn MarinoThe file status flags and file access modes of the open file description 63*86d7f5d3SJohn Marinoshall be set according to the value of 64*86d7f5d3SJohn Marino.Fa oflag . 65*86d7f5d3SJohn MarinoValues for 66*86d7f5d3SJohn Marino.Fa oflag 67*86d7f5d3SJohn Marinoare constructed by a bitwise-inclusive OR of flags from the following 68*86d7f5d3SJohn Marinolist, defined in 69*86d7f5d3SJohn Marino.In fcntl.h : 70*86d7f5d3SJohn Marino.Bl -tag -width ".Dv O_NOCTTY" 71*86d7f5d3SJohn Marino.It Dv O_RDWR 72*86d7f5d3SJohn MarinoOpen for reading and writing. 73*86d7f5d3SJohn Marino.It Dv O_NOCTTY 74*86d7f5d3SJohn MarinoIf set 75*86d7f5d3SJohn Marino.Fn posix_openpt 76*86d7f5d3SJohn Marinoshall not cause the terminal device to become the controlling terminal 77*86d7f5d3SJohn Marinofor the process. 78*86d7f5d3SJohn Marino.El 79*86d7f5d3SJohn Marino.Pp 80*86d7f5d3SJohn MarinoThe 81*86d7f5d3SJohn Marino.Fn posix_openpt 82*86d7f5d3SJohn Marinofunction shall fail when 83*86d7f5d3SJohn Marino.Fa oflag 84*86d7f5d3SJohn Marinocontains other values. 85*86d7f5d3SJohn Marino.Sh RETURN VALUES 86*86d7f5d3SJohn MarinoUpon successful completion, the 87*86d7f5d3SJohn Marino.Fn posix_openpt 88*86d7f5d3SJohn Marinofunction shall allocate a new pseudo-terminal device and return a 89*86d7f5d3SJohn Marinonon-negative integer representing a file descriptor, which is connected 90*86d7f5d3SJohn Marinoto its master device. 91*86d7f5d3SJohn MarinoOtherwise, -1 shall be returned and errno set to indicate the error. 92*86d7f5d3SJohn Marino.Sh ERRORS 93*86d7f5d3SJohn MarinoThe 94*86d7f5d3SJohn Marino.Fn posix_openpt 95*86d7f5d3SJohn Marinofunction shall fail if: 96*86d7f5d3SJohn Marino.Bl -tag -width Er 97*86d7f5d3SJohn Marino.It Bq Er ENFILE 98*86d7f5d3SJohn MarinoThe system file table is full. 99*86d7f5d3SJohn Marino.It Bq Er EINVAL 100*86d7f5d3SJohn MarinoThe value of 101*86d7f5d3SJohn Marino.Fa oflag 102*86d7f5d3SJohn Marinois not valid. 103*86d7f5d3SJohn Marino.El 104*86d7f5d3SJohn Marino.Sh SEE ALSO 105*86d7f5d3SJohn Marino.Xr open 2 , 106*86d7f5d3SJohn Marino.Xr grantpt 3 , 107*86d7f5d3SJohn Marino.Xr ptsname 3 , 108*86d7f5d3SJohn Marino.Xr unlockpt 3 , 109*86d7f5d3SJohn Marino.Xr tty 4 110*86d7f5d3SJohn Marino.Sh RATIONALE 111*86d7f5d3SJohn MarinoThe standards committee did not want to directly expose the cloning device and 112*86d7f5d3SJohn Marinothus decided to wrap the functionality in this function. 113*86d7f5d3SJohn MarinoThe equivalent code would be: 114*86d7f5d3SJohn Marino.Bd -literal 115*86d7f5d3SJohn Marino int 116*86d7f5d3SJohn Marino posix_openpt(int oflag) { 117*86d7f5d3SJohn Marino return open("/dev/ptmx", oflag); 118*86d7f5d3SJohn Marino } 119*86d7f5d3SJohn Marino.Ed 120*86d7f5d3SJohn Marino.Sh STANDARDS 121*86d7f5d3SJohn MarinoThe 122*86d7f5d3SJohn Marino.Fn posix_openpt 123*86d7f5d3SJohn Marinofunction conforms to 124*86d7f5d3SJohn Marino.St -p1003.1-2001 . 125*86d7f5d3SJohn Marino.Sh HISTORY 126*86d7f5d3SJohn MarinoThe 127*86d7f5d3SJohn Marino.Fn posix_openpt 128*86d7f5d3SJohn Marinofunction appeared in 129*86d7f5d3SJohn Marino.Dx 2.3 . 130*86d7f5d3SJohn Marino.Sh NOTES 131*86d7f5d3SJohn MarinoThe 132*86d7f5d3SJohn Marino.Fn posix_openpt 133*86d7f5d3SJohn Marinois equivalent in 134*86d7f5d3SJohn Marino.Dx 135*86d7f5d3SJohn Marinoto calling 136*86d7f5d3SJohn Marino.Xr open 2 137*86d7f5d3SJohn Marinoon 138*86d7f5d3SJohn Marino.Pa /dev/ptmx . 139*86d7f5d3SJohn Marino.Pp 140*86d7f5d3SJohn MarinoThe flag 141*86d7f5d3SJohn Marino.Dv O_NOCTTY 142*86d7f5d3SJohn Marinois included for compatibility; in 143*86d7f5d3SJohn Marino.Dx , 144*86d7f5d3SJohn Marinoopening a terminal does not cause it to become a process's controlling 145*86d7f5d3SJohn Marinoterminal. 146