diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libc/stdlib/Makefile.inc | 13 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/posix_openpt.3 | 128 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/posix_pty.c | 119 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/ptsname.3 | 160 |
4 files changed, 414 insertions, 6 deletions
diff --git a/src/lib/libc/stdlib/Makefile.inc b/src/lib/libc/stdlib/Makefile.inc index 652d6fb90f..5f3a142ec4 100644 --- a/src/lib/libc/stdlib/Makefile.inc +++ b/src/lib/libc/stdlib/Makefile.inc | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile.inc,v 1.46 2012/09/15 20:59:38 miod Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.47 2012/12/03 20:08:33 millert Exp $ |
| 2 | 2 | ||
| 3 | # stdlib sources | 3 | # stdlib sources |
| 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/stdlib ${LIBCSRCDIR}/stdlib | 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/stdlib ${LIBCSRCDIR}/stdlib |
| @@ -6,8 +6,8 @@ | |||
| 6 | SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c atoll.c bsearch.c \ | 6 | SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c atoll.c bsearch.c \ |
| 7 | cfree.c exit.c ecvt.c gcvt.c getenv.c getopt_long.c \ | 7 | cfree.c exit.c ecvt.c gcvt.c getenv.c getopt_long.c \ |
| 8 | getsubopt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c l64a.c llabs.c \ | 8 | getsubopt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c l64a.c llabs.c \ |
| 9 | lldiv.c lsearch.c malloc.c merge.c qsort.c radixsort.c rand.c \ | 9 | lldiv.c lsearch.c malloc.c merge.c posix_pty.c qsort.c radixsort.c \ |
| 10 | random.c realpath.c setenv.c strtoimax.c strtol.c \ | 10 | rand.c random.c realpath.c setenv.c strtoimax.c strtol.c \ |
| 11 | strtoll.c strtonum.c strtoul.c strtoull.c strtoumax.c system.c \ | 11 | strtoll.c strtonum.c strtoul.c strtoull.c strtoumax.c system.c \ |
| 12 | tfind.c tsearch.c _rand48.c drand48.c erand48.c jrand48.c lcong48.c \ | 12 | tfind.c tsearch.c _rand48.c drand48.c erand48.c jrand48.c lcong48.c \ |
| 13 | lrand48.c mrand48.c nrand48.c seed48.c srand48.c qabs.c qdiv.c _Exit.c | 13 | lrand48.c mrand48.c nrand48.c seed48.c srand48.c qabs.c qdiv.c _Exit.c |
| @@ -34,9 +34,9 @@ SRCS+= insque.c remque.c | |||
| 34 | MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 atoll.3 \ | 34 | MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 atoll.3 \ |
| 35 | bsearch.3 div.3 ecvt.3 exit.3 getenv.3 getopt.3 getopt_long.3 \ | 35 | bsearch.3 div.3 ecvt.3 exit.3 getenv.3 getopt.3 getopt_long.3 \ |
| 36 | getsubopt.3 hcreate.3 imaxabs.3 imaxdiv.3 insque.3 labs.3 ldiv.3 \ | 36 | getsubopt.3 hcreate.3 imaxabs.3 imaxdiv.3 insque.3 labs.3 ldiv.3 \ |
| 37 | lldiv.3 lsearch.3 malloc.3 posix_memalign.3 qabs.3 qdiv.3 qsort.3 \ | 37 | lldiv.3 lsearch.3 malloc.3 posix_memalign.3 posix_openpt.3 ptsname.3 \ |
| 38 | radixsort.3 rand48.3 rand.3 random.3 realpath.3 strtod.3 strtonum.3 \ | 38 | qabs.3 qdiv.3 qsort.3 radixsort.3 rand48.3 rand.3 random.3 realpath.3 \ |
| 39 | strtol.3 strtoul.3 system.3 tsearch.3 | 39 | strtod.3 strtonum.3 strtol.3 strtoul.3 system.3 tsearch.3 |
| 40 | 40 | ||
| 41 | MLINKS+=exit.3 _Exit.3 | 41 | MLINKS+=exit.3 _Exit.3 |
| 42 | MLINKS+=ecvt.3 fcvt.3 ecvt.3 gcvt.3 | 42 | MLINKS+=ecvt.3 fcvt.3 ecvt.3 gcvt.3 |
| @@ -56,6 +56,7 @@ MLINKS+=random.3 srandom.3 random.3 srandomdev.3 | |||
| 56 | MLINKS+=rand48.3 drand48.3 rand48.3 erand48.3 rand48.3 lrand48.3 | 56 | MLINKS+=rand48.3 drand48.3 rand48.3 erand48.3 rand48.3 lrand48.3 |
| 57 | MLINKS+=rand48.3 mrand48.3 rand48.3 nrand48.3 rand48.3 jrand48.3 | 57 | MLINKS+=rand48.3 mrand48.3 rand48.3 nrand48.3 rand48.3 jrand48.3 |
| 58 | MLINKS+=rand48.3 srand48.3 rand48.3 seed48.3 rand48.3 lcong48.3 | 58 | MLINKS+=rand48.3 srand48.3 rand48.3 seed48.3 rand48.3 lcong48.3 |
| 59 | MLINKS+=ptsname.3 grantpt.3 ptsname.3 unlockpt.3 | ||
| 59 | MLINKS+=strtod.3 strtof.3 strtod.3 strtold.3 | 60 | MLINKS+=strtod.3 strtof.3 strtod.3 strtold.3 |
| 60 | MLINKS+=strtol.3 strtoll.3 strtol.3 strtoq.3 strtol.3 strtoimax.3 | 61 | MLINKS+=strtol.3 strtoll.3 strtol.3 strtoq.3 strtol.3 strtoimax.3 |
| 61 | MLINKS+=strtoul.3 strtoull.3 strtoul.3 strtouq.3 strtoul.3 strtoumax.3 | 62 | MLINKS+=strtoul.3 strtoull.3 strtoul.3 strtouq.3 strtoul.3 strtoumax.3 |
diff --git a/src/lib/libc/stdlib/posix_openpt.3 b/src/lib/libc/stdlib/posix_openpt.3 new file mode 100644 index 0000000000..d292ac0a5f --- /dev/null +++ b/src/lib/libc/stdlib/posix_openpt.3 | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | .\" $OpenBSD: posix_openpt.3,v 1.1 2012/12/03 20:08:33 millert Exp $ | ||
| 2 | .\" | ||
| 3 | .\" Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org> | ||
| 4 | .\" All rights reserved. | ||
| 5 | .\" | ||
| 6 | .\" Portions of this software were developed under sponsorship from Snow | ||
| 7 | .\" B.V., the Netherlands. | ||
| 8 | .\" | ||
| 9 | .\" Redistribution and use in source and binary forms, with or without | ||
| 10 | .\" modification, are permitted provided that the following conditions | ||
| 11 | .\" are met: | ||
| 12 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 13 | .\" notice, this list of conditions and the following disclaimer. | ||
| 14 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 15 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 16 | .\" documentation and/or other materials provided with the distribution. | ||
| 17 | .\" | ||
| 18 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 19 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 20 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 21 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 22 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 23 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 24 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 25 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 26 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 28 | .\" SUCH DAMAGE. | ||
| 29 | .\" | ||
| 30 | .\" Portions of this text are reprinted and reproduced in electronic form | ||
| 31 | .\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- | ||
| 32 | .\" Portable Operating System Interface (POSIX), The Open Group Base | ||
| 33 | .\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of | ||
| 34 | .\" Electrical and Electronics Engineers, Inc and The Open Group. In the | ||
| 35 | .\" event of any discrepancy between this version and the original IEEE and | ||
| 36 | .\" The Open Group Standard, the original IEEE and The Open Group Standard is | ||
| 37 | .\" the referee document. The original Standard can be obtained online at | ||
| 38 | .\" http://www.opengroup.org/unix/online.html. | ||
| 39 | .\" | ||
| 40 | .\" $FreeBSD: head/lib/libc/sys/posix_openpt.2 181905 2008-08-20 08:31:58Z ed $ | ||
| 41 | .\" | ||
| 42 | .Dd $Mdocdate: December 3 2012 $ | ||
| 43 | .Dt POSIX_OPENPT 3 | ||
| 44 | .Os | ||
| 45 | .Sh NAME | ||
| 46 | .Nm posix_openpt | ||
| 47 | .Nd "open a pseudo-terminal device" | ||
| 48 | .Sh SYNOPSIS | ||
| 49 | .In stdlib.h | ||
| 50 | .In fcntl.h | ||
| 51 | .Ft int | ||
| 52 | .Fn posix_openpt "int oflag" | ||
| 53 | .Sh DESCRIPTION | ||
| 54 | The | ||
| 55 | .Fn posix_openpt | ||
| 56 | function allocates a new pseudo-terminal and establishes a connection | ||
| 57 | with its master device. | ||
| 58 | After the pseudo-terminal has been allocated, the slave device should | ||
| 59 | have the proper permissions before it can be used (see | ||
| 60 | .Xr grantpt 3 ) . | ||
| 61 | The name of the slave device can be determined by calling | ||
| 62 | .Xr ptsname 3 . | ||
| 63 | .Pp | ||
| 64 | The file status flags and file access modes of the open file description | ||
| 65 | shall be set according to the value of | ||
| 66 | .Fa oflag . | ||
| 67 | Values for | ||
| 68 | .Fa oflag | ||
| 69 | are constructed by a bitwise-inclusive OR of flags from the following | ||
| 70 | list, defined in | ||
| 71 | .In fcntl.h : | ||
| 72 | .Bl -tag -width ".Dv O_NOCTTY" | ||
| 73 | .It Dv O_RDWR | ||
| 74 | Open for reading and writing. | ||
| 75 | .It Dv O_NOCTTY | ||
| 76 | If set | ||
| 77 | .Fn posix_openpt | ||
| 78 | shall not cause the terminal device to become the controlling terminal | ||
| 79 | for the process. | ||
| 80 | .El | ||
| 81 | .Pp | ||
| 82 | The | ||
| 83 | .Fn posix_openpt | ||
| 84 | function shall fail when | ||
| 85 | .Fa oflag | ||
| 86 | contains other values. | ||
| 87 | .Sh RETURN VALUES | ||
| 88 | Upon successful completion, the | ||
| 89 | .Fn posix_openpt | ||
| 90 | function shall allocate a new pseudo-terminal device and return a | ||
| 91 | non-negative integer representing a file descriptor, which is connected | ||
| 92 | to its master device. | ||
| 93 | Otherwise, -1 shall be returned and errno set to indicate the error. | ||
| 94 | .Sh ERRORS | ||
| 95 | The | ||
| 96 | .Fn posix_openpt | ||
| 97 | function shall fail if: | ||
| 98 | .Bl -tag -width Er | ||
| 99 | .It Bq Er EMFILE | ||
| 100 | The per-process descriptor table is full. | ||
| 101 | .It Bq Er ENFILE | ||
| 102 | The system file table is full. | ||
| 103 | .It Bq Er EINVAL | ||
| 104 | The value of | ||
| 105 | .Fa oflag | ||
| 106 | is not valid. | ||
| 107 | .El | ||
| 108 | .Sh SEE ALSO | ||
| 109 | .Xr ptsname 3 , | ||
| 110 | .Xr pty 4 , | ||
| 111 | .Xr tty 4 | ||
| 112 | .Sh STANDARDS | ||
| 113 | The | ||
| 114 | .Fn posix_openpt | ||
| 115 | function conforms to | ||
| 116 | .St -p1003.1-2001 . | ||
| 117 | .Sh HISTORY | ||
| 118 | The | ||
| 119 | .Fn posix_openpt | ||
| 120 | function appeared in | ||
| 121 | .Ox 5.3 . | ||
| 122 | .Sh CAVEATS | ||
| 123 | The flag | ||
| 124 | .Dv O_NOCTTY | ||
| 125 | is included for compatibility; in | ||
| 126 | .Ox , | ||
| 127 | opening a terminal does not cause it to become a process's controlling | ||
| 128 | terminal. | ||
diff --git a/src/lib/libc/stdlib/posix_pty.c b/src/lib/libc/stdlib/posix_pty.c new file mode 100644 index 0000000000..a2025ddbb6 --- /dev/null +++ b/src/lib/libc/stdlib/posix_pty.c | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | /* $OpenBSD: posix_pty.c,v 1.1 2012/12/03 20:08:33 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2012 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <sys/types.h> | ||
| 20 | #include <sys/ioctl.h> | ||
| 21 | #include <sys/stat.h> | ||
| 22 | #include <sys/tty.h> | ||
| 23 | #include <errno.h> | ||
| 24 | #include <fcntl.h> | ||
| 25 | #include <paths.h> | ||
| 26 | #include <stddef.h> | ||
| 27 | #include <stdlib.h> | ||
| 28 | #include <string.h> | ||
| 29 | #include <unistd.h> | ||
| 30 | |||
| 31 | int | ||
| 32 | posix_openpt(int oflag) | ||
| 33 | { | ||
| 34 | struct ptmget ptm; | ||
| 35 | int fd, mfd = -1; | ||
| 36 | |||
| 37 | /* User must specify O_RDWR in oflag. */ | ||
| 38 | if (!(oflag & O_RDWR)) { | ||
| 39 | errno = EINVAL; | ||
| 40 | return -1; | ||
| 41 | } | ||
| 42 | |||
| 43 | /* Get pty master and slave (this API only uses the master). */ | ||
| 44 | fd = open(PATH_PTMDEV, O_RDWR); | ||
| 45 | if (fd != -1) { | ||
| 46 | if (ioctl(fd, PTMGET, &ptm) != -1) { | ||
| 47 | close(ptm.sfd); | ||
| 48 | mfd = ptm.cfd; | ||
| 49 | } | ||
| 50 | close(fd); | ||
| 51 | } | ||
| 52 | |||
| 53 | return mfd; | ||
| 54 | } | ||
| 55 | |||
| 56 | /* | ||
| 57 | * Look up the name of the specified pty master fd. | ||
| 58 | * Note that the name returned does *not* include the /dev/ prefix. | ||
| 59 | * Returns the name on success and NULL on error, setting errno. | ||
| 60 | */ | ||
| 61 | static const char * | ||
| 62 | ptmname(int mfd) | ||
| 63 | { | ||
| 64 | struct stat sb; | ||
| 65 | const char *name; | ||
| 66 | |||
| 67 | /* Make sure it is a pty master. */ | ||
| 68 | if (fstat(mfd, &sb) != 0) | ||
| 69 | return NULL; | ||
| 70 | if (!S_ISCHR(sb.st_mode)) { | ||
| 71 | errno = EINVAL; | ||
| 72 | return NULL; | ||
| 73 | } | ||
| 74 | name = devname(sb.st_rdev, S_IFCHR); | ||
| 75 | if (strncmp(name, "pty", 3) != 0) { | ||
| 76 | errno = EINVAL; | ||
| 77 | return NULL; | ||
| 78 | } | ||
| 79 | return name; | ||
| 80 | } | ||
| 81 | |||
| 82 | /* | ||
| 83 | * The PTMGET ioctl handles the mode and owner for us. | ||
| 84 | */ | ||
| 85 | int | ||
| 86 | grantpt(int mfd) | ||
| 87 | { | ||
| 88 | return ptmname(mfd) ? 0 : -1; | ||
| 89 | } | ||
| 90 | |||
| 91 | /* | ||
| 92 | * The PTMGET ioctl unlocks the pty master and slave for us. | ||
| 93 | */ | ||
| 94 | int | ||
| 95 | unlockpt(int mfd) | ||
| 96 | { | ||
| 97 | return ptmname(mfd) ? 0 : -1; | ||
| 98 | } | ||
| 99 | |||
| 100 | /* | ||
| 101 | * Look up the path of the slave pty that corresponds to the master fd. | ||
| 102 | * Returns the path if successful or NULL on error. | ||
| 103 | */ | ||
| 104 | char * | ||
| 105 | ptsname(int mfd) | ||
| 106 | { | ||
| 107 | const char *master; | ||
| 108 | static char slave[sizeof(((struct ptmget *)NULL)->sn)]; | ||
| 109 | |||
| 110 | if ((master = ptmname(mfd)) == NULL) | ||
| 111 | return NULL; | ||
| 112 | |||
| 113 | /* Add /dev/ prefix and convert "pty" to "tty". */ | ||
| 114 | strlcpy(slave, _PATH_DEV, sizeof(slave)); | ||
| 115 | strlcat(slave, master, sizeof(slave)); | ||
| 116 | slave[sizeof(_PATH_DEV) - 1] = 't'; | ||
| 117 | |||
| 118 | return slave; | ||
| 119 | } | ||
diff --git a/src/lib/libc/stdlib/ptsname.3 b/src/lib/libc/stdlib/ptsname.3 new file mode 100644 index 0000000000..3d7cd979d5 --- /dev/null +++ b/src/lib/libc/stdlib/ptsname.3 | |||
| @@ -0,0 +1,160 @@ | |||
| 1 | .\" $OpenBSD: ptsname.3,v 1.1 2012/12/03 20:08:33 millert Exp $ | ||
| 2 | .\" | ||
| 3 | .\" Copyright (c) 2002 The FreeBSD Project, Inc. | ||
| 4 | .\" All rights reserved. | ||
| 5 | .\" | ||
| 6 | .\" This software includes code contributed to the FreeBSD Project | ||
| 7 | .\" by Ryan Younce of North Carolina State University. | ||
| 8 | .\" | ||
| 9 | .\" Redistribution and use in source and binary forms, with or without | ||
| 10 | .\" modification, are permitted provided that the following conditions | ||
| 11 | .\" are met: | ||
| 12 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 13 | .\" notice, this list of conditions and the following disclaimer. | ||
| 14 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 15 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 16 | .\" documentation and/or other materials provided with the distribution. | ||
| 17 | .\" 3. Neither the name of the FreeBSD Project nor the names of its | ||
| 18 | .\" contributors may be used to endorse or promote products derived from | ||
| 19 | .\" this software without specific prior written permission. | ||
| 20 | .\" | ||
| 21 | .\" THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT AND CONTRIBUTORS | ||
| 22 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 23 | .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
| 24 | .\" PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT | ||
| 25 | .\" OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 26 | .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
| 27 | .\" TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 28 | .\" PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 29 | .\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 30 | .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 31 | .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 32 | .\" | ||
| 33 | .\" $FreeBSD: head/lib/libc/stdlib/ptsname.3 240412 2012-09-12 17:54:09Z emaste $ | ||
| 34 | .\" | ||
| 35 | .Dd $Mdocdate: December 3 2012 $ | ||
| 36 | .Dt PTSNAME 3 | ||
| 37 | .Os | ||
| 38 | .Sh NAME | ||
| 39 | .Nm grantpt , | ||
| 40 | .Nm ptsname , | ||
| 41 | .Nm unlockpt | ||
| 42 | .Nd pseudo-terminal access functions | ||
| 43 | .Sh SYNOPSIS | ||
| 44 | .In stdlib.h | ||
| 45 | .Ft int | ||
| 46 | .Fn grantpt "int fildes" | ||
| 47 | .Ft "char *" | ||
| 48 | .Fn ptsname "int fildes" | ||
| 49 | .Ft int | ||
| 50 | .Fn unlockpt "int fildes" | ||
| 51 | .Sh DESCRIPTION | ||
| 52 | The | ||
| 53 | .Fn grantpt , | ||
| 54 | .Fn ptsname , | ||
| 55 | and | ||
| 56 | .Fn unlockpt | ||
| 57 | functions allow access to pseudo-terminal devices. | ||
| 58 | These three functions accept a file descriptor that references the | ||
| 59 | master half of a pseudo-terminal pair. | ||
| 60 | This file descriptor is created with | ||
| 61 | .Xr posix_openpt 3 . | ||
| 62 | .Pp | ||
| 63 | The | ||
| 64 | .Fn grantpt | ||
| 65 | function is used to establish ownership and permissions | ||
| 66 | of the slave device counterpart to the master device | ||
| 67 | specified with | ||
| 68 | .Fa fildes . | ||
| 69 | The slave device's ownership is set to the real user ID | ||
| 70 | of the calling process, and the permissions are set to | ||
| 71 | user readable-writable and group writable. | ||
| 72 | The group owner of the slave device is also set to the | ||
| 73 | group | ||
| 74 | .Dq Li tty . | ||
| 75 | .Pp | ||
| 76 | The | ||
| 77 | .Fn ptsname | ||
| 78 | function returns the full pathname of the slave device | ||
| 79 | counterpart to the master device specified with | ||
| 80 | .Fa fildes . | ||
| 81 | This value can be used | ||
| 82 | to subsequently open the appropriate slave after | ||
| 83 | .Xr posix_openpt 3 | ||
| 84 | and | ||
| 85 | .Fn grantpt | ||
| 86 | have been called. | ||
| 87 | .Pp | ||
| 88 | The | ||
| 89 | .Fn unlockpt | ||
| 90 | function clears the lock held on the pseudo-terminal pair | ||
| 91 | for the master device specified with | ||
| 92 | .Fa fildes . | ||
| 93 | .Sh RETURN VALUES | ||
| 94 | .Rv -std grantpt unlockpt | ||
| 95 | .Pp | ||
| 96 | The | ||
| 97 | .Fn ptsname | ||
| 98 | function returns a pointer to the name | ||
| 99 | of the slave device on success; otherwise a | ||
| 100 | .Dv NULL | ||
| 101 | pointer is returned. | ||
| 102 | .Sh ERRORS | ||
| 103 | The | ||
| 104 | .Fn grantpt , | ||
| 105 | .Fn ptsname | ||
| 106 | and | ||
| 107 | .Fn unlockpt | ||
| 108 | functions may fail and set | ||
| 109 | .Va errno | ||
| 110 | to: | ||
| 111 | .Bl -tag -width Er | ||
| 112 | .It Bq Er EBADF | ||
| 113 | .Fa fildes | ||
| 114 | is not a valid open file descriptor. | ||
| 115 | .It Bq Er EINVAL | ||
| 116 | .Fa fildes | ||
| 117 | is not a master pseudo-terminal device. | ||
| 118 | .El | ||
| 119 | .Pp | ||
| 120 | In addition, the | ||
| 121 | .Fn grantpt | ||
| 122 | function may set | ||
| 123 | .Va errno | ||
| 124 | to: | ||
| 125 | .Bl -tag -width Er | ||
| 126 | .It Bq Er EACCES | ||
| 127 | The slave pseudo-terminal device could not be accessed. | ||
| 128 | .El | ||
| 129 | .Sh SEE ALSO | ||
| 130 | .Xr posix_openpt 3 , | ||
| 131 | .Xr pty 4 , | ||
| 132 | .Xr tty 4 | ||
| 133 | .Sh STANDARDS | ||
| 134 | The | ||
| 135 | .Fn ptsname | ||
| 136 | function conforms to | ||
| 137 | .St -p1003.1-2008 . | ||
| 138 | .Pp | ||
| 139 | This implementation of | ||
| 140 | .Fn grantpt | ||
| 141 | and | ||
| 142 | .Fn unlockpt | ||
| 143 | does not conform to | ||
| 144 | .St -p1003.1-2008 , | ||
| 145 | because it depends on | ||
| 146 | .Xr posix_openpt 3 | ||
| 147 | to create the pseudo-terminal device with proper permissions in place. | ||
| 148 | It only validates whether | ||
| 149 | .Fa fildes | ||
| 150 | is a valid pseudo-terminal master device. | ||
| 151 | Future revisions of the specification will likely allow this behaviour, | ||
| 152 | as stated by the Austin Group. | ||
| 153 | .Sh HISTORY | ||
| 154 | The | ||
| 155 | .Fn grantpt , | ||
| 156 | .Fn ptsname | ||
| 157 | and | ||
| 158 | .Fn unlockpt | ||
| 159 | functions appeared in | ||
| 160 | .Ox 5.3 . | ||
