2 ** makedir.c -- make a directory
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
10 ** Modified to try recursive create.
15 #include <sys/param.h>
24 mode_t folder_perms, saved_umask;
27 context_save(); /* save the context file */
30 if (!(cp = context_find("folder-protect")) || !*cp) {
33 folder_perms = strtoul(cp, NULL, 8);
36 ** Folders have definite desired permissions that are set -- we
37 ** don't want to interact with the umask. Clear it temporarily.
39 saved_umask = umask(0);
41 c = strncpy(path, dir, sizeof(path));
43 while (!had_an_error && (c = strchr((c + 1), '/')) != NULL) {
45 /* Create an outer directory. */
46 if (mkdir(path, folder_perms) == -1 &&
48 advise(dir, "unable to create directory");
55 ** Create the innermost nested subdirectory of the
56 ** path we're being asked to create.
58 if (!had_an_error && mkdir(dir, folder_perms)==-1) {
59 advise(dir, "unable to create directory");
62 umask(saved_umask); /* put the user's umask back */
64 return (had_an_error) ? 0 : 1;