1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-26 12:56:37 +02:00

core: remove trailing directory separators in home directories (closes #2070)

This commit is contained in:
Sébastien Helleu
2024-02-10 10:23:40 +01:00
parent 5c6e6f43d1
commit caa51160da
3 changed files with 67 additions and 0 deletions
+28
View File
@@ -629,6 +629,29 @@ use_xdg:
return 1;
}
/*
* Removes trailing separators in path, which is modified in place
* (each trailing separator is replaced by NUL char).
*
* Example on Linux: "/home/xxx/" => "/home/xxx".
*/
void
dir_remove_trailing_separators (char *path)
{
int length;
if (!path || !path[0])
return;
length = strlen (path);
while ((length > 1) && (path[length - 1] == DIR_SEPARATOR_CHAR))
{
path[length - 1] = '\0';
length--;
}
}
/*
* Creates a home directory.
*
@@ -681,6 +704,11 @@ dir_create_home_dirs ()
if (!dir_find_home_dirs ())
goto error;
dir_remove_trailing_separators (weechat_config_dir);
dir_remove_trailing_separators (weechat_data_dir);
dir_remove_trailing_separators (weechat_cache_dir);
dir_remove_trailing_separators (weechat_runtime_dir);
rc = dir_create_home_dir (weechat_config_dir);
if (rc && (strcmp (weechat_config_dir, weechat_data_dir) != 0))
rc = dir_create_home_dir (weechat_data_dir);