.\" .\" Copyright (c) 2002 The FreeBSD Project, Inc. .\" All rights reserved. .\" .\" This software includes code contributed to the FreeBSD Project .\" by Ryan Younce of North Carolina State University. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the FreeBSD Project nor the names of its .\" contributors may be used to endorse or promote products derived from .\" this software without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A .\" PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT .\" OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED .\" TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR .\" PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF .\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD: src/lib/libc/sys/posix_openpt.2,v 1.1 2008/08/20 08:31:58 ed Exp $ .\" .Dd September 10, 2009 .Dt POSIX_OPENPT 3 .Os .Sh NAME .Nm posix_openpt .Nd "open a pseudo-terminal device" .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In stdlib.h .In fcntl.h .Ft int .Fn posix_openpt "int oflag" .Sh DESCRIPTION The .Fn posix_openpt function allocates a new pseudo-terminal and establishes a connection with its master device. A slave device shall be created in .Pa /dev/pts . After the pseudo-terminal has been allocated, the slave will already have the proper permissions (see .Xr grantpt 3 ) without the need to call .Xr grantpt 3 . The name of the slave device can be determined by calling .Xr ptsname 3 . .Pp The file status flags and file access modes of the open file description shall be set according to the value of .Fa oflag . Values for .Fa oflag are constructed by a bitwise-inclusive OR of flags from the following list, defined in .In fcntl.h : .Bl -tag -width ".Dv O_NOCTTY" .It Dv O_RDWR Open for reading and writing. .It Dv O_NOCTTY If set .Fn posix_openpt shall not cause the terminal device to become the controlling terminal for the process. .El .Pp The .Fn posix_openpt function shall fail when .Fa oflag contains other values. .Sh RETURN VALUES Upon successful completion, the .Fn posix_openpt function shall allocate a new pseudo-terminal device and return a non-negative integer representing a file descriptor, which is connected to its master device. Otherwise, -1 shall be returned and errno set to indicate the error. .Sh ERRORS The .Fn posix_openpt function shall fail if: .Bl -tag -width Er .It Bq Er ENFILE The system file table is full. .It Bq Er EINVAL The value of .Fa oflag is not valid. .El .Sh SEE ALSO .Xr open 2 , .Xr grantpt 3 , .Xr ptsname 3 , .Xr unlockpt 3 , .Xr tty 4 .Sh RATIONALE The standards committee did not want to directly expose the cloning device and thus decided to wrap the functionality in this function. The equivalent code would be: .Bd -literal int posix_openpt(int oflag) { return open("/dev/ptmx", oflag); } .Ed .Sh STANDARDS The .Fn posix_openpt function conforms to .St -p1003.1-2001 . .Sh HISTORY The .Fn posix_openpt function appeared in .Dx 2.3 . .Sh NOTES The .Fn posix_openpt is equivalent in .Dx to calling .Xr open 2 on .Pa /dev/ptmx . .Pp The flag .Dv O_NOCTTY is included for compatibility; in .Dx , opening a terminal does not cause it to become a process's controlling terminal.