1POSIX_OPENPT(3) Linux Programmer's Manual POSIX_OPENPT(3)
2
3
4
6 posix_openpt - open a pseudo-terminal device
7
9 #define _XOPEN_SOURCE 600
10 #include <stdlib.h>
11 #include <fcntl.h>
12
13 int posix_openpt(int flags);
14
16 The posix_openpt() function opens an unused pseudo-terminal master
17 device, returning a file descriptor that can be used to refer to that
18 device.
19
20 The flags argument is a bit mask that ORs together zero or more of the
21 following flags:
22
23 O_RDWR Open the device for both reading and writing. It is usual to
24 specify this flag.
25
26 O_NOCTTY
27 Do not make this device the controlling terminal for the
28 process.
29
31 On success, posix_openpt() returns a non-negative file descriptor which
32 is the lowest numbered unused descriptor. On failure, -1 is returned,
33 and errno is set to indicate the error.
34
36 See open(2).
37
39 posix_openpt() is part of the Unix98 pseudo-terminal support (see
40 pts(4)). This function is specified in POSIX.1-2001.
41
43 This function is a recent invention in POSIX. Some Unix implementa‐
44 tions that support System V (aka Unix 98) pseudo-terminals don't have
45 this function, but it is easy to implement:
46
47 int
48 posix_openpt(int flags)
49 {
50 return open("/dev/ptmx", flags);
51 }
52
54 open(2), getpt(3), grantpt(3), ptsname(3), unlock(3), pts(4), fea‐
55 ture_test_macros(7), pty(7)
56
57
58
59PTY Control 2007-01-08 POSIX_OPENPT(3)