bc: convert to "G trick" - this returns bc to zero bss increase
[oweals/busybox.git] / coreutils / shred.c
index 9cd39b79cf42f85f63ee43b89e9ffbef6cfdd9d5..3ceb58d195628a9a4809e15061eb9ecb57cbce9c 100644 (file)
@@ -5,10 +5,10 @@
  * Licensed under GPLv2, see file LICENSE in this source tree.
  */
 //config:config SHRED
-//config:      bool "shred"
+//config:      bool "shred (5 kb)"
 //config:      default y
 //config:      help
-//config:        Overwrite a file to hide its contents, and optionally delete it
+//config:      Overwrite a file to hide its contents, and optionally delete it
 
 //applet:IF_SHRED(APPLET(shred, BB_DIR_USR_BIN, BB_SUID_DROP))
 
@@ -66,16 +66,21 @@ int shred_main(int argc UNUSED_PARAM, char **argv)
 
        for (;;) {
                struct stat sb;
+               const char *fname;
                unsigned i;
-               int fd = -1;
+               int fd;
 
+               fname = *argv++;
+               if (!fname)
+                       break;
+               fd = -1;
                if (opt & OPT_f) {
-                       fd = open(*argv, O_WRONLY);
+                       fd = open(fname, O_WRONLY);
                        if (fd < 0)
-                               chmod(*argv, 0666);
+                               chmod(fname, 0666);
                }
                if (fd < 0)
-                       fd = xopen(*argv, O_WRONLY);
+                       fd = xopen(fname, O_WRONLY);
 
                if (fstat(fd, &sb) == 0 && sb.st_size > 0) {
                        off_t size = sb.st_size;
@@ -91,13 +96,10 @@ int shred_main(int argc UNUSED_PARAM, char **argv)
                        }
                        if (opt & OPT_u) {
                                ftruncate(fd, 0);
-                               xunlink(*argv);
+                               xunlink(fname);
                        }
                        xclose(fd);
                }
-               argv++;
-               if (!*argv)
-                       break;
        }
 
        return EXIT_SUCCESS;