1 /*
2  * mkdirs - make the directories implied by `name'
3  */
4 
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include "libc.h"
10 #include "news.h"
11 
12 /*
13  * Given a/b/c/d, try to make any of a, a/b, a/b/c and a/b/c/d which are missing;
14  * stop on first failure.
15  * Returns success.
16  */
17 boolean
mkdirs(name,uid,gid)18 mkdirs(name, uid, gid)
19 register char *name;
20 int uid, gid;
21 {
22 	register char *cp;
23 	register int isthere = YES;
24 	struct stat stbuf;
25 
26 	for (cp = name; isthere && *cp != '\0'; cp++)
27 		if (*cp == FNDELIM) {
28 			*cp = '\0';
29 			isthere = stat(name, &stbuf) >= 0;
30 			if (!isthere) {
31 				isthere = mkdir(name, 0777) >= 0;
32 				(void) chown(name, uid, gid);
33 			}
34 			*cp = FNDELIM;
35 		}
36 	return isthere;
37 }
38