diff options
Diffstat (limited to 'coreutils/shred.c')
-rw-r--r-- | coreutils/shred.c | 18 |
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; |