#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; }