xref: /netbsd-src/lib/libc/stdlib/posix_openpt.3 (revision 7eadd4d3717c38a6f5fd67f0145092f4da2610cb)
1*7eadd4d3Sgutteridge.\" $NetBSD: posix_openpt.3,v 1.10 2022/11/15 22:17:53 gutteridge Exp $
2892ad9caSchristos.\"
3892ad9caSchristos.\" Copyright (c) 2004 The NetBSD Foundation, Inc.
4892ad9caSchristos.\" All rights reserved.
5892ad9caSchristos.\"
6892ad9caSchristos.\" This code is derived from software contributed to The NetBSD Foundation
7892ad9caSchristos.\" by Christos Zoulas.
8892ad9caSchristos.\"
9892ad9caSchristos.\" Redistribution and use in source and binary forms, with or without
10892ad9caSchristos.\" modification, are permitted provided that the following conditions
11892ad9caSchristos.\" are met:
12892ad9caSchristos.\" 1. Redistributions of source code must retain the above copyright
13892ad9caSchristos.\"    notice, this list of conditions and the following disclaimer.
14892ad9caSchristos.\" 2. Redistributions in binary form must reproduce the above copyright
15892ad9caSchristos.\"    notice, this list of conditions and the following disclaimer in the
16892ad9caSchristos.\"    documentation and/or other materials provided with the distribution.
17892ad9caSchristos.\"
18892ad9caSchristos.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19892ad9caSchristos.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20892ad9caSchristos.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21892ad9caSchristos.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22892ad9caSchristos.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23892ad9caSchristos.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24892ad9caSchristos.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25892ad9caSchristos.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26892ad9caSchristos.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27892ad9caSchristos.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28892ad9caSchristos.\" POSSIBILITY OF SUCH DAMAGE.
29892ad9caSchristos.\"
30*7eadd4d3Sgutteridge.Dd November 15, 2022
31508c6e77Swiz.Dt POSIX_OPENPT 3
32892ad9caSchristos.Os
33892ad9caSchristos.Sh NAME
34892ad9caSchristos.Nm posix_openpt
35892ad9caSchristos.Nd open a pseudo-terminal device
36892ad9caSchristos.Sh LIBRARY
37892ad9caSchristos.Lb libc
38892ad9caSchristos.Sh SYNOPSIS
39892ad9caSchristos.In stdlib.h
40892ad9caSchristos.In fcntl.h
41892ad9caSchristos.Ft int
42892ad9caSchristos.Fn posix_openpt "int oflag"
43892ad9caSchristos.Sh DESCRIPTION
4419742b49SjruohoThe
45892ad9caSchristos.Fn posix_openpt
4619742b49Sjruohofunction searches for an unused master pseudo-terminal device,
4793cfe89eSwizopens it, and returns a file descriptor associated with the now
4893cfe89eSwizused pseudo-terminal device.
49892ad9caSchristosThe
50892ad9caSchristos.Fa oflag
51892ad9caSchristosargument has the same meaning as in the
52892ad9caSchristos.Xr open 2
53892ad9caSchristoscall.
54892ad9caSchristos.Sh RETURN VALUES
55892ad9caSchristosIf successful,
56892ad9caSchristos.Fn posix_openpt
57892ad9caSchristosreturns a non-negative integer, which corresponds to a file descriptor
58508c6e77Swizpointing to the master pseudo-terminal device.
59508c6e77SwizOtherwise, a value of \-1 is returned and
60892ad9caSchristos.Va errno
61892ad9caSchristosis set to indicate the error.
629b526a43Sgutteridge.Pp
639b526a43SgutteridgeNote that unlike implementations on some other operating systems,
649b526a43Sgutteridge.Fn posix_openpt
659b526a43Sgutteridgedoes not return
669b526a43Sgutteridge.Er EINVAL
67e3b62718Sgutteridgeif a flag supplied in
689b526a43Sgutteridge.Fa oflag
699b526a43Sgutteridgewould be deemed invalid, instead it is simply ignored.
709b526a43SgutteridgeThis means it is not possible to dynamically test which
719b526a43Sgutteridge.Xr open 2
729b526a43Sgutteridgeflags are possible to set, and apply a fallback if
739b526a43Sgutteridge.Er EINVAL
749b526a43Sgutteridgeis received.
755568d804SgutteridgeHowever, this is unlikely to be a concern in practice, as flags such as
765568d804Sgutteridge.Dv O_NONBLOCK
775568d804Sgutteridgeand
785568d804Sgutteridge.Dv O_CLOEXEC
795568d804Sgutteridgeare supported.
80892ad9caSchristos.Sh SEE ALSO
81892ad9caSchristos.Xr ioctl 2 ,
82508c6e77Swiz.Xr open 2 ,
83508c6e77Swiz.Xr grantpt 3 ,
84508c6e77Swiz.Xr ptsname 3 ,
85508c6e77Swiz.Xr unlockpt 3
86892ad9caSchristos.Sh RATIONALE
87892ad9caSchristosThe standards committee did not want to directly expose the cloning device,
88508c6e77Swizthus decided to wrap the functionality in this function.
89508c6e77SwizThe equivalent code would be:
90892ad9caSchristos.Bd -literal
91892ad9caSchristos	int
92892ad9caSchristos	posix_openpt(int oflag) {
93892ad9caSchristos		return open("/dev/ptmx", oflag);
94892ad9caSchristos	}
95892ad9caSchristos.Ed
96892ad9caSchristos.Sh STANDARDS
97892ad9caSchristosThe
98892ad9caSchristos.Fn posix_openpt
99892ad9caSchristosfunction conforms to
100892ad9caSchristos.St -p1003.1-2001 .
101*7eadd4d3Sgutteridge.Sh HISTORY
102*7eadd4d3SgutteridgeThis function first appeared in
103*7eadd4d3Sgutteridge.Nx 3 .
104*7eadd4d3SgutteridgeSupport for non-standard flags appeared in
105*7eadd4d3Sgutteridge.Nx 10 .
106