diff options
| author | 2026-01-12 16:30:37 -0600 | |
|---|---|---|
| committer | 2026-01-12 16:30:37 -0600 | |
| commit | 2016dceaa9cfc65ee80ee7e433331390f4263744 (patch) | |
| tree | d0c97b2ab5fc1933298a050f167b6a68fff08c89 /lib/util.c | |
| parent | add support for verified files (diff) | |
download jobs
Diffstat (limited to 'lib/util.c')
| -rw-r--r-- | lib/util.c | 30 |
1 files changed, 30 insertions, 0 deletions
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 <fcntl.h> +#include <sys/stat.h> +#include <errno.h> +#include <string.h> + +/* 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; +} |
