Home | History | Annotate | Download | only in toolbox
      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 #include <sys/types.h>
      5 #include <dirent.h>
      6 #include <errno.h>
      7 
      8 #include <unistd.h>
      9 #include <time.h>
     10 
     11 int chmod_main(int argc, char **argv)
     12 {
     13     int i;
     14 
     15     if (argc < 3) {
     16         fprintf(stderr, "Usage: chmod <MODE> <FILE>\n");
     17         return 10;
     18     }
     19 
     20     int mode = 0;
     21     const char* s = argv[1];
     22     while (*s) {
     23         if (*s >= '0' && *s <= '7') {
     24             mode = (mode<<3) | (*s-'0');
     25         }
     26         else {
     27             fprintf(stderr, "Bad mode\n");
     28             return 10;
     29         }
     30         s++;
     31     }
     32     for (i = 2; i < argc; i++) {
     33         if (chmod(argv[i], mode) < 0) {
     34             fprintf(stderr, "Unable to chmod %s: %s\n", argv[i], strerror(errno));
     35             return 10;
     36         }
     37     }
     38     return 0;
     39 }
     40 
     41