]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add makedir() in fd_common.h
authorEric Bollengier <eric@baculasystems.com>
Wed, 31 Oct 2018 13:43:47 +0000 (14:43 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 10 Nov 2018 09:41:30 +0000 (10:41 +0100)
bacula/src/plugins/fd/fd_common.h

index a04e757658c2f7374a05835024e90b1f6ae5c0c2..5d98bee3ba69af4febab26ba2f5c3f8026a7f8fe 100644 (file)
@@ -696,3 +696,35 @@ static int32_t full_write(int fd, const char *ptr, int32_t nbytes, bool *cancele
    return nbytes - nleft;
 }
 #endif
+
+#ifdef USE_MAKEDIR
+/* Skip leading slash(es) */
+static bool makedir(char *path, mode_t mode)
+{
+   struct stat statp;
+   char *p = path;
+
+   while (IsPathSeparator(*p)) {
+      p++;
+   }
+   while ((p = first_path_separator(p))) {
+      char save_p;
+      save_p = *p;
+      *p = 0;
+      if (mkdir(path, mode) != 0) {
+         if (stat(path, &statp) != 0) {
+            *p = save_p;
+            return false;
+         } else if (!S_ISDIR(statp.st_mode)) {
+            *p = save_p;
+            return false;
+         }
+      }
+      *p = save_p;
+      while (IsPathSeparator(*p)) {
+         p++;
+      }
+   }
+   return true;
+}
+#endif