Bash-4.3 distribution sources and documentation
[platform/upstream/bash.git] / builtins / umask.def
index 9205c94..d9aa041 100644 (file)
@@ -1,43 +1,49 @@
 This file is umask.def, from which is created umask.c.
 It implements the builtin "umask" in Bash.
 
-Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
-Bash is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
+Bash is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
-Bash is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
+Bash is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License along
-with Bash; see the file COPYING.  If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash.  If not, see <http://www.gnu.org/licenses/>.
 
 $PRODUCES umask.c
 
 $BUILTIN umask
 $FUNCTION umask_builtin
 $SHORT_DOC umask [-p] [-S] [mode]
-The user file-creation mask is set to MODE.  If MODE is omitted, or if
-`-S' is supplied, the current value of the mask is printed.  The `-S'
-option makes the output symbolic; otherwise an octal number is output.
-If `-p' is supplied, and MODE is omitted, the output is in a form
-that may be used as input.  If MODE begins with a digit, it is
-interpreted as an octal number, otherwise it is a symbolic mode string
-like that accepted by chmod(1).
+Display or set file mode mask.
+
+Sets the user file-creation mask to MODE.  If MODE is omitted, prints
+the current value of the mask.
+
+If MODE begins with a digit, it is interpreted as an octal number;
+otherwise it is a symbolic mode string like that accepted by chmod(1).
+
+Options:
+  -p   if MODE is omitted, output in a form that may be reused as input
+  -S   makes the output symbolic; otherwise an octal number is output
+
+Exit Status:
+Returns success unless MODE is invalid or an invalid option is given.
 $END
 
 #include <config.h>
 
 #include "../bashtypes.h"
 #include "filecntl.h"
-#ifndef _MINIX
+#if ! defined(_MINIX) && defined (HAVE_SYS_FILE_H)
 #  include <sys/file.h>
 #endif
 
@@ -46,6 +52,9 @@ $END
 #endif
 
 #include <stdio.h>
+#include <chartypes.h>
+
+#include "../bashintl.h"
 
 #include "../shell.h"
 #include "posixstat.h"
@@ -58,8 +67,8 @@ $END
 /*                                                                  */
 /* **************************************************************** */
 
-static void print_symbolic_umask ();
-static int symbolic_umask ();
+static void print_symbolic_umask __P((mode_t));
+static int symbolic_umask __P((WORD_LIST *));
 
 /* Set or display the mask used by the system when creating files.  Flag
    of -S means display the umask in a symbolic mode. */
@@ -92,7 +101,7 @@ umask_builtin (list)
 
   if (list)
     {
-      if (digit (*list->word->word))
+      if (DIGIT (*list->word->word))
        {
          umask_value = read_octal (list->word->word);
 
@@ -102,8 +111,7 @@ umask_builtin (list)
             is lousy. */
          if (umask_value == -1)
            {
-             builtin_error ("`%s' is not an octal number from 000 to 777",
-                               list->word->word);
+             sh_erange (list->word->word, _("octal number"));
              return (EXECUTION_FAILURE);
            }
        }
@@ -128,11 +136,10 @@ umask_builtin (list)
       if (print_symbolically)
        print_symbolic_umask (umask_arg);
       else
-       printf ("%03o\n", umask_arg);
+       printf ("%04lo\n", (unsigned long)umask_arg);
     }
 
-  fflush (stdout);
-  return (EXECUTION_SUCCESS);
+  return (sh_chkwrite (EXECUTION_SUCCESS));
 }
 
 /* Print the umask in a symbolic form.  In the output, a letter is
@@ -179,16 +186,16 @@ parse_symbolic_mode (mode, initial_bits)
      char *mode;
      int initial_bits;
 {
-  int who, op, perm, mask, bits, c;
+  int who, op, perm, bits, c;
   char *s;
 
   for (s = mode, bits = initial_bits;;)
     {
-      who = op = perm = mask = 0;
+      who = op = perm = 0;
 
       /* Parse the `who' portion of the symbolic mode clause. */
       while (member (*s, "agou"))
-        {
+       {
          switch (c = *s++)
            {
            case 'u':
@@ -217,7 +224,7 @@ parse_symbolic_mode (mode, initial_bits)
        case '=':
          break;
        default:
-         builtin_error ("bad symbolic mode operator: %c", op);
+         builtin_error (_("`%c': invalid symbolic mode operator"), op);
          return (-1);
        }
 
@@ -256,6 +263,8 @@ parse_symbolic_mode (mode, initial_bits)
              bits &= ~perm;
              break;
            case '=':
+             if (who == 0)
+               who = S_IRWXU | S_IRWXG | S_IRWXO;
              bits &= ~who;
              bits |= perm;
              break;
@@ -270,7 +279,7 @@ parse_symbolic_mode (mode, initial_bits)
        }
       else
        {
-         builtin_error ("bad character in symbolic mode: %c", *s);
+         builtin_error (_("`%c': invalid symbolic mode character"), *s);
          return (-1);
        }
     }
@@ -294,7 +303,7 @@ symbolic_umask (list)
   /* All work is done with the complement of the umask -- it's
      more intuitive and easier to deal with.  It is complemented
      again before being returned. */
-  bits = parse_symbolic_mode (list->word->word, ~um);
+  bits = parse_symbolic_mode (list->word->word, ~um & 0777);
   if (bits == -1)
     return (-1);