summaryrefslogtreecommitdiffstats
path: root/src/common.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2012-07-17 19:26:57 +0200
committerGravatar Nikias Bassen2012-07-17 19:26:57 +0200
commit0437413da2e6a61d955300c9bbc56f88d2461100 (patch)
tree6de20554c14aba7149281cae66e6a1d2111fe480 /src/common.c
parent58a4fd91026cc00182fc0aea2ab45c19f729b8d0 (diff)
downloadidevicerestore-0437413da2e6a61d955300c9bbc56f88d2461100.tar.gz
idevicerestore-0437413da2e6a61d955300c9bbc56f88d2461100.tar.bz2
main: add --cache-path parameter and use it for version.xml and wtf image
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c25
1 files changed, 25 insertions, 0 deletions
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 <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
#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;
+}