From patchwork Tue May 4 01:51:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C3=89rico_Nogueira?= X-Patchwork-Id: 43247 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 429343945C37; Tue, 4 May 2021 01:52:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 429343945C37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1620093139; bh=13YsQTrLLu58Qf87E0yJ+ShKlpU6VBfwuTGRezKIDMo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=l+e6BJiM/VeIuakL/uj5iYtnHctavCiWZpBYmJy2v5cZbJDQay582/AHrD3Sh7AMM L7rQNinG62Ckzs22BVpofxi/SfNxjv7GYfEMORFPnp5GO2Rw9aNxzdYHvU3jEkjGor fLwa7vePIilyuPFMGCzaBeOY8Ahw/ja6u97jwwBA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from knopi.disroot.org (knopi.disroot.org [178.21.23.139]) by sourceware.org (Postfix) with ESMTPS id 112BE393BC29 for ; Tue, 4 May 2021 01:52:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 112BE393BC29 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 911F953AD9; Tue, 4 May 2021 03:52:11 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Zu1Bii5uoKaA; Tue, 4 May 2021 03:52:10 +0200 (CEST) To: libc-alpha@sourceware.org Subject: [PATCH 2/3] linux: use fd_to_filename instead of _fitoa_word in ttyname_r. Date: Mon, 3 May 2021 22:51:51 -0300 Message-Id: <20210504015152.31064-2-ericonr@disroot.org> In-Reply-To: <20210504015152.31064-1-ericonr@disroot.org> References: <20210504015152.31064-1-ericonr@disroot.org> Mime-Version: 1.0 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, UNWANTED_LANGUAGE_BODY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?=C3=89rico_Nogueira_via_Libc-alpha?= From: =?utf-8?q?=C3=89rico_Nogueira?= Reply-To: =?utf-8?q?=C3=89rico_Nogueira?= Cc: =?utf-8?q?=C3=89rico_Nogueira?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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 --- 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 #include -#include <_itoa.h> +#include #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);