From: Eric Bollengier Date: Wed, 31 Oct 2018 13:43:47 +0000 (+0100) Subject: Add makedir() in fd_common.h X-Git-Tag: Release-9.4.0~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0438fd368c28e7ffc4677b715a01eef5e2356c6f;p=thirdparty%2Fbacula.git Add makedir() in fd_common.h --- diff --git a/bacula/src/plugins/fd/fd_common.h b/bacula/src/plugins/fd/fd_common.h index a04e75765..5d98bee3b 100644 --- a/bacula/src/plugins/fd/fd_common.h +++ b/bacula/src/plugins/fd/fd_common.h @@ -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