mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] return EBADF from ttyname_r
@ 2018-09-13  0:34 Benjamin Peterson
  2018-09-13  2:07 ` Rich Felker
  2018-09-13  8:53 ` Szabolcs Nagy
  0 siblings, 2 replies; 7+ messages in thread
From: Benjamin Peterson @ 2018-09-13  0:34 UTC (permalink / raw)
  To: musl

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



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-09-13 16:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-13  0:34 [PATCH] return EBADF from ttyname_r Benjamin Peterson
2018-09-13  2:07 ` Rich Felker
2018-09-13  3:23   ` A. Wilcox
2018-09-13  3:26     ` Rich Felker
2018-09-13  8:53 ` Szabolcs Nagy
2018-09-13 15:29   ` Rich Felker
2018-09-13 16:25     ` Benjamin Peterson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).