Supporting deeper symbolic links
Supporting deeper symbolic links
Posted Jul 5, 2004 16:15 UTC (Mon) by jschrod (subscriber, #1646)In reply to: Supporting deeper symbolic links by khim
Parent article: Supporting deeper symbolic links
char real_name [path_max+1] = "";
char *s = link_name;
char *path_elem;
while ( path_elem = strstr(s, '/') ) {
char r [path_max+1] = strcpy(real_name);
int size;
strcat(r, "/");
strcat(r, path_elem);
while ( (size = readlink(r, real_name)) != -1 ) {
real_name[size] = NUL;
}
if ( size != EINVAL ) do_error_handling();
s = NULL;
}
No recursion, mom. (Not tested either... :-) Add a few overflow checks, please. And exchange libc functions by kernel ones. But none of them need dynamic memory, so there is no stack issue.
Cheers, Joachim
