mirror of git://sourceware.org/git/glibc.git
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>
This commit is contained in:
parent
330001202a
commit
0fb3dadca2
|
|
@ -26,7 +26,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <_itoa.h>
|
#include <fd_to_filename.h>
|
||||||
|
|
||||||
#include "ttyname.h"
|
#include "ttyname.h"
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ getttyname_r (char *buf, size_t buflen, const struct stat64 *mytty,
|
||||||
int
|
int
|
||||||
__ttyname_r (int fd, char *buf, size_t buflen)
|
__ttyname_r (int fd, char *buf, size_t buflen)
|
||||||
{
|
{
|
||||||
char procname[30];
|
struct fd_to_filename filename;
|
||||||
struct stat64 st, st1;
|
struct stat64 st, st1;
|
||||||
int dostat = 0;
|
int dostat = 0;
|
||||||
int doispty = 0;
|
int doispty = 0;
|
||||||
|
|
@ -122,9 +122,7 @@ __ttyname_r (int fd, char *buf, size_t buflen)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
/* We try using the /proc filesystem. */
|
/* We try using the /proc filesystem. */
|
||||||
*_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0';
|
ssize_t ret = __readlink (__fd_to_filename (fd, &filename), buf, buflen - 1);
|
||||||
|
|
||||||
ssize_t ret = __readlink (procname, buf, buflen - 1);
|
|
||||||
if (__glibc_unlikely (ret == -1 && errno == ENAMETOOLONG))
|
if (__glibc_unlikely (ret == -1 && errno == ENAMETOOLONG))
|
||||||
{
|
{
|
||||||
__set_errno (ERANGE);
|
__set_errno (ERANGE);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue