]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/grantpt.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / grantpt.c
CommitLineData
27fe5f2e 1/* grantpt implementation for Linux.
2b778ceb 2 Copyright (C) 1998-2021 Free Software Foundation, Inc.
27fe5f2e
FW
3 This file is part of the GNU C Library.
4 Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
139ee080 5
27fe5f2e
FW
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.
540d7568 10
27fe5f2e
FW
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.
139ee080 15
27fe5f2e
FW
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>
139ee080 24
27fe5f2e
FW
25int
26grantpt (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. */
139ee080 33
27fe5f2e
FW
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;
139ee080 41}