diff mbox series

[v2,2/4] util: factor in mkpath()

Message ID 20181214144130.18819-2-christian.storm@siemens.com
State Accepted
Headers show
Series [v2,1/4] cpio_utils: factor in copy_write_padded() | expand

Commit Message

Storm, Christian Dec. 14, 2018, 2:41 p.m. UTC
Shift mkpath() from raw_handler.c to util.c so that
other parts of SWUpdate may use it as well.

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 core/util.c            | 19 +++++++++++++++++++
 handlers/raw_handler.c | 18 ------------------
 include/util.h         |  1 +
 3 files changed, 20 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/core/util.c b/core/util.c
index 00d53e8..ea4ad8a 100644
--- a/core/util.c
+++ b/core/util.c
@@ -21,6 +21,7 @@ 
 #include <dirent.h>
 #include <limits.h>
 #include <time.h>
+#include <libgen.h>
 
 #include "swupdate.h"
 #include "util.h"
@@ -181,6 +182,24 @@  int openfileoutput(const char *filename)
 	return fdout;
 }
 
+int mkpath(char *dir, mode_t mode)
+{
+	if (!dir) {
+		return -EINVAL;
+	}
+
+	if (strlen(dir) == 1 && dir[0] == '/')
+		return 0;
+
+	mkpath(dirname(strdupa(dir)), mode);
+
+	if (mkdir(dir, mode) == -1) {
+		if (errno != EEXIST)
+			return 1;
+	}
+	return 0;
+}
+
 /*
  * This function is strict bounded with the hardware
  * It reads some GPIOs to get the hardware revision
diff --git a/handlers/raw_handler.c b/handlers/raw_handler.c
index 913dce6..7b6c7a7 100644
--- a/handlers/raw_handler.c
+++ b/handlers/raw_handler.c
@@ -45,24 +45,6 @@  static int install_raw_image(struct img_type *img,
 	return ret;
 }
 
-static int mkpath(char *dir, mode_t mode)
-{
-	if (!dir) {
-		return -EINVAL;
-	}
-
-	if (strlen(dir) == 1 && dir[0] == '/')
-		return 0;
-
-	mkpath(dirname(strdupa(dir)), mode);
-
-	if (mkdir(dir, mode) == -1) {
-		if (errno != EEXIST)
-			return 1;
-	}
-	return 0;
-}
-
 static int install_raw_file(struct img_type *img,
 	void __attribute__ ((__unused__)) *data)
 {
diff --git a/include/util.h b/include/util.h
index e48d652..4675d89 100644
--- a/include/util.h
+++ b/include/util.h
@@ -168,6 +168,7 @@  int extract_sw_description(int fd, const char *descfile, off_t *offs);
 off_t extract_next_file(int fd, int fdout, off_t start, int compressed,
 			int encrypted, unsigned char *hash);
 int openfileoutput(const char *filename);
+int mkpath(char *dir, mode_t mode);
 
 int register_notifier(notifier client);
 void notify(RECOVERY_STATUS status, int error, int level, const char *msg);