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>
25 mode_t folder_perms, saved_umask;
28 context_save(); /* save the context file */
31 if (!(cp = context_find("folder-protect")) || !*cp) {
34 folder_perms = strtoul(cp, NULL, 8);
37 ** Folders have definite desired permissions that are set -- we
38 ** don't want to interact with the umask. Clear it temporarily.
40 saved_umask = umask(0);
42 c = strncpy(path, dir, sizeof(path));
44 while (!had_an_error && (c = strchr((c + 1), '/')) != NULL) {
46 /* Create an outer directory. */
47 if (mkdir(path, folder_perms) == -1 &&
49 advise(dir, "unable to create directory");
56 ** Create the innermost nested subdirectory of the
57 ** path we're being asked to create.
59 if (!had_an_error && mkdir(dir, folder_perms)==-1) {
60 advise(dir, "unable to create directory");
63 umask(saved_umask); /* put the user's umask back */
65 return (had_an_error) ? 0 : 1;