1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-09 19:23:13 +02:00

Add function "string_expand_home" in plugin API, fix bug with replacement of home in paths

This commit is contained in:
Sebastien Helleu
2010-05-02 18:21:58 +02:00
parent 1836b40a4a
commit 4616ca981e
15 changed files with 154 additions and 43 deletions
+30
View File
@@ -395,6 +395,36 @@ string_replace (const char *string, const char *search, const char *replace)
return new_string;
}
/*
* string_expand_home: expand home in a PATH
* (for example: "~/file.txt" => "/home/xxx/file.txt")
* note: returned value has to be free() after use
*/
char *
string_expand_home (const char *path)
{
char *ptr_home, *str;
int length;
if (!path)
return NULL;
if (!path[0] || (path[0] != '~') || (path[1] != DIR_SEPARATOR_CHAR))
return strdup (path);
ptr_home = getenv ("HOME");
length = strlen (ptr_home) + strlen (path + 1) + 1;
str = malloc (length);
if (!str)
return strdup (path);
snprintf (str, length, "%s%s", ptr_home, path + 1);
return str;
}
/*
* string_remove_quotes: remove quotes at beginning/end of string
* (ignore spaces if there are before first quote or