X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fruntime%2Fwrap.c;h=9a45b23e78af3ae83a322e32a1f5cd4dd6dbe704;hb=83fd554b67913275d8dc06edcad8b2f065c89c49;hp=272a6f95036e8fde09a4913a8a4fdb01b190bbb9;hpb=e37366e7bb72bc80c6c9908efe09f94ce26add16;p=sbcl.git diff --git a/src/runtime/wrap.c b/src/runtime/wrap.c index 272a6f9..9a45b23 100644 --- a/src/runtime/wrap.c +++ b/src/runtime/wrap.c @@ -106,6 +106,35 @@ free_directory_lispy_filenames(char** directory_lispy_filenames) } /* + * readlink(2) stuff + */ + +/* a wrapped version of readlink(2): + * -- If path isn't a symlink, or is a broken symlink, return 0. + * -- If path is a symlink, return a newly allocated string holding + * the thing it's linked to. + */ +char * +wrapped_readlink(char *path) +{ + int strlen_path = strlen(path); + int bufsiz = strlen(path) + 16; + while (1) { + char *result = malloc(bufsiz); + int n_read = readlink(path, result, n_read); + if (n_read < 0) { + return 0; + } else if (n_read < bufsiz) { + result[n_read] = 0; + return result; + } else { + free(result); + bufsiz *= 2; + } + } +} + +/* * stat(2) stuff */