config SHRED
bool "shred"
- default n
+ default y
help
usage: shred [-fuz] [-n COUNT] [-s SIZE] FILE...
char **try;
if (!(toys.optflags & FLAG_n)) TT.iterations++;
- TT.ufd = xopen("/dev/urandom", O_RDONLY);
+ TT.ufd = xopenro("/dev/urandom");
// We don't use loopfiles() here because "-" isn't stdin, and want to
// respond to files we can't open via chmod.
fd = open(*try, O_RDWR);
}
if (fd == -1) {
- perror_msg("%s", *try);
+ perror_msg_raw(*try);
continue;
}
if (pos < TT.offset) {
if (TT.offset != lseek(fd, TT.offset, SEEK_SET)) {
- perror_msg("%s", *try);
+ perror_msg_raw(*try);
break;
}
pos = TT.offset;
if (len-pos < throw) throw = len-pos;
if (iter != TT.iterations) xread(TT.ufd, toybuf, throw);
- if (throw != writeall(fd, toybuf, throw)) perror_msg("%s");
+ if (throw != writeall(fd, toybuf, throw)) perror_msg_raw(*try);
pos += throw;
}
+ if (toys.optflags & FLAG_u)
+ if (unlink(*try)) perror_msg("unlink '%s'", *try);
}
}