| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 1.91

 

locate_path

#include "sfldir.h"
char *
locate_path (
    const char *root,
    const char *path)

Synopsis

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 static string that is reused by each call to this function.

Source Code - (sfldir.c)

{
#if (defined (__UNIX__) || defined (MSDOS_FILESYSTEM) || defined (__VMS__))
    static char
        new_path [PATH_MAX];            /*  Returned path value              */

    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
        strcpy (new_path, path);        /*  Use path as supplied             */
    else
      {
        strcpy (new_path, root);        /*  Build root/path                  */
        if (!path_delimiter (strlast (new_path)))
            strcat (new_path, "/");
        strcat (new_path, path);
      }
    /*  Append slash if necessary                                            */
    if (!path_delimiter (strlast (new_path)))
        strcat (new_path, "/");
    return (resolve path (new_path));
#else
    return ((char *) path);
#endif
}

| << | < | > | >> iMatix Copyright © 1996-98 iMatix