unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Subject: [PATCH 2/3] Linux: Port ttyname, ttyname_r to <fd_file_name.h>
Date: Fri, 14 Feb 2020 19:11:15 +0100	[thread overview]
Message-ID: <dfe5df934af6d37ca92c8d324bb39413b0b8174e.1581703185.git.fweimer@redhat.com> (raw)
In-Reply-To: <cover.1581703185.git.fweimer@redhat.com>

---
 misc/tst-fd_to_filename.c           | 1 +
 sysdeps/unix/sysv/linux/ttyname.c   | 7 +++----
 sysdeps/unix/sysv/linux/ttyname_r.c | 7 +++----
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/misc/tst-fd_to_filename.c b/misc/tst-fd_to_filename.c
index 480f613dcf..eb08dd7e25 100644
--- a/misc/tst-fd_to_filename.c
+++ b/misc/tst-fd_to_filename.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <fcntl.h>
 #include <fd_to_filename.h>
 #include <stdio.h>
 #include <support/check.h>
diff --git a/sysdeps/unix/sysv/linux/ttyname.c b/sysdeps/unix/sysv/linux/ttyname.c
index c05ca687f5..6034e132b0 100644
--- a/sysdeps/unix/sysv/linux/ttyname.c
+++ b/sysdeps/unix/sysv/linux/ttyname.c
@@ -25,8 +25,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
-
-#include <_itoa.h>
+#include <fd_to_filename.h>
 
 #include "ttyname.h"
 
@@ -112,7 +111,6 @@ char *
 ttyname (int fd)
 {
   static size_t buflen;
-  char procname[30];
   struct stat64 st, st1;
   int dostat = 0;
   int doispty = 0;
@@ -129,7 +127,8 @@ ttyname (int fd)
     return NULL;
 
   /* We try using the /proc filesystem.  */
-  *_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0';
+  struct fd_to_filename procname_storage;
+  char *procname = __fd_to_filename (fd, &procname_storage);
 
   if (buflen == 0)
     {
diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c
index 4a1ae40bb2..e16761b43d 100644
--- a/sysdeps/unix/sysv/linux/ttyname_r.c
+++ b/sysdeps/unix/sysv/linux/ttyname_r.c
@@ -25,8 +25,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
-
-#include <_itoa.h>
+#include <fd_to_filename.h>
 
 #include "ttyname.h"
 
@@ -92,7 +91,6 @@ 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 stat64 st, st1;
   int dostat = 0;
   int doispty = 0;
@@ -122,7 +120,8 @@ __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';
+  struct fd_to_filename procname_storage;
+  char *procname = __fd_to_filename (fd, &procname_storage);
 
   ssize_t ret = __readlink (procname, buf, buflen - 1);
   if (__glibc_unlikely (ret == -1 && errno == ENAMETOOLONG))
-- 
2.24.1



  parent reply	other threads:[~2020-02-14 18:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-14 18:10 [PATCH 0/3] <fd_to_filename.h> improvements Florian Weimer
2020-02-14 18:11 ` [PATCH 1/3] <fd_to_filename.h>: Add type safety and port to Hurd Florian Weimer
2020-02-14 18:43   ` Samuel Thibault
2020-02-14 19:08   ` Adhemerval Zanella
2020-02-14 20:21     ` Florian Weimer
2020-02-14 20:28   ` Paul Eggert
2020-02-15 13:16     ` Florian Weimer
2020-02-16  0:02       ` Paul Eggert
2020-02-17 15:18         ` Florian Weimer
2020-02-17 18:26           ` Paul Eggert
2020-02-17 18:59             ` Adhemerval Zanella
2020-02-17 19:14               ` Paul Eggert
2020-02-14 18:11 ` Florian Weimer [this message]
2020-02-14 18:11 ` [PATCH 3/3] Linux: Port fexecve to <fd_to_filename.h> Florian Weimer

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

  List information: https://www.gnu.org/software/libc/involved.html

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

  git send-email \
    --in-reply-to=dfe5df934af6d37ca92c8d324bb39413b0b8174e.1581703185.git.fweimer@redhat.com \
    --to=fweimer@redhat.com \
    --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).