mirror of https://github.com/sheumann/hush.git
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>
This commit is contained in:
parent
6283f98283
commit
c1e2e005b4
31
shell/ash.c
31
shell/ash.c
|
@ -12816,16 +12816,9 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||||
static int FAST_FUNC
|
static int FAST_FUNC
|
||||||
umaskcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
umaskcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||||
{
|
{
|
||||||
static const char permuser[3] ALIGN1 = "ugo";
|
static const char permuser[3] ALIGN1 = "ogu";
|
||||||
static const char permmode[3] ALIGN1 = "rwx";
|
|
||||||
static const short permmask[] ALIGN2 = {
|
|
||||||
S_IRUSR, S_IWUSR, S_IXUSR,
|
|
||||||
S_IRGRP, S_IWGRP, S_IXGRP,
|
|
||||||
S_IROTH, S_IWOTH, S_IXOTH
|
|
||||||
};
|
|
||||||
|
|
||||||
mode_t mask;
|
mode_t mask;
|
||||||
int i;
|
|
||||||
int symbolic_mode = 0;
|
int symbolic_mode = 0;
|
||||||
|
|
||||||
while (nextopt("S") != '\0') {
|
while (nextopt("S") != '\0') {
|
||||||
|
@ -12839,22 +12832,26 @@ umaskcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||||
|
|
||||||
if (*argptr == NULL) {
|
if (*argptr == NULL) {
|
||||||
if (symbolic_mode) {
|
if (symbolic_mode) {
|
||||||
char buf[18];
|
char buf[sizeof("u=rwx,g=rwx,o=rwx")];
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
i = 2;
|
||||||
int j;
|
for (;;) {
|
||||||
|
unsigned bits;
|
||||||
|
|
||||||
*p++ = permuser[i];
|
*p++ = permuser[i];
|
||||||
*p++ = '=';
|
*p++ = '=';
|
||||||
for (j = 0; j < 3; j++) {
|
/* mask is 0..0uuugggooo. i=2 selects uuu bits */
|
||||||
if ((mask & permmask[3 * i + j]) == 0) {
|
bits = (mask >> (i*3));
|
||||||
*p++ = permmode[j];
|
if (!(bits & 4)) *p++ = 'r';
|
||||||
}
|
if (!(bits & 2)) *p++ = 'w';
|
||||||
}
|
if (!(bits & 1)) *p++ = 'x';
|
||||||
|
if (--i < 0)
|
||||||
|
break;
|
||||||
*p++ = ',';
|
*p++ = ',';
|
||||||
}
|
}
|
||||||
*--p = '\0';
|
*p = '\0';
|
||||||
puts(buf);
|
puts(buf);
|
||||||
} else {
|
} else {
|
||||||
out1fmt("%.4o\n", mask);
|
out1fmt("%.4o\n", mask);
|
||||||
|
|
Loading…
Reference in New Issue