(main): Compile mode with MODE_MASK_ALL and initial umask.
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 22 Apr 2005 23:52:35 +0000 (23:52 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 22 Apr 2005 23:52:35 +0000 (23:52 +0000)
src/mkdir.c

index e52ac9c..d0c975f 100644 (file)
@@ -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;