#include #include #define U(x) (x<<6) #define G(x) (x<<3) #define O(x) (x) #define A(x) (U(x)|G(x)|O(x)) #define CHRWE (CHREAD|CHWRITE|CHEXEC) int parsemode(char *, ulong *, ulong *); void main(int argc, char *argv[]) { int i; Dir dir; ulong mode, mask; char *p; char err[ERRLEN]; if(argc < 2){ fprint(2, "usage: chmod 0777 file ... or chmod [who]op[rwxal] file ...\n"); exits("usage"); } mode = strtol(argv[1], &p, 8); if(*p == 0) mask = A(CHRWE); else if(!parsemode(argv[1], &mask, &mode)){ fprint(2, "chmod: bad mode: %s\n", argv[1]); exits("mode"); } for(i=2; i