From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13246 Path: news.gmane.org!.POSTED!not-for-mail From: Benjamin Peterson Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] return EBADF from ttyname_r Date: Wed, 12 Sep 2018 17:34:24 -0700 Message-ID: <20180913003424.12234-1-benjamin@python.org> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1536802148 22630 195.159.176.226 (13 Sep 2018 01:29:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 13 Sep 2018 01:29:08 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-13262-gllmg-musl=m.gmane.org@lists.openwall.com Thu Sep 13 03:29:04 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1g0GRL-0005mb-CQ for gllmg-musl@m.gmane.org; Thu, 13 Sep 2018 03:29:03 +0200 Original-Received: (qmail 21746 invoked by uid 550); 13 Sep 2018 01:31:12 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 1885 invoked from network); 13 Sep 2018 00:34:39 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=python.org; s=200901; t=1536798867; bh=jzOcQZh3V2H4MrBrlHbXA2cJPQpANke6FnXQhOj+eF8=; h=From:To:Subject:Date:From; b=cophWoQEsInZqo1kGe2RyJ4Y7O23AeTUKgglNONqHir3bi46xX96ooHBo4O/90jO4 8qLU0kLdN/yfx4Th8/WbOXaf7E7XEBdCigGkZOs0wRXS5x0wiahth6cOqesQ6gNc// qRpnV7jI4HUSLse72hFx9NA5nNu2yub7Zi9SHTFw= X-ME-Proxy: X-ME-Sender: X-Mailer: git-send-email 2.17.1 Xref: news.gmane.org gmane.linux.lib.musl.general:13246 Archived-At: POSIX allows ttyname(_r) to return EBADF if passed file descriptor is invalid. --- src/unistd/ttyname_r.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/unistd/ttyname_r.c b/src/unistd/ttyname_r.c index 33aa4ae1..e208b3c3 100644 --- a/src/unistd/ttyname_r.c +++ b/src/unistd/ttyname_r.c @@ -10,7 +10,10 @@ int ttyname_r(int fd, char *name, size_t size) char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2]; ssize_t l; - if (!isatty(fd)) return ENOTTY; + if (!isatty(fd)) { + if (errno == EBADF) return EBADF; + return ENOTTY; + } __procfdname(procname, fd); l = readlink(procname, name, size); -- 2.17.1