summaryrefslogtreecommitdiff
path: root/src/core/wee-string.c
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2010-05-02 18:21:58 +0200
committerSebastien Helleu <flashcode@flashtux.org>2010-05-02 18:21:58 +0200
commit4616ca981ed37dde25105e7ebd5d9d1b7717a022 (patch)
tree3b61407ece3c31c662268181e5e3c03db7d79f06 /src/core/wee-string.c
parent1836b40a4a7866200a98e5aa7cb18e41ed7ae0b5 (diff)
downloadweechat-4616ca981ed37dde25105e7ebd5d9d1b7717a022.zip
Add function "string_expand_home" in plugin API, fix bug with replacement of home in paths
Diffstat (limited to 'src/core/wee-string.c')
-rw-r--r--src/core/wee-string.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index afdc05ed4..115c81295 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -396,6 +396,36 @@ string_replace (const char *string, const char *search, const char *replace)
}
/*
+ * 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
* after last quote)