|
| iMatix home page | << | < | > | >> |
SFLVersion 2.11 |
#include "sfldir.h"
char *
clean_path (
const char *path)
Returns a clean directory name; i.e. resolves the path, removes a trailing slash unless the name consists just of '/'; on a MS- DOS file system, cleans-up a directory name consisting of a disk specifier. The cleaned-up directory path is in a static area that is overwritten by each call.
{
#if (defined (__UNIX__) || defined (MSDOS_FILESYSTEM) || defined (__VMS__))
static char
new_path [PATH_MAX + 1]; /* Returned path value */
char
*slash;
strncpy (new_path, path, PATH_MAX);
new_path [PATH_MAX] = '\0';
# if (defined (MSDOS_FILESYSTEM))
/* For DOS filesystems, use only back slashes */
strconvch (new_path, '/', '\\');
# endif
slash = strrchr (new_path, PATHEND); /* Find last slash */
# if (defined (MSDOS_FILESYSTEM))
/* If slash is last character in string, maybe squash it */
if (slash && slash [1] == '\0')
{
if (slash > new_path && slash [-1] != ':')
*slash = '\0';
}
else /* Turn X: into X:\ */
if (new_path [1] == ':' && new_path [2] == '\0')
{
new_path [2] = '\\';
new_path [3] = '\0';
}
# else
/* If slash is last character in string, maybe squash it */
if (slash && slash [1] == '\0')
if (slash > new_path)
*slash = '\0';
# endif
return (new_path);
#else
return ((char *) path);
#endif
}
| | << | < | > | >> |
|