Merge branch 'ds/maintenance-part-3'
[git] / t / helper / test-crontab.c
1 #include "test-tool.h"
2 #include "cache.h"
3
4 /*
5  * Usage: test-tool cron <file> [-l]
6  *
7  * If -l is specified, then write the contents of <file> to stdout.
8  * Otherwise, write from stdin into <file>.
9  */
10 int cmd__crontab(int argc, const char **argv)
11 {
12         int a;
13         FILE *from, *to;
14
15         if (argc == 3 && !strcmp(argv[2], "-l")) {
16                 from = fopen(argv[1], "r");
17                 if (!from)
18                         return 0;
19                 to = stdout;
20         } else if (argc == 2) {
21                 from = stdin;
22                 to = fopen(argv[1], "w");
23         } else
24                 return error("unknown arguments");
25
26         while ((a = fgetc(from)) != EOF)
27                 fputc(a, to);
28
29         if (argc == 3)
30                 fclose(from);
31         else
32                 fclose(to);
33
34         return 0;
35 }