summaryrefslogtreecommitdiff
path: root/src/mkdir.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-11-17 08:18:38 +0000
committerJim Meyering <jim@meyering.net>1999-11-17 08:18:38 +0000
commit06c06bd6f740a2e84931a4b58a308a6d36897d68 (patch)
tree8f6154944842d5833791c183b61593dc682213b8 /src/mkdir.c
parent8c63b5603035bf5835c5cd57e6ff5351c6653e87 (diff)
downloadcoreutils-06c06bd6f740a2e84931a4b58a308a6d36897d68.tar.xz
(S_IRWXUGO): Define if necessary.
(main): Use chmod to set the permissions if bits other than those of S_IRWXUGO were requested. Reported by Sami Farin.
Diffstat (limited to 'src/mkdir.c')
-rw-r--r--src/mkdir.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/mkdir.c b/src/mkdir.c
index 9f24bb216..00b8b5cd3 100644
--- a/src/mkdir.c
+++ b/src/mkdir.c
@@ -27,6 +27,10 @@
#include "makepath.h"
#include "modechange.h"
+#ifndef S_IRWXUGO
+# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
+#endif
+
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "mkdir"
@@ -117,7 +121,7 @@ main (int argc, char **argv)
usage (1);
}
- newmode = (S_IRWXU | S_IRWXG | S_IRWXO) & ~ umask (0);
+ newmode = S_IRWXUGO & ~ umask (0);
parent_mode = S_IWUSR | S_IXUSR | newmode;
if (symbolic_mode)
{
@@ -131,20 +135,34 @@ main (int argc, char **argv)
for (; optind < argc; ++optind)
{
+ int fail = 0;
if (path_mode)
{
- errors |= make_path (argv[optind], newmode, parent_mode,
- -1, -1, 1, verbose_fmt_string);
+ fail = make_path (argv[optind], newmode, parent_mode,
+ -1, -1, 1, verbose_fmt_string);
}
- else if (mkdir (argv[optind], newmode))
+ else
{
- error (0, errno, _("cannot create directory `%s'"), argv[optind]);
- errors = 1;
+ fail = mkdir (argv[optind], newmode);
+ if (fail)
+ error (0, errno, _("cannot create directory `%s'"), argv[optind]);
+ else if (verbose_fmt_string)
+ error (0, 0, verbose_fmt_string, argv[optind]);
}
- else if (verbose_fmt_string)
+
+ /* FIXME: move this functionality into make_path. */
+ /* mkdir(2) is required to honor only the file permission bits.
+ In particular, it needn't do anything about `special' bits,
+ so if any were set in newmode, apply them with chmod. */
+ if (fail == 0 && (newmode & ~S_IRWXUGO))
{
- error (0, 0, verbose_fmt_string, argv[optind]);
+ fail = chmod (argv[optind], newmode);
+ if (fail)
+ error (0, errno, _("cannot set permissions of directory `%s'"),
+ argv[optind]);
}
+
+ errors |= fail;
}
exit (errors);