-static char *prefix_path(const char *prefix, int len, const char *path)
-{
- int speclen;
- char *n;
-
- for (;;) {
- char c;
- if (*path != '.')
- break;
- c = path[1];
- /* "." */
- if (!c) {
- path++;
- break;
- }
- /* "./" */
- if (c == '/') {
- path += 2;
- continue;
- }
- if (c != '.')
- break;
- c = path[2];
- if (!c)
- path += 2;
- else if (c == '/')
- path += 3;
- else
- break;
- /* ".." and "../" */
- /* Remove last component of the prefix */
- do {
- if (!len)
- return NULL;
- len--;
- } while (len && prefix[len-1] != '/');
- continue;
- }
- if (!len)
- return para_strdup(path);
- speclen = strlen(path);
- n = para_malloc(speclen + len + 1);
- memcpy(n, prefix, len);
- memcpy(n + len, path, speclen+1);
- return n;
-}
-
-/*
- * We fundamentally don't like some paths: we don't want
- * dot or dot-dot anywhere.
- *
- * Also, we don't want double slashes or slashes at the
- * end that can make pathnames ambiguous.
- */