cmogstored 1.8.1 - use default system stack size
[cmogstored.git] / mkpath_for.c
blobefbf5743aa5398310bf08ece900006c2a218dcf8
1 /*
2 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
3 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
4 */
5 #include "cmogstored.h"
7 /*
8 * "path" is the pathname for a file (not a directory)
9 * returns -1 on error, sets errno to EACCES on invalid paths
11 int mog_mkpath_for(struct mog_svc *svc, char *path)
13 char *tip = path + 1;
14 char *c = strchr(tip, '/');
15 int rc = 0;
16 int i;
18 /* refuse to create files at the top-level */
19 if (c == NULL) {
20 errno = EACCES;
21 return -1;
24 for (i = 0; c != NULL; i++) {
25 if (i > 0) {
26 *c = 0;
27 rc = mog_mkdir(svc, path, svc->mkcol_perms);
28 *c = '/';
31 if (rc != 0 && errno != EEXIST)
32 return rc;
34 tip = c + 1;
35 c = strchr(tip, '/');
38 return 0;