wrong errno value set by readlinkat()

Bruno Haible bruno@clisp.org
Tue Apr 18 10:21:43 GMT 2023


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





More information about the Cygwin mailing list