terminate prematurely when target disk is full
[rofl0r-filesync.git] / rmlist.c
blobff194d7381222e4b9db2eb5e2d9b480bb2d470f3
1 #include <stdio.h>
2 #include <string.h>
3 #include <errno.h>
5 static int usage(const char *argv0) {
6 dprintf(2,
7 "usage: %s file\n\n"
8 "all filenames inside file will be deleted\n"
9 "filename may be '-' to indicate stdin\n", argv0);
10 return 1;
13 int main(int argc, char** argv) {
14 if(argc != 2) return usage(argv[0]);
15 char buf[2048];
16 FILE *f;
17 if(!strcmp(argv[1], "-")) f = stdin;
18 else f = fopen(argv[1], "r");
19 if(!f) {
20 perror("fopen");
21 return 1;
23 while(fgets(buf, sizeof buf, f)) {
24 char *p = strrchr(buf, '\n');
25 if(!p) {
26 dprintf(2, "error: line too long: %s\n", buf);
27 continue;
29 *p = 0;
30 if(remove(buf) != 0) {
31 dprintf(2, "error: %s (%s)\n", strerror(errno), buf);
32 } else {
33 printf("removed %s\n", buf);
36 if(f != stdin) fclose(f);
37 return 0;