summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorportix <none@none>2012-03-29 16:13:39 +0200
committerportix <none@none>2012-03-29 16:13:39 +0200
commit58bd735a96f0f8ac144790223a694c2d1d4557d8 (patch)
tree527f5a7b3cdae5e54d4392ab0e8e22304f07d55d /src/util.c
parenta5a1b73dd582d8bc46caafe766f1c911a6fcb0f0 (diff)
downloaddwb-58bd735a96f0f8ac144790223a694c2d1d4557d8.zip
Expand ~ in util_set_file_content
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index d1ce2675..d0066323 100644
--- a/src/util.c
+++ b/src/util.c
@@ -320,6 +320,16 @@ util_get_lines(const char *filename) {
}
return ret;
}
+char *
+util_expand_home(char *buffer, const char *filename, size_t length) {
+ if (*filename == '~') {
+ const char *home = g_getenv("HOME");
+ snprintf(buffer, length, "%s%s", home, filename+1);
+ }
+ else
+ strncpy(buffer, filename, length);
+ return buffer;
+}
/* util_set_file_content(const char *filename, const char *content) {{{*/
gboolean
util_set_file_content(const char *filename, const char *content) {
@@ -328,6 +338,9 @@ util_set_file_content(const char *filename, const char *content) {
char *link = NULL;
char *dname = NULL;
char *realpath = NULL;
+ char buffer[PATH_MAX];
+ util_expand_home(buffer, filename, PATH_MAX);
+ filename = buffer;
if (g_file_test(filename, G_FILE_TEST_IS_SYMLINK)) {
link = g_file_read_link(filename, &error);
if (link == NULL) {