summaryrefslogtreecommitdiff
path: root/builtins/umask.def
diff options
context:
space:
mode:
Diffstat (limited to 'builtins/umask.def')
-rw-r--r--builtins/umask.def149
1 files changed, 73 insertions, 76 deletions
diff --git a/builtins/umask.def b/builtins/umask.def
index f7341130..5b98c0c8 100644
--- a/builtins/umask.def
+++ b/builtins/umask.def
@@ -174,29 +174,15 @@ print_symbolic_umask (um)
printf ("u=%s,g=%s,o=%s\n", ubits, gbits, obits);
}
-/* Set the umask from a symbolic mode string similar to that accepted
- by chmod. If the -S argument is given, then print the umask in a
- symbolic form. */
-static int
-symbolic_umask (list)
- WORD_LIST *list;
+int
+parse_symbolic_mode (mode, initial_bits)
+ char *mode;
+ int initial_bits;
{
- int um, umc, c;
- int who, op, perm, mask;
+ int who, op, perm, mask, bits, c;
char *s;
- /* Get the initial umask. Don't change it yet. */
- um = umask (022);
- umask (um);
-
- /* All work below is done with the complement of the umask -- it's
- more intuitive and easier to deal with. It is complemented
- again before being returned. */
- umc = ~um;
-
- s = list->word->word;
-
- for (;;)
+ for (s = mode, bits = initial_bits;;)
{
who = op = perm = mask = 0;
@@ -205,20 +191,20 @@ symbolic_umask (list)
{
switch (c = *s++)
{
- case 'u':
- who |= S_IRWXU;
- continue;
- case 'g':
- who |= S_IRWXG;
- continue;
- case 'o':
- who |= S_IRWXO;
- continue;
- case 'a':
- who |= S_IRWXU | S_IRWXG | S_IRWXO;
- continue;
- default:
- break;
+ case 'u':
+ who |= S_IRWXU;
+ continue;
+ case 'g':
+ who |= S_IRWXG;
+ continue;
+ case 'o':
+ who |= S_IRWXO;
+ continue;
+ case 'a':
+ who |= S_IRWXU | S_IRWXG | S_IRWXO;
+ continue;
+ default:
+ break;
}
}
@@ -226,13 +212,13 @@ symbolic_umask (list)
op = *s++;
switch (op)
{
- case '+':
- case '-':
- case '=':
- break;
- default:
- builtin_error ("bad symbolic mode operator: %c", op);
- return (-1);
+ case '+':
+ case '-':
+ case '=':
+ break;
+ default:
+ builtin_error ("bad symbolic mode operator: %c", op);
+ return (-1);
}
/* Parse out the `perm' section of the symbolic mode clause. */
@@ -242,17 +228,15 @@ symbolic_umask (list)
switch (c)
{
- case 'r':
- perm |= S_IRUGO;
- break;
-
- case 'w':
- perm |= S_IWUGO;
- break;
-
- case 'x':
- perm |= S_IXUGO;
- break;
+ case 'r':
+ perm |= S_IRUGO;
+ break;
+ case 'w':
+ perm |= S_IWUGO;
+ break;
+ case 'x':
+ perm |= S_IXUGO;
+ break;
}
}
@@ -265,32 +249,22 @@ symbolic_umask (list)
switch (op)
{
- case '+':
- umc |= perm;
- break;
-
- case '-':
- umc &= ~perm;
- break;
-
- case '=':
- umc &= ~who;
- umc |= perm;
- break;
-
-#if 0
- /* No other values are possible. */
- default:
- builtin_error ("bad symbolic mode operator: %c", op);
- return (-1);
-#endif
- }
-
- if (!*s)
- {
- um = ~umc & 0777;
+ case '+':
+ bits |= perm;
+ break;
+ case '-':
+ bits &= ~perm;
break;
+ case '=':
+ bits &= ~who;
+ bits |= perm;
+ break;
+
+ /* No other values are possible. */
}
+
+ if (*s == '\0')
+ break;
else
s++; /* skip past ',' */
}
@@ -300,5 +274,28 @@ symbolic_umask (list)
return (-1);
}
}
+
+ return (bits);
+}
+
+/* Set the umask from a symbolic mode string similar to that accepted
+ by chmod. If the -S argument is given, then print the umask in a
+ symbolic form. */
+static int
+symbolic_umask (list)
+ WORD_LIST *list;
+{
+ int um, bits;
+
+ /* Get the initial umask. Don't change it yet. */
+ um = umask (022);
+ umask (um);
+
+ /* 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);
+
+ um = ~bits & 0777;
return (um);
}