commit 52a44f3afc6ec4a267e5c2f8956dc79bc4556c64
parent c6c4b61fb79e1db9be92837626609ea676dcdaff
Author: aabacchus <ben@bvnf.space>
Date: Tue, 14 Sep 2021 17:23:45 +0100
shred: use optind
so that we don't shred a file called '-u' if the flag is used
Diffstat:
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/shred.c b/src/shred.c
@@ -38,12 +38,13 @@ main(int argc, char *argv[])
{
int c = getopt(argc, argv, "u"); /* TODO: add -f */
- if(fill_with_zeroes(argv[1]) != 0) {
+ if(fill_with_zeroes(argv[optind]) != 0) {
return 1;
}
if(c == 'u')
- if(remove(argv[1]) == -1) {
- fprintf(stderr, "shred: %s: %s\n", argv[1], strerror(errno));
+ if(remove(argv[optind]) == -1) {
+ fprintf(
+ stderr, "shred: %s: %s\n", argv[optind], strerror(errno));
return 1;
}
return 0;