summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-03 21:44:59 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-03 21:45:46 +0200
commit9de5c93986bc6a4b33f3f50ed2a94c9aa3a33c7f (patch)
tree592a91bb99de624139de9f64d0fc4e2716889891 /lib
parent11163f69106c88736499ca3ec3a9972bcdcd0c26 (diff)
unsquashfs: add code to unpack the entire file system
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/Makemodule.am2
-rw-r--r--lib/util/mkdir_p.c42
2 files changed, 43 insertions, 1 deletions
diff --git a/lib/Makemodule.am b/lib/Makemodule.am
index f23d9b7..691d6df 100644
--- a/lib/Makemodule.am
+++ b/lib/Makemodule.am
@@ -19,7 +19,7 @@ libsquashfs_a_SOURCES += include/frag_reader.h
libutil_a_SOURCES = lib/util/canonicalize_name.c lib/util/write_retry.c
libutil_a_SOURCES += lib/util/read_retry.c include/util.h
-libutil_a_SOURCES += lib/util/print_version.c
+libutil_a_SOURCES += lib/util/print_version.c lib/util/mkdir_p.c
if WITH_ZLIB
libcompress_a_SOURCES += lib/comp/zlib.c
diff --git a/lib/util/mkdir_p.c b/lib/util/mkdir_p.c
new file mode 100644
index 0000000..7d1e052
--- /dev/null
+++ b/lib/util/mkdir_p.c
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <alloca.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include "util.h"
+
+int mkdir_p(const char *path)
+{
+ size_t i, len;
+ char *buffer;
+
+ while (path[0] == '/' && path[1] == '/')
+ ++path;
+
+ if (*path == '\0' || (path[0] == '/' && path[1] == '\0'))
+ return 0;
+
+ len = strlen(path) + 1;
+ buffer = alloca(len);
+
+ for (i = 0; i < len; ++i) {
+ if (i > 0 && (path[i] == '/' || path[i] == '\0')) {
+ buffer[i] = '\0';
+
+ if (mkdir(buffer, 0755) != 0) {
+ if (errno != EEXIST) {
+ fprintf(stderr, "mkdir %s: %s\n",
+ buffer, strerror(errno));
+ return -1;
+ }
+ }
+ }
+
+ buffer[i] = path[i];
+ }
+
+ return 0;
+}