From 5ce302fba5b3734fd21315d27948f10bce74b614 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 22 Apr 2005 23:52:35 +0000 Subject: (main): Compile mode with MODE_MASK_ALL and initial umask. --- src/mkdir.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/mkdir.c b/src/mkdir.c index e52ac9cfb..d0c975f70 100644 --- a/src/mkdir.c +++ b/src/mkdir.c @@ -1,5 +1,5 @@ /* mkdir -- make directories - Copyright (C) 90, 1995-2002, 2004 Free Software Foundation, Inc. + Copyright (C) 90, 1995-2002, 2004, 2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -82,7 +82,7 @@ int main (int argc, char **argv) { mode_t newmode; - mode_t parent_mode; + mode_t parent_mode IF_LINT (= 0); const char *specified_mode = NULL; const char *verbose_fmt_string = NULL; int exit_status = EXIT_SUCCESS; @@ -125,16 +125,9 @@ main (int argc, char **argv) } newmode = S_IRWXUGO; - { - mode_t umask_value = umask (0); - umask (umask_value); /* Restore the old value. */ - parent_mode = (newmode & (~ umask_value)) | S_IWUSR | S_IXUSR; - } - if (specified_mode) { - struct mode_change *change = mode_compile (specified_mode, 0); - newmode &= ~ umask (0); + struct mode_change *change = mode_compile (specified_mode, MODE_MASK_ALL); if (change == MODE_INVALID) error (EXIT_FAILURE, 0, _("invalid mode %s"), quote (specified_mode)); else if (change == MODE_MEMORY_EXHAUSTED) @@ -142,6 +135,14 @@ main (int argc, char **argv) newmode = mode_adjust (newmode, change); } + if (specified_mode || create_parents) + { + mode_t umask_value = umask (0); + if (! specified_mode) + umask (umask_value); + parent_mode = (S_IRWXUGO & ~umask_value) | (S_IWUSR | S_IXUSR); + } + for (; optind < argc; ++optind) { bool ok; -- cgit v1.2.3-70-g09d2