[PATCH 1/2] Bionic lacks ttyname_r; provide a workaround

Tanguy Pruvot tanguy.pruvot at gmail.com
Sat Apr 25 11:19:46 UTC 2015


Not really a syscall... Could be put elsewhere no ? Like in libbb
Le 25 avr. 2015 12:49 AM, "Matt Whitlock" <busybox at mattwhitlock.name> a
écrit :

> ---
>  include/platform.h       |  7 +++++++
>  libbb/missing_syscalls.c | 17 +++++++++++++++++
>  2 files changed, 24 insertions(+)
>
> diff --git a/include/platform.h b/include/platform.h
> index 8914d4a..8896a6b 100644
> --- a/include/platform.h
> +++ b/include/platform.h
> @@ -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_MEMPCPY
> @@ -506,6 +508,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)))
> diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
> index dd430e3..c768f11 100644
> --- a/libbb/missing_syscalls.c
> +++ b/libbb/missing_syscalls.c
> @@ -40,3 +40,20 @@ int pivot_root(const char *new_root, const char
> *put_old)
>         return syscall(__NR_pivot_root, new_root, put_old);
>  }
>  #endif
> +
> +#ifndef HAVE_TTYNAME_R
> +int ttyname_r(int fd, char *buf, size_t buflen)
> +{
> +       int r;
> +       char path[32];
> +       if (!isatty(fd))
> +               return errno == EINVAL ? ENOTTY : errno;
> +       sprintf(path, "/proc/self/fd/%d", fd);
> +       if ((r = readlink(path, buf, buflen)) < 0)
> +               return errno;
> +       if (r >= buflen)
> +               return ERANGE;
> +       buf[r] = '\0';
> +       return 0;
> +}
> +#endif
> --
> 2.0.5
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20150425/f7dc4520/attachment-0001.html>


More information about the busybox mailing list