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:
@ -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--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user