9 char *realpath(const char *filename, char *resolved)
14 char buf[15+3*sizeof(int)];
22 fd = open(filename, O_RDONLY|O_NONBLOCK);
24 snprintf(buf, sizeof buf, "/proc/self/fd/%d", fd);
28 resolved = malloc(PATH_MAX);
29 if (!resolved) return 0;
32 r = readlink(buf, resolved, PATH_MAX-1);
37 r = stat(resolved, &st2);
38 if (r<0 || st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) {
39 if (!r) errno = ELOOP;
46 if (alloc) free(resolved);