public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Ken Brown <kbrown@cornell.edu>
To: cygwin-patches@cygwin.com
Subject: Re: [PATCH] Cygwin: ptsname_r: always return an error number on failure
Date: Thu, 21 Jan 2021 17:48:54 -0500	[thread overview]
Message-ID: <b7ae5752-cfce-0be8-92b5-81515d5a57d0@cornell.edu> (raw)
In-Reply-To: <20210120180003.1458-1-kbrown@cornell.edu>

On 1/20/2021 1:00 PM, Ken Brown via Cygwin-patches wrote:
> Following Linux, return ENOTTY on a bad file descriptor and also set
> errno to ENOTTY.
> 
> Previously 0 was returned and errno was set to EBADF.  Returning 0
> violates the requirement in
> https://man7.org/linux/man-pages/man3/ptsname_r.3.html that an error
> number should be returned on failure.  (That man page doesn't specify
> setting errno.)
> 
> Addresses: https://lists.gnu.org/archive/html/bug-gnulib/2021-01/msg00245.html
> ---
>   winsup/cygwin/release/3.2.0 | 3 +++
>   winsup/cygwin/syscalls.cc   | 5 ++++-
>   2 files changed, 7 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 4742c6653..18d9e3f88 100644
> --- a/winsup/cygwin/syscalls.cc
> +++ b/winsup/cygwin/syscalls.cc
> @@ -3364,7 +3364,10 @@ ptsname_r (int fd, char *buf, size_t buflen)
>   
>     cygheap_fdget cfd (fd);
>     if (cfd < 0)
> -    return 0;
> +    {
> +      set_errno (ENOTTY);
> +      return ENOTTY;
> +    }
>     return cfd->ptsname_r (buf, buflen);
>   }
>   
> 

I'm not really convinced we should blindly follow Linux here, when EBADF would 
seem to make more sense.  See

   https://lists.gnu.org/archive/html/bug-gnulib/2021-01/msg00264.html

Corinna, what's your preference?

Ken

  reply	other threads:[~2021-01-21 22:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20 18:00 Ken Brown
2021-01-21 22:48 ` Ken Brown [this message]
2021-01-22  9:44   ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b7ae5752-cfce-0be8-92b5-81515d5a57d0@cornell.edu \
    --to=kbrown@cornell.edu \
    --cc=cygwin-patches@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).