commit 9ff8b1f2c9ac45e6b1f3184278a1faa1c0362e9f
parent bf294b1ffe58f2412d592f2e099b73ce0c7daa83
Author: sin <sin@2f30.org>
Date: Wed, 21 Mar 2018 14:04:43 +0000
Parse input/output file from command line as well
Diffstat:
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/dedup.c b/dedup.c
@@ -343,7 +343,7 @@ extract(char *id, int fd)
if (ent->blks[j] > nblks)
errx(1, "index is corrupted");
read_blk(&blk, ent->blks[j]);
- xwrite(1, blk.data, blk.sz);
+ xwrite(fd, blk.data, blk.sz);
}
break;
}
@@ -494,7 +494,7 @@ list(void)
void
usage(void)
{
- fprintf(stderr, "usage: %s [-clv] [-e id]\n", argv0);
+ fprintf(stderr, "usage: %s [-clv] [-e id] [file]\n", argv0);
exit(1);
}
@@ -502,7 +502,7 @@ int
main(int argc, char *argv[])
{
char *id = NULL;
- int lflag = 0, cflag = 0;
+ int fd = -1, lflag = 0, cflag = 0;
ARGBEGIN {
case 'c':
@@ -521,6 +521,9 @@ main(int argc, char *argv[])
usage();
} ARGEND
+ if (argc > 1)
+ usage();
+
init();
if (cflag) {
@@ -533,10 +536,16 @@ main(int argc, char *argv[])
return 0;
}
+ if (argc == 1) {
+ fd = open(argv[0], O_RDWR | O_CREAT, 0600);
+ if (fd == -1)
+ err(1, "open %s", argv[0]);
+ }
+
if (id)
- extract(id, 0);
+ extract(id, fd == -1 ? 0 : fd);
else
- dedup(0);
+ dedup(fd == -1 ? 0 : fd);
term();
}