8 * Emulates mkdir -p (creates any missing folders)
11 bool mkdirp(const char *path) {
12 if (mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0)
14 if (errno == EEXIST) {
16 /* Check that the named file actually is a directory. */
17 if (stat(path, &st)) {
18 ELOG("stat(%s) failed: %s\n", path, strerror(errno));
21 if (!S_ISDIR(st.st_mode)) {
22 ELOG("mkdir(%s) failed: %s\n", path, strerror(ENOTDIR));
26 } else if (errno != ENOENT) {
27 ELOG("mkdir(%s) failed: %s\n", path, strerror(errno));
30 char *copy = sstrdup(path);
31 /* strip trailing slashes, if any */
32 while (copy[strlen(copy) - 1] == '/')
33 copy[strlen(copy) - 1] = '\0';
35 char *sep = strrchr(copy, '/');
46 result = mkdirp(path);