1 #include "config_ast.h" // IWYU pragma: keep 2 3 #include <fcntl.h> 4 #include <string.h> 5 #include <unistd.h> 6 7 #include "ast.h" 8 #include "terror.h" 9 tmain()10tmain() { 11 UNUSED(argc); 12 UNUSED(argv); 13 const char *linkname = "foo"; 14 15 char buff[10]; 16 const char *filename = "foobarbaz"; 17 char smallbuff[4]; 18 19 int fd = open(filename, O_CREAT, 0666); 20 if (fd == -1) terror("Failed to create test file"); 21 close(fd); 22 23 if (symlink(filename, linkname) < 0) { 24 terror("Failed to create symbolic link"); 25 } 26 27 if ((pathgetlink(linkname, buff, sizeof(buff)) < 0) || strcmp(buff, filename)) { 28 terror("pathgetlink() should return filename of link"); 29 } 30 31 if (pathgetlink(linkname, smallbuff, sizeof(smallbuff)) > 0) { 32 terror("pathgetlink() should fail when buffer is small"); 33 } 34 35 texit(0); 36 } 37