| iMatix home page | << | < | > | >> |
SFL Version 2.11 |
#include "sfldir.h" char * locate_path ( const char *root, const char *path)
Accepts a root directory and a path and locates the path with respect to the root. If the path looks like an absolute directory, returns the path after cleaning it up. Otherwise appends the path to the root, and returns the result. In any case, the resulting directory does not need to exist. Cleans-up the returned path by appending a '/' if necessary, and resolving any '..' subpaths. The returned value is held in a freshly-allocated string which the caller must free using mem_free() when finished with..
{ #if (defined (__UNIX__) || defined (MSDOS_FILESYSTEM) || defined (__VMS__)) char *new_path, /* Returned path value */ *resolved; /* and after .. resolution */ ASSERT (root); ASSERT (path); #if (defined (MSDOS_FILESYSTEM)) /* Under MSDOS, OS/2, or Windows we have a full path if we have any of: * /directory * D:/directory * the variations of those with backslashes. */ if (path [0] == '\\' || path [0] == '/' || (isalpha (path [0]) && path [1] == ':' && (path [2] == '\\' || path [2] == '/'))) #else /* Under UNIX or VMS we have a full path if the path starts with the * directory marker. */ if (path [0] == PATHEND) #endif new_path = mem_strdup (path); /* Use path as supplied */ else { xstrcpy_debug (); if (path_delimiter (strlast (root))) new_path = xstrcpy (NULL, root, path, NULL); else new_path = xstrcpy (NULL, root, "/", path, NULL); } resolved = resolve path (new_path); mem_free (new_path); /* Append slash if necessary */ if (!path_delimiter (strlast (resolved))) { new_path = resolved; xstrcpy_debug (); resolved = xstrcpy (NULL, new_path, "/", NULL); mem_free (new_path); } return (resolved); #else return (mem_strdup (path)); /* Unknown system */ #endif }
| << | < | > | >> | Copyright © 1996-2000 iMatix Corporation |