Debian Codegraph @

upstream/debian-unstable/man3/posix_openpt.3

raw
1 '\" t
2 .\" Copyright 2004, Michael Kerrisk <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH posix_openpt 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 posix_openpt \- open a pseudoterminal device
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <stdlib.h>
16 .B #include <fcntl.h>
17 .P
18 .BI "int posix_openpt(int " flags ");"
19 .fi
20 .P
21 .RS -4
22 Feature Test Macro Requirements for glibc (see
23 .BR feature_test_macros (7)):
24 .RE
25 .P
26 .BR posix_openpt ():
27 .nf
28 _XOPEN_SOURCE >= 600
29 .fi
30 .SH DESCRIPTION
31 The
32 .BR posix_openpt ()
33 function opens an unused pseudoterminal master device, returning a
34 file descriptor that can be used to refer to that device.
35 .P
36 The
37 .I flags
38 argument is a bit mask that ORs together zero or more of
39 the following flags:
40 .TP
41 .B O_RDWR
42 Open the device for both reading and writing.
43 It is usual to specify this flag.
44 .TP
45 .B O_NOCTTY
46 Do not make this device the controlling terminal for the process.
47 .SH RETURN VALUE
48 On success,
49 .BR posix_openpt ()
50 returns a file descriptor (a nonnegative integer) which is the lowest
51 numbered unused file descriptor.
52 On failure, \-1 is returned, and
53 .I errno
54 is set to indicate the error.
55 .SH ERRORS
56 See
57 .BR open (2).
58 .SH ATTRIBUTES
59 For an explanation of the terms used in this section, see
60 .BR attributes (7).
61 .TS
62 allbox;
63 lbx lb lb
64 l l l.
65 Interface Attribute Value
66 T{
67 .na
68 .nh
69 .BR posix_openpt ()
70 T} Thread safety MT-Safe
71 .TE
72 .SH STANDARDS
73 POSIX.1-2008.
74 .SH HISTORY
75 glibc 2.2.1.
76 POSIX.1-2001.
77 .P
78 It is part of the UNIX 98 pseudoterminal support (see
79 .BR pts (4)).
80 .SH NOTES
81 Some older UNIX implementations that support System V
82 (aka UNIX 98) pseudoterminals don't have this function, but it
83 can be easily implemented by opening the pseudoterminal multiplexer device:
84 .P
85 .in +4n
86 .EX
87 int
88 posix_openpt(int flags)
89 {
90 return open("/dev/ptmx", flags);
91 }
92 .EE
93 .in
94 .P
95 Calling
96 .BR posix_openpt ()
97 creates a pathname for the corresponding pseudoterminal slave device.
98 The pathname of the slave device can be obtained using
99 .BR ptsname (3).
100 The slave device pathname exists only as long as the master device is open.
101 .SH SEE ALSO
102 .BR open (2),
103 .BR getpt (3),
104 .BR grantpt (3),
105 .BR ptsname (3),
106 .BR unlockpt (3),
107 .BR pts (4),
108 .BR pty (7)