1 /* Determine name of the slave side of a pseudo-terminal.
2 Copyright (C) 1998, 2002, 2010-2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
30 # define _PATH_TTY "/dev/tty"
33 # define _PATH_DEV "/dev/"
36 # define __set_errno(e) errno = (e)
37 # define __isatty isatty
39 # define __ttyname_r ttyname_r
40 # define __ptsname_r ptsname_r
45 /* Store at most BUFLEN characters of the pathname of the slave pseudo
46 terminal associated with the master FD is open on in BUF.
47 Return 0 on success, otherwise an error number. */
49 __ptsname_r (int fd, char *buf, size_t buflen)
51 int save_errno = errno;
62 /* We rely on isatty to set errno properly (i.e. EBADF or ENOTTY). */
65 if (buflen < strlen (_PATH_TTY) + 3)
71 err = __ttyname_r (fd, buf, buflen);
78 buf[sizeof (_PATH_DEV) - 1] = 't';
80 if (__stat (buf, &st) < 0)
83 __set_errno (save_errno);