#include #include #include #include #include #include #include #include #include #ifndef F_GETPATH #define F_GETPATH (1024 + 7) #endif int main(int ac, char **av) { int size; int fd, pfds[2]; char buf[MAXPATHLEN]; fprintf(stdout, "Testing PIPE ...\n"); if (pipe(pfds)) perror("pipe"); else { if ((size = fcntl(pfds[0], F_GETPATH, buf)) < 0) perror("fcntl(PIPE)"); else { fprintf(stdout, "PIPE: path='%s' size = %d\n", buf, size); } close(pfds[1]); close(pfds[0]); } fprintf(stdout, "Testing SOCKET ...\n"); if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) perror("socket"); else { if ((size = fcntl(fd, F_GETPATH, buf)) < 0) perror("fcntl(SOCKET)"); else { fprintf(stdout, "SOCKET: path='%s' size = %d\n", buf, size); } close(fd); } fprintf(stdout, "Testing FILE ...\n"); if ((fd = open(av[0], O_RDONLY)) < 0) perror(av[0]); else { if ((size = fcntl(fd, F_GETPATH, buf)) < 0) perror("fcntl(FILE)"); else { fprintf(stdout, "FILE: path='%s' size = %d\n", buf, size); } close(fd); } return 0; }