]>
diplodocus.org Git - nmh/blob - sbr/makedir.c
3 * makedir.c -- make a directory
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
11 * Modified to try recursive create.
21 char* folder_perms_ASCII
;
23 mode_t folder_perms
, saved_umask
;
26 context_save(); /* save the context file */
29 if (!(folder_perms_ASCII
= context_find ("folder-protect")))
30 folder_perms_ASCII
= foldprot
; /* defaults to "700" */
32 /* Because mh-profile.man documents "Folder-Protect:" as an octal constant,
33 and we don't want to force the user to remember to include a leading
34 zero, we call atooi(folder_perms_ASCII) here rather than
35 strtoul(folder_perms_ASCII, NULL, 0). Therefore, if anyone ever tries to
36 specify a mode in say, hex, they'll get garbage. (I guess nmh uses its
37 atooi() function rather than calling strtoul() with a radix of 8 because
38 some ancient platforms are missing that functionality. */
39 folder_perms
= atooi(folder_perms_ASCII
);
41 /* Folders have definite desired permissions that are set -- we don't want
42 to interact with the umask. Clear it temporarily. */
43 saved_umask
= umask(0);
45 c
= strncpy(path
, dir
, sizeof(path
));
47 while (!had_an_error
&& (c
= strchr((c
+ 1), '/')) != NULL
) {
49 if (access(path
, X_OK
)) {
51 advise (dir
, "unable to create directory");
54 /* Create an outer directory. */
55 if (mkdir(path
, folder_perms
)) {
56 advise (dir
, "unable to create directory");
64 /* Create the innermost nested subdirectory of the path we're being
66 if (mkdir (dir
, folder_perms
) == -1) {
67 advise (dir
, "unable to create directory");
72 umask(saved_umask
); /* put the user's umask back */
75 return 0; /* opposite of UNIX error return convention */