Bionic lacks ttyname_r; provide a workaround
No binary (build failed)
—
(log yok)
| @@ -368,6 +368,7 @@ typedef unsigned smalluint; | |
| #define HAVE_DPRINTF 1 | |
| #define HAVE_MEMRCHR 1 | |
| #define HAVE_MKDTEMP 1 | |
| + | #define HAVE_TTYNAME_R 1 |
| #define HAVE_PTSNAME_R 1 | |
| #define HAVE_SETBIT 1 | |
| #define HAVE_SIGHANDLER_T 1 | |
| @@ -480,6 +481,7 @@ typedef unsigned smalluint; | |
| #if defined(ANDROID) || defined(__ANDROID__) | |
| # undef HAVE_DPRINTF | |
| + | # undef HAVE_TTYNAME_R |
| # undef HAVE_GETLINE | |
| # undef HAVE_STPCPY | |
| # undef HAVE_STRCHRNUL | |
| @@ -505,6 +507,11 @@ extern void *memrchr(const void *s, int c, size_t n) FAST_FUNC; | |
| extern char *mkdtemp(char *template) FAST_FUNC; | |
| #endif | |
| + | #ifndef HAVE_TTYNAME_R |
| + | #define ttyname_r bb_ttyname_r |
| + | extern int ttyname_r(int fd, char *buf, size_t buflen); |
| + | #endif |
| + | |
| #ifndef HAVE_SETBIT | |
| # define setbit(a, b) ((a)[(b) >> 3] |= 1 << ((b) & 7)) | |
| # define clrbit(a, b) ((a)[(b) >> 3] &= ~(1 << ((b) & 7))) | |
| @@ -194,3 +194,22 @@ ssize_t FAST_FUNC getline(char **lineptr, size_t *n, FILE *stream) | |
| return len; | |
| } | |
| #endif | |
| + | |
| + | #ifndef HAVE_TTYNAME_R |
| + | int ttyname_r(int fd, char *buf, size_t buflen) |
| + | { |
| + | int r; |
| + | char path[sizeof("/proc/self/fd/%d") + sizeof(int)*3]; |
| + | |
| + | if (!isatty(fd)) |
| + | return errno == EINVAL ? ENOTTY : errno; |
| + | sprintf(path, "/proc/self/fd/%d", fd); |
| + | r = readlink(path, buf, buflen); |
| + | if (r < 0) |
| + | return errno; |
| + | if (r >= buflen) |
| + | return ERANGE; |
| + | buf[r] = '\0'; |
| + | return 0; |
| + | } |
| + | #endif |