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
main(int argc,char ** argv)12 int main(int argc, char **argv) {
13 char symlink_path[PATH_MAX];
14 snprintf(symlink_path, sizeof(symlink_path), "%s_%d.symlink", argv[0],
15 getpid());
16 remove(symlink_path);
17 int res = symlink(argv[0], symlink_path);
18 assert(!res);
19
20 char readlinkat_path[PATH_MAX];
21 int res2 = readlinkat(AT_FDCWD, symlink_path, readlinkat_path,
22 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