shred: smaller code
function old new delta shred_main 361 356 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
2f59bf39e2
commit
0f7f1ae094
@ -66,16 +66,21 @@ int shred_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
const char *fname;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
int fd = -1;
|
int fd;
|
||||||
|
|
||||||
|
fname = *argv++;
|
||||||
|
if (!fname)
|
||||||
|
break;
|
||||||
|
fd = -1;
|
||||||
if (opt & OPT_f) {
|
if (opt & OPT_f) {
|
||||||
fd = open(*argv, O_WRONLY);
|
fd = open(fname, O_WRONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
chmod(*argv, 0666);
|
chmod(fname, 0666);
|
||||||
}
|
}
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
fd = xopen(*argv, O_WRONLY);
|
fd = xopen(fname, O_WRONLY);
|
||||||
|
|
||||||
if (fstat(fd, &sb) == 0 && sb.st_size > 0) {
|
if (fstat(fd, &sb) == 0 && sb.st_size > 0) {
|
||||||
off_t size = sb.st_size;
|
off_t size = sb.st_size;
|
||||||
@ -91,13 +96,10 @@ int shred_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
}
|
}
|
||||||
if (opt & OPT_u) {
|
if (opt & OPT_u) {
|
||||||
ftruncate(fd, 0);
|
ftruncate(fd, 0);
|
||||||
xunlink(*argv);
|
xunlink(fname);
|
||||||
}
|
}
|
||||||
xclose(fd);
|
xclose(fd);
|
||||||
}
|
}
|
||||||
argv++;
|
|
||||||
if (!*argv)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user