claenups for previous commit
[oweals/busybox.git] / coreutils / truncate.c
index e5fa656c8e623f5a1c145651c2acc39927328ff0..f693570aa1ba55f35203343932475c87e7d610b0 100644 (file)
@@ -5,17 +5,17 @@
  *
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
-
 //config:config TRUNCATE
-//config:      bool "truncate"
+//config:      bool "truncate (4.7 kb)"
 //config:      default y
 //config:      help
-//config:        truncate truncates files to a given size. If a file does
-//config:        not exist, it is created unless told otherwise.
+//config:      truncate truncates files to a given size. If a file does
+//config:      not exist, it is created unless told otherwise.
 
-//kbuild:lib-$(CONFIG_TRUNCATE) += truncate.o
 //applet:IF_TRUNCATE(APPLET_NOFORK(truncate, truncate, BB_DIR_USR_BIN, BB_SUID_DROP, truncate))
 
+//kbuild:lib-$(CONFIG_TRUNCATE) += truncate.o
+
 //usage:#define truncate_trivial_usage
 //usage:       "[-c] -s SIZE FILE..."
 //usage:#define truncate_full_usage "\n\n"
@@ -40,7 +40,7 @@ int truncate_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int truncate_main(int argc UNUSED_PARAM, char **argv)
 {
        unsigned opts;
-       int flags = O_RDWR;
+       int flags = O_WRONLY | O_NONBLOCK;
        int ret = EXIT_SUCCESS;
        char *size_str;
        off_t size;
@@ -50,8 +50,7 @@ int truncate_main(int argc UNUSED_PARAM, char **argv)
                OPT_SIZE = (1 << 1),
        };
 
-       opt_complementary = "s:-1";
-       opts = getopt32(argv, "cs:", &size_str);
+       opts = getopt32(argv, "^" "cs:" "\0" "s:-1", &size_str);
 
        if (!(opts & OPT_NOCREATE))
                flags |= O_CREAT;
@@ -64,7 +63,7 @@ int truncate_main(int argc UNUSED_PARAM, char **argv)
 
        argv += optind;
        while (*argv) {
-               int fd = open(*argv, flags);
+               int fd = open(*argv, flags, 0666);
                if (fd < 0) {
                        if (errno != ENOENT || !(opts & OPT_NOCREATE)) {
                                bb_perror_msg("%s: open", *argv);