public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] linux: use fd_to_filename instead of _fitoa_word in ttyname_r.
@ 2021-05-07 17:21 Adhemerval Zanella
  0 siblings, 0 replies; only message in thread
From: Adhemerval Zanella @ 2021-05-07 17:21 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0fb3dadca2548df348904d083b4d911fa25503f5

commit 0fb3dadca2548df348904d083b4d911fa25503f5
Author: Érico Nogueira <ericonr@disroot.org>
Date:   Mon May 3 22:51:51 2021 -0300

    linux: use fd_to_filename instead of _fitoa_word in ttyname_r.
    
    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.
    
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

Diff:
---
 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);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-07 17:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 17:21 [glibc] linux: use fd_to_filename instead of _fitoa_word in ttyname_r Adhemerval Zanella

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).