int statvfs (const char *file, struct statvfs *buf) { struct statfs fsbuf; struct stat st; /* Get as much information as possible from the system. */ if (__libc_statfs (file, &fsbuf) < 0) return -1; #define STAT(st) stat (file, st) #include "internal_statvfs.c" /* We signal success if the statfs call succeeded. */ return 0; }
/* 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; char _buf[PATH_MAX]; char *buf = _buf; if (pts_name (fd, &buf, sizeof (_buf))) return -1; if (__libc_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 __unix_grantpt (fd); return 0; }
/* Open a master pseudo terminal and return its file descriptor. */ int posix_openpt (int flags) { #define have_no_dev_ptmx (1<<0) #define devpts_mounted (1<<1) #if !defined __UNIX98PTY_ONLY__ static smallint _state; #endif int fd; #if !defined __UNIX98PTY_ONLY__ if (!(_state & have_no_dev_ptmx)) #endif { fd = open (_PATH_DEVPTMX, flags); if (fd != -1) { #if defined __ASSUME_DEVPTS__ return fd; #else struct statfs fsbuf; /* Check that the /dev/pts filesystem is mounted or if /dev is a devfs filesystem (this implies /dev/pts). */ if ( #if !defined __UNIX98PTY_ONLY__ (_state & devpts_mounted) || #endif (__libc_statfs (_PATH_DEVPTS, &fsbuf) == 0 && fsbuf.f_type == DEVPTS_SUPER_MAGIC) || (__libc_statfs (_PATH_DEV, &fsbuf) == 0 && fsbuf.f_type == DEVFS_SUPER_MAGIC)) { /* Everything is ok. */ #if !defined __UNIX98PTY_ONLY__ _state |= devpts_mounted; #endif return fd; } /* If /dev/pts is not mounted then the UNIX98 pseudo terminals are not usable. */ close (fd); #if !defined __UNIX98PTY_ONLY__ _state |= have_no_dev_ptmx; #endif #endif } else { #if !defined __UNIX98PTY_ONLY__ if (errno == ENOENT || errno == ENODEV) _state |= have_no_dev_ptmx; else #endif return -1; } } #if !defined __UNIX98PTY_ONLY__ && defined __UCLIBC_HAS_GETPT__ /* If we have no ptmx then ignore flags and use the fallback. */ if (_state & have_no_dev_ptmx) return __bsd_getpt(); #endif return -1; }