ntpd: default to FEATURE_NTP_AUTH=y
[oweals/busybox.git] / coreutils / chmod.c
index 0bcd6bb66a0d0cd236c55b4905af1e8d7ef47ad8..88989bf674b6530c338069b587ff846fa28ea4a8 100644 (file)
@@ -9,6 +9,15 @@
  *
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
+//config:config CHMOD
+//config:      bool "chmod (5.1 kb)"
+//config:      default y
+//config:      help
+//config:      chmod is used to change the access permission of files.
+
+//applet:IF_CHMOD(APPLET_NOEXEC(chmod, chmod, BB_DIR_BIN, BB_SUID_DROP, chmod))
+
+//kbuild:lib-$(CONFIG_CHMOD) += chmod.o
 
 /* BB_AUDIT SUSv3 compliant */
 /* BB_AUDIT GNU defects - unsupported long options. */
@@ -19,7 +28,6 @@
 //usage:#define chmod_full_usage "\n\n"
 //usage:       "Each MODE is one or more of the letters ugoa, one of the\n"
 //usage:       "symbols +-= and one or more of the letters rwxst\n"
-//usage:     "\nOptions:"
 //usage:     "\n       -R      Recurse"
 //usage:       IF_DESKTOP(
 //usage:     "\n       -c      List changed files"
@@ -70,9 +78,9 @@ static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, void
                if (S_ISLNK(statbuf->st_mode))
                        return TRUE;
        }
-       newmode = statbuf->st_mode;
 
-       if (!bb_parse_mode((char *)param, &newmode))
+       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) {
@@ -115,8 +123,7 @@ int chmod_main(int argc UNUSED_PARAM, char **argv)
        }
 
        /* Parse options */
-       opt_complementary = "-2";
-       getopt32(argv, ("-"OPT_STR) + 1); /* Reuse string */
+       getopt32(argv, "^" OPT_STR "\0" "-2");
        argv += optind;
 
        /* Restore option-like mode if needed */