From a60a4501b77dca8f30e01327b96171ee89c278f7 Mon Sep 17 00:00:00 2001 From: Ken Brown Date: Wed, 20 Jan 2021 12:01:13 -0500 Subject: [PATCH] Cygwin: ptsname_r: always return an error number on failure Return EBADF on a bad file descriptor. Previously 0 was returned, in violation of the requirement in https://man7.org/linux/man-pages/man3/ptsname_r.3.html that an error number should be returned on failure. We are intentionally deviating from Linux, on which ENOTTY is returned. Addresses: https://lists.gnu.org/archive/html/bug-gnulib/2021-01/msg00245.html --- winsup/cygwin/release/3.2.0 | 3 +++ winsup/cygwin/syscalls.cc | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/release/3.2.0 b/winsup/cygwin/release/3.2.0 index 43725cec2..f748a9bc8 100644 --- a/winsup/cygwin/release/3.2.0 +++ b/winsup/cygwin/release/3.2.0 @@ -52,3 +52,6 @@ Bug Fixes - Fix the errno when a path contains .. and the prefix exists but is not a directory. Addresses: https://lists.gnu.org/archive/html/bug-gnulib/2021-01/msg00214.html + +- Fix the return value when ptsname_r(3) is called with a bad file descriptor + Addresses: https://lists.gnu.org/archive/html/bug-gnulib/2021-01/msg00245.html diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 7044ea903..c985142eb 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -3392,7 +3392,7 @@ ptsname_r (int fd, char *buf, size_t buflen) cygheap_fdget cfd (fd); if (cfd < 0) - return 0; + return EBADF; return cfd->ptsname_r (buf, buflen); }