File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change 2
2
#include "cache.h"
3
3
4
4
/*
5
- * Usage: test-tool cron <file> [-l]
5
+ * Usage: test-tool crontab <file> -l|<input>
6
6
*
7
7
* If -l is specified, then write the contents of <file> to stdout.
8
- * Otherwise, write from stdin into <file>.
8
+ * Otherwise, copy the contents of <input> into <file>.
9
9
*/
10
10
int cmd__crontab (int argc , const char * * argv )
11
11
{
12
12
int a ;
13
13
FILE * from , * to ;
14
14
15
- if (argc == 3 && !strcmp (argv [2 ], "-l" )) {
15
+ if (argc != 3 )
16
+ usage ("test-tool crontab <file> -l|<input>" );
17
+
18
+ if (!strcmp (argv [2 ], "-l" )) {
16
19
from = fopen (argv [1 ], "r" );
17
20
if (!from )
18
21
return 0 ;
19
22
to = stdout ;
20
- } else if (argc == 3 ) {
21
- from = fopen (argv [2 ], "r" );
22
- to = fopen (argv [1 ], "w" );
23
- } else
24
- return error ("unknown arguments" );
23
+ } else {
24
+ from = xfopen (argv [2 ], "r" );
25
+ to = xfopen (argv [1 ], "w" );
26
+ }
25
27
26
28
while ((a = fgetc (from )) != EOF )
27
29
fputc (a , to );
28
30
29
- if (argc == 3 )
30
- fclose (from );
31
- else
31
+ fclose (from );
32
+ if (to != stdout )
32
33
fclose (to );
33
34
34
35
return 0 ;
You can’t perform that action at this time.
0 commit comments