MXS-463: Filepaths are now properly formatted for printing

The various global directory setter functions now process the input they receive
and remove redundant and trailing forward slashes from the directory paths.
This commit is contained in:
Markus Makela
2015-12-31 10:33:53 +02:00
parent 05a7f5759b
commit 4ef89d213b
4 changed files with 123 additions and 37 deletions

View File

@ -278,3 +278,44 @@ char *create_hex_sha1_sha1_passwd(char *passwd)
return hexpasswd;
}
/**
* Remove duplicate and trailing forward slashes from a path.
* @param path Path to clean up
*/
void clean_up_pathname(char *path)
{
char *data = path;
size_t len = strlen(path);
if (len > PATH_MAX)
{
MXS_WARNING("Pathname too long: %s", path);
}
while (*data != '\0')
{
if (*data == '/')
{
if (*(data + 1) == '/')
{
memmove(data, data + 1, len);
len--;
}
else if (*(data + 1) == '\0' && data != path)
{
*data = '\0';
}
else
{
data++;
len--;
}
}
else
{
data++;
len--;
}
}
}