Update.
[glibc.git] / sysdeps / unix / sysv / linux / grantpt.c
blob0473f357b3237f06366d8bd383d763de97ee7747
1 /* Copyright (C) 1998, 1999 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <limits.h>
20 #include <stdlib.h>
21 #include <sys/statfs.h>
23 #include "linux_fsinfo.h"
25 /* Prototype for function that changes ownership and access permission
26 for slave pseudo terminals that do not live on a `devpts'
27 filesystem. */
28 int __unix_grantpt (int fd);
30 /* Prototype for private function that gets the name of the slave
31 pseudo terminal in a safe way. */
32 static int pts_name (int fd, char **pts, size_t buf_len);
34 /* Change the ownership and access permission of the slave pseudo
35 terminal associated with the master pseudo terminal specified
36 by FD. */
37 int
38 grantpt (int fd)
40 struct statfs fsbuf;
41 #ifdef PATH_MAX
42 char _buf[PATH_MAX];
43 #else
44 char _buf[512];
45 #endif
46 char *buf = _buf;
48 if (pts_name (fd, &buf, sizeof (_buf)))
49 return -1;
51 if (__statfs (buf, &fsbuf) < 0)
52 return -1;
54 /* If the slave pseudo terminal lives on a `devpts' filesystem, the
55 ownership and access permission are already set. */
56 if (fsbuf.f_type == DEVPTS_SUPER_MAGIC || fsbuf.f_type == DEVFS_SUPER_MAGIC)
57 return 0;
59 return __unix_grantpt (fd);
62 #define grantpt __unix_grantpt
63 #include <sysdeps/unix/grantpt.c>