Debian Codegraph @

upstream/debian-trixie/man3/posix_openpt.3

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