aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-04-07 21:10:00 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-04-07 21:10:00 +0200
commit0f7f1ae094f4124303aca58f4efa69da4e2831a6 (patch)
tree8de39334ea5dacd81a400db25b170eb2590a98f7 /coreutils
parent2f59bf39e2ea6fb4c3ed3e74ea113a521e1a3558 (diff)
downloadbusybox-w32-0f7f1ae094f4124303aca58f4efa69da4e2831a6.tar.gz
busybox-w32-0f7f1ae094f4124303aca58f4efa69da4e2831a6.tar.bz2
busybox-w32-0f7f1ae094f4124303aca58f4efa69da4e2831a6.zip
shred: smaller code
function old new delta shred_main 361 356 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/shred.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/coreutils/shred.c b/coreutils/shred.c
index 9cd39b79c..b3c009539 100644
--- a/coreutils/shred.c
+++ b/coreutils/shred.c
@@ -66,16 +66,21 @@ int shred_main(int argc UNUSED_PARAM, char **argv)
66 66
67 for (;;) { 67 for (;;) {
68 struct stat sb; 68 struct stat sb;
69 const char *fname;
69 unsigned i; 70 unsigned i;
70 int fd = -1; 71 int fd;
71 72
73 fname = *argv++;
74 if (!fname)
75 break;
76 fd = -1;
72 if (opt & OPT_f) { 77 if (opt & OPT_f) {
73 fd = open(*argv, O_WRONLY); 78 fd = open(fname, O_WRONLY);
74 if (fd < 0) 79 if (fd < 0)
75 chmod(*argv, 0666); 80 chmod(fname, 0666);
76 } 81 }
77 if (fd < 0) 82 if (fd < 0)
78 fd = xopen(*argv, O_WRONLY); 83 fd = xopen(fname, O_WRONLY);
79 84
80 if (fstat(fd, &sb) == 0 && sb.st_size > 0) { 85 if (fstat(fd, &sb) == 0 && sb.st_size > 0) {
81 off_t size = sb.st_size; 86 off_t size = sb.st_size;
@@ -91,13 +96,10 @@ int shred_main(int argc UNUSED_PARAM, char **argv)
91 } 96 }
92 if (opt & OPT_u) { 97 if (opt & OPT_u) {
93 ftruncate(fd, 0); 98 ftruncate(fd, 0);
94 xunlink(*argv); 99 xunlink(fname);
95 } 100 }
96 xclose(fd); 101 xclose(fd);
97 } 102 }
98 argv++;
99 if (!*argv)
100 break;
101 } 103 }
102 104
103 return EXIT_SUCCESS; 105 return EXIT_SUCCESS;