From 438ad16d03f38e0e444f6ad575078ee949679a86 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Wed, 27 Dec 2023 16:05:41 +0530 Subject: repo: init --- util.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 util.c (limited to 'util.c') diff --git a/util.c b/util.c new file mode 100644 index 0000000..6e6079e --- /dev/null +++ b/util.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +#include "util.h" + +int r_mkdir(const char *path, mode_t mode) +{ + int r; + size_t len; + char *p; + char tmp[NAME_MAX + 1]; + + strncpy(tmp, path, sizeof(tmp) - 1); + len = strlen(tmp); + if(tmp[len - 1] == '/') + tmp[len - 1] = '\0'; + + for (p = tmp + 1; *p; ++p) { + if (*p == '/') { + *p = '\0'; + + r = mkdir(tmp, mode); + if (r && !(errno & EEXIST)) + return r; + + *p = '/'; + } + } + + return mkdir(path, mode); +} -- cgit v1.2.3