123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #include "libbb.h"
- #define OPT_RECURSE (option_mask32 & 1)
- #define OPT_VERBOSE (IF_DESKTOP(option_mask32 & 2) IF_NOT_DESKTOP(0))
- #define OPT_CHANGED (IF_DESKTOP(option_mask32 & 4) IF_NOT_DESKTOP(0))
- #define OPT_QUIET (IF_DESKTOP(option_mask32 & 8) IF_NOT_DESKTOP(0))
- #define OPT_STR "R" IF_DESKTOP("vcf")
- static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, void* param, int depth)
- {
- mode_t newmode;
-
- if (depth == 0) {
-
- if (stat(fileName, statbuf))
- goto err;
- } else {
- if (S_ISLNK(statbuf->st_mode))
- return TRUE;
- }
- newmode = bb_parse_mode((char *)param, statbuf->st_mode);
- if (newmode == (mode_t)-1)
- bb_error_msg_and_die("invalid mode '%s'", (char *)param);
- if (chmod(fileName, newmode) == 0) {
- if (OPT_VERBOSE
- || (OPT_CHANGED && statbuf->st_mode != newmode)
- ) {
- printf("mode of '%s' changed to %04o (%s)\n", fileName,
- newmode & 07777, bb_mode_string(newmode)+1);
- }
- return TRUE;
- }
- err:
- if (!OPT_QUIET)
- bb_simple_perror_msg(fileName);
- return FALSE;
- }
- int chmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
- int chmod_main(int argc UNUSED_PARAM, char **argv)
- {
- int retval = EXIT_SUCCESS;
- char *arg, **argp;
- char *smode;
-
- argp = argv;
- while ((arg = *++argp)) {
-
-
- if (arg[0] != '-') {
- arg = NULL;
- break;
- }
-
- if (arg[1] && !strchr("-"OPT_STR, arg[1])) {
- arg[0] = 'a';
- break;
- }
- }
-
- opt_complementary = "-2";
- getopt32(argv, ("-"OPT_STR) + 1);
- argv += optind;
-
- if (arg) arg[0] = '-';
-
- smode = *argv++;
- do {
- if (!recursive_action(*argv,
- OPT_RECURSE,
- fileAction,
- fileAction,
- smode,
- 0)
- ) {
- retval = EXIT_FAILURE;
- }
- } while (*++argv);
- return retval;
- }
|