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