Blame sysdeps/unix/sysv/linux/ttyname.h

Packit 6c4009
/* Copyright (C) 2016-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public License as
Packit 6c4009
   published by the Free Software Foundation; either version 2.1 of the
Packit 6c4009
   License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; see the file COPYING.LIB.  If
Packit 6c4009
   not, see <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <stdbool.h>
Packit 6c4009
#include <sys/sysmacros.h>
Packit 6c4009
#include <sys/types.h>
Packit 6c4009
#include <sys/stat.h>
Packit 6c4009
Packit 6c4009
/* Return true if this is a UNIX98 pty device, as defined in
Packit 6c4009
   linux/Documentation/devices.txt (on linux < 4.10) or
Packit 6c4009
   linux/Documentation/admin-guide/devices.txt (on linux >= 4.10).  */
Packit 6c4009
static inline bool
Packit 6c4009
is_pty (struct stat64 *sb)
Packit 6c4009
{
Packit 6c4009
#ifdef _STATBUF_ST_RDEV
Packit 6c4009
  int m = __gnu_dev_major (sb->st_rdev);
Packit 6c4009
  return (136 <= m && m <= 143);
Packit 6c4009
#else
Packit 6c4009
  return false;
Packit 6c4009
#endif
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static inline bool
Packit 6c4009
is_mytty (const struct stat64 *mytty, const struct stat64 *maybe)
Packit 6c4009
{
Packit 6c4009
  return (maybe->st_ino == mytty->st_ino
Packit 6c4009
	  && maybe->st_dev == mytty->st_dev
Packit 6c4009
#ifdef _STATBUF_ST_RDEV
Packit 6c4009
	  && S_ISCHR (maybe->st_mode)
Packit 6c4009
	  && maybe->st_rdev == mytty->st_rdev
Packit 6c4009
#endif
Packit 6c4009
	  );
Packit 6c4009
}