diff options
author | Matt Whitlock <busybox@mattwhitlock.name> | 2015-04-25 21:32:48 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-04-25 21:32:48 +0200 |
commit | cee59053dcf47b4a3ab87f7654c1ed20620def16 (patch) | |
tree | d14818d1f81743b8849f84aa8c2fc4f01fa13e20 /libbb | |
parent | de5edadee2dca2896492f97ab3a56e389305e74d (diff) | |
download | busybox-w32-cee59053dcf47b4a3ab87f7654c1ed20620def16.tar.gz busybox-w32-cee59053dcf47b4a3ab87f7654c1ed20620def16.tar.bz2 busybox-w32-cee59053dcf47b4a3ab87f7654c1ed20620def16.zip |
Bionic lacks ttyname_r; provide a workaround
Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/platform.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libbb/platform.c b/libbb/platform.c index 8d90ca4e9..03bbb798b 100644 --- a/libbb/platform.c +++ b/libbb/platform.c | |||
@@ -194,3 +194,22 @@ ssize_t FAST_FUNC getline(char **lineptr, size_t *n, FILE *stream) | |||
194 | return len; | 194 | return len; |
195 | } | 195 | } |
196 | #endif | 196 | #endif |
197 | |||
198 | #ifndef HAVE_TTYNAME_R | ||
199 | int ttyname_r(int fd, char *buf, size_t buflen) | ||
200 | { | ||
201 | int r; | ||
202 | char path[sizeof("/proc/self/fd/%d") + sizeof(int)*3]; | ||
203 | |||
204 | if (!isatty(fd)) | ||
205 | return errno == EINVAL ? ENOTTY : errno; | ||
206 | sprintf(path, "/proc/self/fd/%d", fd); | ||
207 | r = readlink(path, buf, buflen); | ||
208 | if (r < 0) | ||
209 | return errno; | ||
210 | if (r >= buflen) | ||
211 | return ERANGE; | ||
212 | buf[r] = '\0'; | ||
213 | return 0; | ||
214 | } | ||
215 | #endif | ||