1 #include <assert.h> 2 #include <stdio.h> 3 #include <string.h> 4 #include <unistd.h> 5 main()6int main() { 7 const char* target = "./input.txt"; 8 const char* linkpath = "/sandbox/subdir/test_link"; 9 char readlink_result[128]; 10 size_t result_size = sizeof(readlink_result); 11 12 assert(0 == symlink(target, linkpath)); 13 assert(readlink(linkpath, readlink_result, result_size) == 14 strlen(target) + 1); 15 assert(0 == strcmp(readlink_result, target)); 16 17 FILE* file = fopen(linkpath, "r"); 18 assert(file != NULL); 19 20 int c = fgetc(file); 21 while (c != EOF) { 22 int wrote = fputc(c, stdout); 23 assert(wrote != EOF); 24 c = fgetc(file); 25 } 26 } 27