public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* wrong errno value set by readlinkat()
@ 2023-04-18 10:21 Bruno Haible
  2023-04-18 11:56 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Haible @ 2023-04-18 10:21 UTC (permalink / raw)
  To: cygwin

Hi,

When an empty path argument is passed to the readlinkat() function,
POSIX:2018 specifies that the function fails with error ENOENT:

https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlinkat.html
"These functions shall fail if:
...
[ENOENT]
    A component of path does not name an existing file or path is an empty
    string."

In Cygwin 3.4.6, readlinkat() fails with error EBADF instead.

How to reproduce:
============================== foo.c ===================================
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main ()
{
  char buf[80];
  int ret = readlinkat (AT_FDCWD, "", buf, sizeof (buf));
  int err = errno;
  printf ("ret = %d, errno = %d = \"%s\"\n", ret, err, strerror (err));
  return 0;
}
========================================================================
$ gcc -Wall foo.c
$ ./a.exe

Expected output:
ret = -1, errno = 2 = "No such file or directory"

Actual output:
ret = -1, errno = 9 = "Bad file descriptor"


Bruno




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

end of thread, other threads:[~2023-04-18 11:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-18 10:21 wrong errno value set by readlinkat() Bruno Haible
2023-04-18 11:56 ` Corinna Vinschen

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).