diff options
author | Jari Aalto <jari.aalto@cante.net> | 1999-02-19 17:11:39 +0000 |
---|---|---|
committer | Jari Aalto <jari.aalto@cante.net> | 2009-09-12 16:46:52 +0000 |
commit | b72432fdcc59300c6fe7c9d6c8a31ad3447933f5 (patch) | |
tree | b9899162338c2ff3fd83a8aef8831cb119e85cd7 /builtins/umask.def | |
parent | bc4cd23ce958feda898c618215f94d8a4e8f4ffa (diff) | |
download | android_external_bash-b72432fdcc59300c6fe7c9d6c8a31ad3447933f5.tar.gz android_external_bash-b72432fdcc59300c6fe7c9d6c8a31ad3447933f5.tar.bz2 android_external_bash-b72432fdcc59300c6fe7c9d6c8a31ad3447933f5.zip |
Imported from ../bash-2.03.tar.gz.
Diffstat (limited to 'builtins/umask.def')
-rw-r--r-- | builtins/umask.def | 149 |
1 files changed, 73 insertions, 76 deletions
diff --git a/builtins/umask.def b/builtins/umask.def index f734113..5b98c0c 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); } |