]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/grantpt.c
43122f9a76a86ff299b390fb54bac6f7669cf160
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / grantpt.c
1 /* grantpt implementation for Linux.
2 Copyright (C) 1998-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20 #include <errno.h>
21 #include <stdlib.h>
22 #include <sys/ioctl.h>
23 #include <termios.h>
24
25 int
26 grantpt (int fd)
27 {
28 /* Without pt_chown on Linux, we have delegated the creation of the
29 pty node with the right group and permission mode to the kernel, and
30 non-root users are unlikely to be able to change it. Therefore let's
31 consider that POSIX enforcement is the responsibility of the whole
32 system and not only the GNU libc. */
33
34 /* Verify that fd refers to a ptmx descriptor. */
35 unsigned int ptyno;
36 int ret = __ioctl (fd, TIOCGPTN, &ptyno);
37 if (ret != 0 && errno == ENOTTY)
38 /* POSIX requires EINVAL instead of ENOTTY provided by the kernel. */
39 __set_errno (EINVAL);
40 return ret;
41 }