mirror of
git://sourceware.org/git/glibc.git
synced 2024-12-27 04:41:02 +08:00
9cddf9deda
2001-12-18 Jakub Jelinek <jakub@redhat.com> * sysdeps/unix/sysv/linux/sparc/sparc64/clone.S (clone): Subtract stack bias from child stack pointer before passing it to clone syscall. 2001-12-18 Ulrich Drepper <drepper@redhat.com> * sysdeps/posix/sysconf.c (__sysconf): Respect POSIX minimum for _SC_TZNAME_MAX. * sysdeps/generic/sysconf.c (__sysconf): Likewise. Reported by Thorsten Kukuk <kukuk@suse.de>. * sysdeps/unix/grantpt.c (grantpt): Correct typo in comment and add some casts. * sysdeps/unix/sysv/linux/grantpt.c: Make __unix_grantpt static. 2001-12-18 Thorsten Kukuk <kukuk@suse.de> * sysdeps/unix/sysv/linux/grantpt.c: Make errno results standard conforming: return EBADF if file descriptor is invalid and EINVAL if file descriptor is no valid tty. * login/tst-grantpt.c: New file. * login/Makefile (tests): Add tst-grantpt.
81 lines
2.4 KiB
C
81 lines
2.4 KiB
C
/* Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, write to the Free
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
02111-1307 USA. */
|
|
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <limits.h>
|
|
#include <stdlib.h>
|
|
#include <sys/statfs.h>
|
|
|
|
#include "linux_fsinfo.h"
|
|
|
|
/* Prototype for function that changes ownership and access permission
|
|
for slave pseudo terminals that do not live on a `devpts'
|
|
filesystem. */
|
|
static int __unix_grantpt (int fd);
|
|
|
|
/* Prototype for private function that gets the name of the slave
|
|
pseudo terminal in a safe way. */
|
|
static int pts_name (int fd, char **pts, size_t buf_len);
|
|
|
|
/* Change the ownership and access permission of the slave pseudo
|
|
terminal associated with the master pseudo terminal specified
|
|
by FD. */
|
|
int
|
|
grantpt (int fd)
|
|
{
|
|
struct statfs fsbuf;
|
|
#ifdef PATH_MAX
|
|
char _buf[PATH_MAX];
|
|
#else
|
|
char _buf[512];
|
|
#endif
|
|
char *buf = _buf;
|
|
|
|
if (__builtin_expect (pts_name (fd, &buf, sizeof (_buf)), 0))
|
|
{
|
|
int save_errno = errno;
|
|
|
|
/* Check, if the file descriptor is valid. pts_name returns the
|
|
wrong errno number, so we cannot use that. */
|
|
if (__libc_fcntl (fd, F_GETFD) == -1 && errno == EBADF)
|
|
return -1;
|
|
|
|
__set_errno (save_errno);
|
|
|
|
/* If the filedescriptor is no TTY, grantpt has to set errno
|
|
to EINVAL. */
|
|
if (errno == ENOTTY)
|
|
__set_errno (EINVAL);
|
|
return -1;
|
|
}
|
|
|
|
if (__statfs (buf, &fsbuf) < 0)
|
|
return -1;
|
|
|
|
/* If the slave pseudo terminal lives on a `devpts' filesystem, the
|
|
ownership and access permission are already set. */
|
|
if (fsbuf.f_type == DEVPTS_SUPER_MAGIC || fsbuf.f_type == DEVFS_SUPER_MAGIC)
|
|
return 0;
|
|
|
|
return __unix_grantpt (fd);
|
|
}
|
|
|
|
#define grantpt static __unix_grantpt
|
|
#include <sysdeps/unix/grantpt.c>
|