[2/3] Linux: Port ttyname, ttyname_r to <fd_file_name.h>
Commit Message
---
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(-)
@@ -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>
@@ -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)
{
@@ -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))