1// RUN: %clang -O0 %s -o %t && %run %t
2
3// XFAIL: i386-netbsd && asan
4
5#include <assert.h>
6#include <fcntl.h>
7#include <limits.h>
8#include <stdio.h>
9#include <string.h>
10#include <unistd.h>
11
12int main(int argc, char **argv) {
13 char symlink_path[PATH_MAX];
14 snprintf(s: symlink_path, maxlen: sizeof(symlink_path), format: "%s_%d.symlink", argv[0],
15 getpid());
16 remove(filename: symlink_path);
17 int res = symlink(from: argv[0], to: symlink_path);
18 assert(!res);
19
20 char readlinkat_path[PATH_MAX];
21 int res2 = readlinkat(AT_FDCWD, path: symlink_path, buf: readlinkat_path,
22 len: sizeof(readlinkat_path));
23 assert(res2 >= 0);
24 readlinkat_path[res2] = '\0';
25 assert(!strcmp(readlinkat_path, argv[0]));
26
27 return 0;
28}
29

source code of compiler-rt/test/sanitizer_common/TestCases/Posix/readlinkat.c