| 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(symlink_path, sizeof(symlink_path), "%s_%d.symlink", argv[0], |
| 14 |
getpid()); |
| 15 |
remove(symlink_path); |
| 16 |
int res = symlink(argv[0], symlink_path); |
| 17 |
assert(!res); |
| 18 |
|
| 19 |
char readlink_path[PATH_MAX]; |
| 20 |
ssize_t res2 = readlink(symlink_path, readlink_path, sizeof(readlink_path)); |
| 21 |
assert(res2 >= 0); |
| 22 |
readlink_path[res2] = '\0'; |
| 23 |
assert(!strcmp(readlink_path, argv[0])); |
| 24 |
|
| 25 |
return 0; |
| 26 |
} |