lineedit: do not hang on error, but return error indicator.
[oweals/busybox.git] / coreutils / chmod.c
index aa36258772d9cd71e2cfe21e5a4508c43769925e..f07a49bd3b0922efae9865d98fa875aefcb8123e 100644 (file)
@@ -7,23 +7,23 @@
  * Reworked by (C) 2002 Vladimir Oleynik <dzo@simtreas.ru>
  *  to correctly parse '-rwxgoa'
  *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
 /* BB_AUDIT SUSv3 compliant */
 /* BB_AUDIT GNU defects - unsupported long options. */
 /* http://www.opengroup.org/onlinepubs/007904975/utilities/chmod.html */
 
-#include "busybox.h"
+#include "libbb.h"
 
 /* This is a NOEXEC applet. Be very careful! */
 
 
 #define OPT_RECURSE (option_mask32 & 1)
-#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 2) SKIP_DESKTOP(0))
-#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 4) SKIP_DESKTOP(0))
-#define OPT_QUIET   (USE_DESKTOP(option_mask32 & 8) SKIP_DESKTOP(0))
-#define OPT_STR     "R" USE_DESKTOP("vcf")
+#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")
 
 /* coreutils:
  * chmod never changes the permissions of symbolic links; the chmod
@@ -34,7 +34,7 @@
  * symbolic links encountered during recursive directory traversals.
  */
 
-static int fileAction(const char *fileName, struct stat *statbuf, void* param, int depth)
+static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, void* param, int depth)
 {
        mode_t newmode;
 
@@ -50,7 +50,7 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* param, i
        newmode = statbuf->st_mode;
 
        if (!bb_parse_mode((char *)param, &newmode))
-               bb_error_msg_and_die("invalid mode: %s", (char *)param);
+               bb_error_msg_and_die("invalid mode '%s'", (char *)param);
 
        if (chmod(fileName, newmode) == 0) {
                if (OPT_VERBOSE
@@ -63,12 +63,12 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* param, i
        }
  err:
        if (!OPT_QUIET)
-               bb_perror_msg("%s", fileName);
+               bb_simple_perror_msg(fileName);
        return FALSE;
 }
 
-int chmod_main(int argc, char **argv);
-int chmod_main(int argc, char **argv)
+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;
@@ -93,7 +93,7 @@ int chmod_main(int argc, char **argv)
 
        /* Parse options */
        opt_complementary = "-2";
-       getopt32(argc, argv, ("-"OPT_STR) + 1); /* Reuse string */
+       getopt32(argv, ("-"OPT_STR) + 1); /* Reuse string */
        argv += optind;
 
        /* Restore option-like mode if needed */