cuserid: support invocation with a null pointer argument
[musl.git] / src / unistd / readlink.c
blob32f4537f972b0fda8ed2325d9b48c2c8be8e4a45
1 #include <unistd.h>
2 #include <fcntl.h>
3 #include "syscall.h"
5 ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize)
7 char dummy[1];
8 if (!bufsize) {
9 buf = dummy;
10 bufsize = 1;
12 #ifdef SYS_readlink
13 int r = __syscall(SYS_readlink, path, buf, bufsize);
14 #else
15 int r = __syscall(SYS_readlinkat, AT_FDCWD, path, buf, bufsize);
16 #endif
17 if (buf == dummy && r > 0) r = 0;
18 return __syscall_ret(r);