# HG changeset patch # User Rob Landley # Date 1342928705 18000 # Node ID 92200901cfe16af6f594e3fbfd26a56aec391464 # Parent 9aeea680acc714cbb5b6cbcb8711e6eee89b63d9 Make chmod +w respect umask, implement +s and +t, fix ls to show suid/sgid/stid without x bit. diff -r 9aeea680acc7 -r 92200901cfe1 lib/lib.c --- a/lib/lib.c Sat Jul 21 18:38:36 2012 -0500 +++ b/lib/lib.c Sat Jul 21 22:45:05 2012 -0500 @@ -983,16 +983,20 @@ // Gaze into the bin of permission... for (;;) { - int i, j, dowho, dohow, dowhat; + int i, j, dowho, dohow, dowhat, amask; - dowho = dohow = dowhat = 0; + dowho = dohow = dowhat = amask = 0; // Find the who, how, and what stanzas, in that order while (*str && (s = strchr(whos, *str))) { dowho |= 1<<(s-whos); str++; } - if (!dowho) dowho = 8; + // If who isn't specified, like "a" but honoring umask. + if (!dowho) { + dowho = 8; + umask(amask=umask(0)); + } if (!*str || !(s = strchr(hows, *str))) goto barf; dohow = *(str++); @@ -1018,19 +1022,26 @@ for (i=0; i<4; i++) { for (j=0; j<3; j++) { mode_t bit = 0; + int where = 1<<((3*i)+j); + + if (amask & where) continue; // Figure out new value at this location if (i == 3) { - } else if (dowhat&(1<