linux fails with EINVAL when a zero buffer size is passed to the syscall. this is non-conforming because POSIX already defines EINVAL with a significantly different meaning: the target is not a symlink. since the request is semantically valid, patch it up by using a dummy buffer of length one, and truncating the return value to zero if it succeeds.
15 lines
323 B
C
15 lines
323 B
C
#include <unistd.h>
|
|
#include "syscall.h"
|
|
|
|
ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize)
|
|
{
|
|
char dummy[1];
|
|
if (!bufsize) {
|
|
buf = dummy;
|
|
bufsize = 1;
|
|
}
|
|
int r = __syscall(SYS_readlinkat, fd, path, buf, bufsize);
|
|
if (buf == dummy && r > 0) r = 0;
|
|
return __syscall_ret(r);
|
|
}
|