User: Password:
|
|
Subscribe / Log in / New account

Supporting deeper symbolic links

Supporting deeper symbolic links

Posted Jul 2, 2004 3:54 UTC (Fri) by khim (subscriber, #9252)
In reply to: Supporting deeper symbolic links by bronson
Parent article: Supporting deeper symbolic links

Think about /usr/bin/gcc where /usr is symlink to /mnt/somewhere/else and then ../bin/.. part is symlink as well and gcc too is symlink...

Now please about that tail recusion thingy again if you can. Heh.

Unfortunatelly you do care about path - just not path you though about...

As "track for stack usage" - it'll be nightmare to administer: sometimes you can compile this program but if b-tree in filesystem is changed somewhat you're suddenly can not do it. Gosh.


(Log in to post comments)

Supporting deeper symbolic links

Posted Jul 5, 2004 16:15 UTC (Mon) by jschrod (subscriber, #1646) [Link]

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


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds