Mercurial > gnulib
annotate lib/ptsname_r.c @ 40140:81f075eaa990
ptsname_r: Work around bug on Android 4.3.
* m4/ptsname_r.m4 (gl_FUNC_PTSNAME_R): Define
HAVE_ESSENTIALLY_WORKING_PTSNAME_R. Test whether the return value is
correct.
* lib/ptsname_r.c (__ptsname_r): If HAVE_ESSENTIALLY_WORKING_PTSNAME_R
is defined, just fix the return value.
* doc/glibc-functions/ptsname_r.texi: Mention the Android bug. Reword:
The behaviour of musl libc is nothing to be "fixed", since it is
compliant with the next POSIX standard.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 26 Jan 2019 15:23:19 +0100 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
16067 | 1 /* Determine name of the slave side of a pseudo-terminal. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 1998, 2002, 2010-2019 Free Software Foundation, Inc. |
16067 | 3 |
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. | |
8 | |
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. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
16067 | 16 |
17 #include <config.h> | |
18 | |
19 #include <stdlib.h> | |
20 | |
21 #include <errno.h> | |
16940
f0c9b2dc0596
ptsname_r: Fix test failures on IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
22 #include <fcntl.h> |
16067 | 23 #include <string.h> |
24 #include <sys/stat.h> | |
25 #include <unistd.h> | |
26 | |
27 #ifdef _LIBC | |
28 # include <paths.h> | |
29 #else | |
30 # ifndef _PATH_TTY | |
31 # define _PATH_TTY "/dev/tty" | |
32 # endif | |
33 # ifndef _PATH_DEV | |
34 # define _PATH_DEV "/dev/" | |
35 # endif | |
36 | |
18372
d9961cf477d9
maint: preprocessor changes to support z/OS
Daniel Richard G <skunk@iSKUNK.ORG>
parents:
18189
diff
changeset
|
37 # undef __set_errno |
d9961cf477d9
maint: preprocessor changes to support z/OS
Daniel Richard G <skunk@iSKUNK.ORG>
parents:
18189
diff
changeset
|
38 # undef __stat |
d9961cf477d9
maint: preprocessor changes to support z/OS
Daniel Richard G <skunk@iSKUNK.ORG>
parents:
18189
diff
changeset
|
39 # undef __ttyname_r |
d9961cf477d9
maint: preprocessor changes to support z/OS
Daniel Richard G <skunk@iSKUNK.ORG>
parents:
18189
diff
changeset
|
40 # undef __ptsname_r |
d9961cf477d9
maint: preprocessor changes to support z/OS
Daniel Richard G <skunk@iSKUNK.ORG>
parents:
18189
diff
changeset
|
41 |
16067 | 42 # define __set_errno(e) errno = (e) |
43 # define __isatty isatty | |
44 # define __stat stat | |
45 # define __ttyname_r ttyname_r | |
46 # define __ptsname_r ptsname_r | |
47 | |
48 #endif | |
49 | |
18532
93a8694eca79
ptsname_r: leverage AC_HEADER_MAJOR
Mike Frysinger <vapier@gentoo.org>
parents:
18372
diff
changeset
|
50 /* Get the major, minor macros. */ |
93a8694eca79
ptsname_r: leverage AC_HEADER_MAJOR
Mike Frysinger <vapier@gentoo.org>
parents:
18372
diff
changeset
|
51 #if MAJOR_IN_MKDEV |
93a8694eca79
ptsname_r: leverage AC_HEADER_MAJOR
Mike Frysinger <vapier@gentoo.org>
parents:
18372
diff
changeset
|
52 # include <sys/mkdev.h> |
93a8694eca79
ptsname_r: leverage AC_HEADER_MAJOR
Mike Frysinger <vapier@gentoo.org>
parents:
18372
diff
changeset
|
53 #endif |
93a8694eca79
ptsname_r: leverage AC_HEADER_MAJOR
Mike Frysinger <vapier@gentoo.org>
parents:
18372
diff
changeset
|
54 #if MAJOR_IN_SYSMACROS |
93a8694eca79
ptsname_r: leverage AC_HEADER_MAJOR
Mike Frysinger <vapier@gentoo.org>
parents:
18372
diff
changeset
|
55 # include <sys/sysmacros.h> |
93a8694eca79
ptsname_r: leverage AC_HEADER_MAJOR
Mike Frysinger <vapier@gentoo.org>
parents:
18372
diff
changeset
|
56 #endif |
93a8694eca79
ptsname_r: leverage AC_HEADER_MAJOR
Mike Frysinger <vapier@gentoo.org>
parents:
18372
diff
changeset
|
57 |
16942
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
58 #ifdef __sun |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
59 /* Get ioctl() and 'struct strioctl'. */ |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
60 # include <stropts.h> |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
61 /* Get ISPTM. */ |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
62 # include <sys/stream.h> |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
63 # include <sys/ptms.h> |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
64 # include <stdio.h> |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
65 #endif |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
66 |
16945
af6492941f0d
ptsname_r: Make it consistent with ptsname on AIX.
Bruno Haible <bruno@clisp.org>
parents:
16944
diff
changeset
|
67 #if defined _AIX || defined __osf__ |
16944
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
68 /* Get ioctl(), ISPTM. */ |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
69 # include <sys/ioctl.h> |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
70 # include <stdio.h> |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
71 #endif |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
72 |
16067 | 73 |
74 /* Store at most BUFLEN characters of the pathname of the slave pseudo | |
75 terminal associated with the master FD is open on in BUF. | |
76 Return 0 on success, otherwise an error number. */ | |
77 int | |
78 __ptsname_r (int fd, char *buf, size_t buflen) | |
40140
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
79 #undef ptsname_r |
16067 | 80 { |
40140
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
81 #if HAVE_ESSENTIALLY_WORKING_PTSNAME_R |
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
82 int ret = ptsname_r (fd, buf, buflen); |
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
83 if (ret == 0) |
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
84 return 0; |
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
85 else |
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
86 return errno; |
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
87 #else |
16067 | 88 int save_errno = errno; |
89 int err; | |
90 struct stat st; | |
91 | |
92 if (buf == NULL) | |
93 { | |
94 __set_errno (EINVAL); | |
95 return EINVAL; | |
96 } | |
97 | |
40140
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
98 # if defined __sun /* Solaris */ |
16942
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
99 if (fstat (fd, &st) < 0) |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
100 return errno; |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
101 if (!(S_ISCHR (st.st_mode) && major (st.st_rdev) == 0)) |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
102 { |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
103 errno = ENOTTY; |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
104 return errno; |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
105 } |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
106 { |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
107 /* Master ptys can be recognized through a STREAMS ioctl. See |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
108 "STREAMS-based Pseudo-Terminal Subsystem" |
19192
d86e08b1f555
all: Replace many more http URLs by https URLs. Update stale URLs.
Bruno Haible <bruno@clisp.org>
parents:
19190
diff
changeset
|
109 <https://docs.oracle.com/cd/E18752_01/html/816-4855/termsub15-44781.html> |
16942
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
110 and "STREAMS ioctl commands" |
19192
d86e08b1f555
all: Replace many more http URLs by https URLs. Update stale URLs.
Bruno Haible <bruno@clisp.org>
parents:
19190
diff
changeset
|
111 <https://docs.oracle.com/cd/E18752_01/html/816-5177/streamio-7i.html> |
16942
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
112 */ |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
113 struct strioctl ioctl_arg; |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
114 ioctl_arg.ic_cmd = ISPTM; |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
115 ioctl_arg.ic_timout = 0; |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
116 ioctl_arg.ic_len = 0; |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
117 ioctl_arg.ic_dp = NULL; |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
118 |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
119 if (ioctl (fd, I_STR, &ioctl_arg) < 0) |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
120 { |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
121 errno = ENOTTY; |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
122 return errno; |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
123 } |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
124 } |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
125 { |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
126 char tmpbuf[9 + 10 + 1]; |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
127 int n = sprintf (tmpbuf, "/dev/pts/%u", minor (st.st_rdev)); |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
128 if (n >= buflen) |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
129 { |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
130 errno = ERANGE; |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
131 return errno; |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
132 } |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
133 memcpy (buf, tmpbuf, n + 1); |
17843e284264
ptsname_r: Add support for Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16940
diff
changeset
|
134 } |
40140
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
135 # elif defined _AIX || defined __osf__ /* AIX, OSF/1 */ |
16944
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
136 /* This implementation returns /dev/pts/N, like ptsname() does. |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
137 Whereas the generic implementation below returns /dev/ttypN. |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
138 Both are correct, but let's be consistent with ptsname(). */ |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
139 if (fstat (fd, &st) < 0) |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
140 return errno; |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
141 if (!S_ISCHR (st.st_mode)) |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
142 { |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
143 errno = ENOTTY; |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
144 return errno; |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
145 } |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
146 { |
16945
af6492941f0d
ptsname_r: Make it consistent with ptsname on AIX.
Bruno Haible <bruno@clisp.org>
parents:
16944
diff
changeset
|
147 int ret; |
16944
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
148 int dev; |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
149 char tmpbuf[9 + 10 + 1]; |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
150 int n; |
40140
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
151 # ifdef _AIX |
16945
af6492941f0d
ptsname_r: Make it consistent with ptsname on AIX.
Bruno Haible <bruno@clisp.org>
parents:
16944
diff
changeset
|
152 ret = ioctl (fd, ISPTM, &dev); |
40140
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
153 # endif |
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
154 # ifdef __osf__ |
16945
af6492941f0d
ptsname_r: Make it consistent with ptsname on AIX.
Bruno Haible <bruno@clisp.org>
parents:
16944
diff
changeset
|
155 ret = ioctl (fd, ISPTM, NULL); |
af6492941f0d
ptsname_r: Make it consistent with ptsname on AIX.
Bruno Haible <bruno@clisp.org>
parents:
16944
diff
changeset
|
156 dev = ret; |
40140
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
157 # endif |
16946
f34e11adfc84
ptsname_r: Fix typo in last commit.
Bruno Haible <bruno@clisp.org>
parents:
16945
diff
changeset
|
158 if (ret < 0) |
16944
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
159 { |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
160 errno = ENOTTY; |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
161 return errno; |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
162 } |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
163 n = sprintf (tmpbuf, "/dev/pts/%u", minor (dev)); |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
164 if (n >= buflen) |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
165 { |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
166 errno = ERANGE; |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
167 return errno; |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
168 } |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
169 memcpy (buf, tmpbuf, n + 1); |
00ae3faf06c6
ptsname_r: Make it consistent with ptsname on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
16942
diff
changeset
|
170 } |
40140
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
171 # else |
16067 | 172 if (!__isatty (fd)) |
16940
f0c9b2dc0596
ptsname_r: Fix test failures on IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
173 { |
40140
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
174 # if ISATTY_FAILS_WITHOUT_SETTING_ERRNO && defined F_GETFL /* IRIX, Solaris */ |
16940
f0c9b2dc0596
ptsname_r: Fix test failures on IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
175 /* Set errno. */ |
f0c9b2dc0596
ptsname_r: Fix test failures on IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
176 if (fcntl (fd, F_GETFL) != -1) |
f0c9b2dc0596
ptsname_r: Fix test failures on IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
177 errno = ENOTTY; |
40140
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
178 # else |
16940
f0c9b2dc0596
ptsname_r: Fix test failures on IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
179 /* We rely on isatty to set errno properly (i.e. EBADF or ENOTTY). */ |
40140
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
180 # endif |
16940
f0c9b2dc0596
ptsname_r: Fix test failures on IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
181 return errno; |
f0c9b2dc0596
ptsname_r: Fix test failures on IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
182 } |
16067 | 183 |
184 if (buflen < strlen (_PATH_TTY) + 3) | |
185 { | |
186 __set_errno (ERANGE); | |
187 return ERANGE; | |
188 } | |
189 | |
190 err = __ttyname_r (fd, buf, buflen); | |
191 if (err != 0) | |
192 { | |
193 __set_errno (err); | |
194 return errno; | |
195 } | |
196 | |
17125
99a0d94bccb1
ptsname_r: support ptys returned by FreeBSD posix_openpt
Eric Blake <eblake@redhat.com>
parents:
16946
diff
changeset
|
197 if (strncmp(buf, "/dev/pts/", strlen("/dev/pts/")) != 0) |
99a0d94bccb1
ptsname_r: support ptys returned by FreeBSD posix_openpt
Eric Blake <eblake@redhat.com>
parents:
16946
diff
changeset
|
198 buf[sizeof (_PATH_DEV) - 1] = 't'; |
40140
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
199 # endif |
16067 | 200 |
201 if (__stat (buf, &st) < 0) | |
202 return errno; | |
203 | |
204 __set_errno (save_errno); | |
205 return 0; | |
40140
81f075eaa990
ptsname_r: Work around bug on Android 4.3.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
206 #endif |
16067 | 207 } |