]>
Commit | Line | Data |
---|---|---|
2fec604f | 1 | #include "test-tool.h" |
2fec604f DS |
2 | |
3 | /* | |
0682bc43 | 4 | * Usage: test-tool crontab <file> -l|<input> |
2fec604f DS |
5 | * |
6 | * If -l is specified, then write the contents of <file> to stdout. | |
0682bc43 | 7 | * Otherwise, copy the contents of <input> into <file>. |
2fec604f DS |
8 | */ |
9 | int cmd__crontab(int argc, const char **argv) | |
10 | { | |
11 | int a; | |
12 | FILE *from, *to; | |
13 | ||
0682bc43 JK |
14 | if (argc != 3) |
15 | usage("test-tool crontab <file> -l|<input>"); | |
16 | ||
17 | if (!strcmp(argv[2], "-l")) { | |
2fec604f DS |
18 | from = fopen(argv[1], "r"); |
19 | if (!from) | |
20 | return 0; | |
21 | to = stdout; | |
0682bc43 JK |
22 | } else { |
23 | from = xfopen(argv[2], "r"); | |
24 | to = xfopen(argv[1], "w"); | |
25 | } | |
2fec604f DS |
26 | |
27 | while ((a = fgetc(from)) != EOF) | |
28 | fputc(a, to); | |
29 | ||
0682bc43 JK |
30 | fclose(from); |
31 | if (to != stdout) | |
2fec604f DS |
32 | fclose(to); |
33 | ||
34 | return 0; | |
35 | } |