1 /* Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 #include <sys/statfs.h>
25 #include "linux_fsinfo.h"
27 /* Prototype for function that changes ownership and access permission
28 for slave pseudo terminals that do not live on a `devpts'
30 static int __unix_grantpt (int fd
);
32 /* Prototype for private function that gets the name of the slave
33 pseudo terminal in a safe way. */
34 static int pts_name (int fd
, char **pts
, size_t buf_len
);
36 /* Change the ownership and access permission of the slave pseudo
37 terminal associated with the master pseudo terminal specified
50 if (__builtin_expect (pts_name (fd
, &buf
, sizeof (_buf
)), 0))
52 int save_errno
= errno
;
54 /* Check, if the file descriptor is valid. pts_name returns the
55 wrong errno number, so we cannot use that. */
56 if (__libc_fcntl (fd
, F_GETFD
) == -1 && errno
== EBADF
)
59 /* If the filedescriptor is no TTY, grantpt has to set errno
61 if (save_errno
== ENOTTY
)
64 __set_errno (save_errno
);
69 if (__statfs (buf
, &fsbuf
) < 0)
72 /* If the slave pseudo terminal lives on a `devpts' filesystem, the
73 ownership and access permission are already set. */
74 if (fsbuf
.f_type
== DEVPTS_SUPER_MAGIC
|| fsbuf
.f_type
== DEVFS_SUPER_MAGIC
)
77 return __unix_grantpt (fd
);
80 #define grantpt static __unix_grantpt
81 #include <sysdeps/unix/grantpt.c>