From 0437413da2e6a61d955300c9bbc56f88d2461100 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 17 Jul 2012 19:26:57 +0200 Subject: main: add --cache-path parameter and use it for version.xml and wtf image --- src/common.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/common.c') diff --git a/src/common.c b/src/common.c index e20bd78..904687e 100644 --- a/src/common.c +++ b/src/common.c @@ -21,6 +21,8 @@ #include #include +#include +#include #include "common.h" @@ -132,3 +134,26 @@ char *generate_guid() guid[36] = '\0'; return guid; } + +int mkdir_with_parents(const char *dir, int mode) +{ + if (!dir) return -1; + if (__mkdir(dir, mode) == 0) { + return 0; + } else { + if (errno == EEXIST) return 0; + } + int res; + char *parent = strdup(dir); + parent = dirname(parent); + if (parent && (strcmp(parent, ".") != 0)) { + res = mkdir_with_parents(parent, mode); + } else { + res = -1; + } + free(parent); + if (res == 0) { + mkdir_with_parents(dir, mode); + } + return res; +} -- cgit v1.1-32-gdbae