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