public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: Re: [PATCH 2/3] linux: use fd_to_filename instead of _fitoa_word in ttyname_r.
Date: Tue, 4 May 2021 10:18:55 -0300	[thread overview]
Message-ID: <a26bb08a-0f37-dfc7-8cb8-b98fcb9b5813@linaro.org> (raw)
In-Reply-To: <20210504015152.31064-2-ericonr@disroot.org>



On 03/05/2021 22:51, Érico Nogueira via Libc-alpha wrote:
> Simplifies the logic and makes intent clearer, while at the same time
> decreasing binary size.
> 
> On x86_64, dropped from 1883270 to 1883206, a 64 byte decrease.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/unix/sysv/linux/ttyname_r.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c
> index c1092d1695..fa1578fb64 100644
> --- a/sysdeps/unix/sysv/linux/ttyname_r.c
> +++ b/sysdeps/unix/sysv/linux/ttyname_r.c
> @@ -26,7 +26,7 @@
>  #include <string.h>
>  #include <stdlib.h>
>  
> -#include <_itoa.h>
> +#include <fd_to_filename.h>
>  
>  #include "ttyname.h"
>  
> @@ -92,7 +92,7 @@ getttyname_r (char *buf, size_t buflen, const struct stat64 *mytty,
>  int
>  __ttyname_r (int fd, char *buf, size_t buflen)
>  {
> -  char procname[30];
> +  struct fd_to_filename filename;
>    struct stat64 st, st1;
>    int dostat = 0;
>    int doispty = 0;
> @@ -122,9 +122,7 @@ __ttyname_r (int fd, char *buf, size_t buflen)
>      return errno;
>  
>    /* We try using the /proc filesystem.  */
> -  *_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0';
> -
> -  ssize_t ret = __readlink (procname, buf, buflen - 1);
> +  ssize_t ret = __readlink (__fd_to_filename (fd, &filename), buf, buflen - 1);
>    if (__glibc_unlikely (ret == -1 && errno == ENAMETOOLONG))
>      {
>        __set_errno (ERANGE);
> 

  reply	other threads:[~2021-05-04 13:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04  1:51 [PATCH 1/3] misc: use _fitoa_word to implement __fd_to_filename Érico Nogueira
2021-05-04  1:51 ` [PATCH 2/3] linux: use fd_to_filename instead of _fitoa_word in ttyname_r Érico Nogueira
2021-05-04 13:18   ` Adhemerval Zanella [this message]
2021-05-04  1:51 ` [PATCH 3/3] linux: implement ttyname as a wrapper around ttyname_r Érico Nogueira
2021-05-04 16:37   ` Adhemerval Zanella
2021-05-04 16:43     ` Adhemerval Zanella
2021-05-07 17:21       ` Adhemerval Zanella
2021-05-07 19:20         ` Érico Nogueira
2021-05-04 13:18 ` [PATCH 1/3] misc: use _fitoa_word to implement __fd_to_filename Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a26bb08a-0f37-dfc7-8cb8-b98fcb9b5813@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).