summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2011-09-26 15:46:07 +0200
committerportix <portix@gmx.net>2011-09-26 15:46:07 +0200
commit821efc741fe5d57d74d748509b49cadebe6335ba (patch)
treeab217b2a1e763a6e3d8615219dc9881029e43131 /src/util.c
parent09bdc4d218c5e37e6943944c0d278694dc6940a1 (diff)
downloaddwb-821efc741fe5d57d74d748509b49cadebe6335ba.zip
External editor
--HG-- branch : ext-editor
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index c2193375..895646c3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -19,6 +19,18 @@
#include "util.h"
/* util_string_replace(const char *haystack, const char *needle, const char *replace) return: char * (alloc){{{*/
+
+char *
+util_get_temp_filename(void) {
+ struct timeval t;
+ gettimeofday(&t, NULL);
+ const char *path = g_get_user_cache_dir();
+ char *filename = g_strdup_printf("edit%lu", t.tv_usec + t.tv_sec*1000000);
+ char *cache_path = g_build_filename(path, dwb.misc.name, filename, NULL);
+ g_free(filename);
+
+ return cache_path;
+}
char *
util_string_replace(const char *haystack, const char *needle, const char *replacemant) {
char **token;
@@ -273,6 +285,25 @@ util_get_directory_content(GString **buffer, const char *dirname) {
}
}/*}}}*/
+void
+util_rmdir(const char *path, gboolean recursive) {
+ GDir *dir = g_dir_open(path, 0, NULL);
+ if (dir == NULL)
+ return;
+ const char *filename = NULL;
+ char *fullpath;
+ while ( (filename = g_dir_read_name(dir)) ) {
+ fullpath = g_build_filename(path, filename, NULL);
+ if (!g_file_test(fullpath, G_FILE_TEST_IS_DIR)) {
+ unlink(fullpath);
+ }
+ else if (recursive) {
+ util_rmdir(fullpath, true);
+ rmdir(fullpath);
+ }
+ g_free(fullpath);
+ }
+}
/* util_get_file_content(const char *filename) return: char * (alloc) {{{*/
char *
util_get_file_content(const char *filename) {