diff options
author | portix <none@none> | 2012-03-29 16:13:39 +0200 |
---|---|---|
committer | portix <none@none> | 2012-03-29 16:13:39 +0200 |
commit | 58bd735a96f0f8ac144790223a694c2d1d4557d8 (patch) | |
tree | 527f5a7b3cdae5e54d4392ab0e8e22304f07d55d /src/util.c | |
parent | a5a1b73dd582d8bc46caafe766f1c911a6fcb0f0 (diff) | |
download | dwb-58bd735a96f0f8ac144790223a694c2d1d4557d8.zip |
Expand ~ in util_set_file_content
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -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) { |