From 2016dceaa9cfc65ee80ee7e433331390f4263744 Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Mon, 12 Jan 2026 16:30:37 -0600 Subject: download jobs --- lib/util.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/util.c (limited to 'lib/util.c') diff --git a/lib/util.c b/lib/util.c new file mode 100644 index 0000000..6cfcf1f --- /dev/null +++ b/lib/util.c @@ -0,0 +1,30 @@ +#include "log.h" +#include "util.h" + +#include +#include +#include +#include + +/* will clobber path */ +int vl_mkdir_parents(int fd, char *path, mode_t mode) +{ + int last = 0; + + char *ch = path; + do { + if (*ch == '/' || (*ch == '\0' && (last = 1))) { + /* last is set to 1 iff *ch == '\0' */ + *ch = '\0'; + + if (mkdirat(fd, path, mode) < 0 && errno != EEXIST) { + vl_debug("Failed to create directory %s: %s", path, strerror(errno)); + return -1; + } + + if (!last) *ch = '/'; + } + } while (*(ch++)); + + return 0; +} -- cgit v1.2.3-70-g09d2