WASI-SDK readlink() has invalid error handling
I am posting this as an advisory notice so people can find it if they search for readlink(), I don't need it fixed.
POSIX says that if readlink() is applied to an actual file, not a link, it should return -1 and set errno to EINVAL (https://pubs.opengroup.org/onlinepubs/9699919799.2016edition/functions/readlink.html). In Wasi-SDK, it returns 3 and places the 3-character string "-22" in the buf, the second parameter to readlink().
This is a minimal test program to check the invalid behavior (run touch testfile and then the test program):
#include <stdio.h>
#include <limits.h>
#include <unistd.h>
int main(void)
{
const char *pathname = "testfile";
char buf[_POSIX_PATH_MAX];
ssize_t len;
if ((len = readlink (pathname, buf, sizeof (buf) - 1)) != -1)
{
buf[len] = 0;
fprintf(stderr, "DBG -- readlink() returned %zd\n", len);
fprintf(stderr, "and put %s in return buffer\n", buf);
return 1;
} else {
printf("readlink() returned correct error\n");
return 0;
}
}
Hi Nick, IIRC, this is one of the issues that are fixed in release 1.15.1 (already released for a-Shell mini, under review for a-Shell).
Wonderful! Thank you!