diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-07 17:32:56 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-07 17:32:56 +0200 |
| commit | c1e2e005b4e99070f58a3545bad54ef41a634ad1 (patch) | |
| tree | 1683ff3199c445686ef79a7ce74cb19e36985c9b /shell | |
| parent | 6283f9828320ef5e0be0b060b7f26522b529ed42 (diff) | |
| download | busybox-w32-c1e2e005b4e99070f58a3545bad54ef41a634ad1.tar.gz busybox-w32-c1e2e005b4e99070f58a3545bad54ef41a634ad1.tar.bz2 busybox-w32-c1e2e005b4e99070f58a3545bad54ef41a634ad1.zip | |
ash: shrink "umask -S" code
function old new delta
umaskcmd 279 286 +7
static.permmode 3 - -3
static.permmask 18 - -18
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/ash.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/shell/ash.c b/shell/ash.c index 2669157bc..80dfc1d6a 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -12816,16 +12816,9 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
| 12816 | static int FAST_FUNC | 12816 | static int FAST_FUNC |
| 12817 | umaskcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | 12817 | umaskcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
| 12818 | { | 12818 | { |
| 12819 | static const char permuser[3] ALIGN1 = "ugo"; | 12819 | static const char permuser[3] ALIGN1 = "ogu"; |
| 12820 | static const char permmode[3] ALIGN1 = "rwx"; | ||
| 12821 | static const short permmask[] ALIGN2 = { | ||
| 12822 | S_IRUSR, S_IWUSR, S_IXUSR, | ||
| 12823 | S_IRGRP, S_IWGRP, S_IXGRP, | ||
| 12824 | S_IROTH, S_IWOTH, S_IXOTH | ||
| 12825 | }; | ||
| 12826 | 12820 | ||
| 12827 | mode_t mask; | 12821 | mode_t mask; |
| 12828 | int i; | ||
| 12829 | int symbolic_mode = 0; | 12822 | int symbolic_mode = 0; |
| 12830 | 12823 | ||
| 12831 | while (nextopt("S") != '\0') { | 12824 | while (nextopt("S") != '\0') { |
| @@ -12839,22 +12832,26 @@ umaskcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
| 12839 | 12832 | ||
| 12840 | if (*argptr == NULL) { | 12833 | if (*argptr == NULL) { |
| 12841 | if (symbolic_mode) { | 12834 | if (symbolic_mode) { |
| 12842 | char buf[18]; | 12835 | char buf[sizeof("u=rwx,g=rwx,o=rwx")]; |
| 12843 | char *p = buf; | 12836 | char *p = buf; |
| 12837 | int i; | ||
| 12844 | 12838 | ||
| 12845 | for (i = 0; i < 3; i++) { | 12839 | i = 2; |
| 12846 | int j; | 12840 | for (;;) { |
| 12841 | unsigned bits; | ||
| 12847 | 12842 | ||
| 12848 | *p++ = permuser[i]; | 12843 | *p++ = permuser[i]; |
| 12849 | *p++ = '='; | 12844 | *p++ = '='; |
| 12850 | for (j = 0; j < 3; j++) { | 12845 | /* mask is 0..0uuugggooo. i=2 selects uuu bits */ |
| 12851 | if ((mask & permmask[3 * i + j]) == 0) { | 12846 | bits = (mask >> (i*3)); |
| 12852 | *p++ = permmode[j]; | 12847 | if (!(bits & 4)) *p++ = 'r'; |
| 12853 | } | 12848 | if (!(bits & 2)) *p++ = 'w'; |
| 12854 | } | 12849 | if (!(bits & 1)) *p++ = 'x'; |
| 12850 | if (--i < 0) | ||
| 12851 | break; | ||
| 12855 | *p++ = ','; | 12852 | *p++ = ','; |
| 12856 | } | 12853 | } |
| 12857 | *--p = '\0'; | 12854 | *p = '\0'; |
| 12858 | puts(buf); | 12855 | puts(buf); |
| 12859 | } else { | 12856 | } else { |
| 12860 | out1fmt("%.4o\n", mask); | 12857 | out1fmt("%.4o\n", mask); |
