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 22#include "cache.h"
33
44/*
5- * Usage: test-tool cron <file> [-l]
5+ * Usage: test-tool crontab <file> -l|<input>
66 *
77 * 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>.
99 */
1010int cmd__crontab (int argc , const char * * argv )
1111{
1212 int a ;
1313 FILE * from , * to ;
1414
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" )) {
1619 from = fopen (argv [1 ], "r" );
1720 if (!from )
1821 return 0 ;
1922 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+ }
2527
2628 while ((a = fgetc (from )) != EOF )
2729 fputc (a , to );
2830
29- if (argc == 3 )
30- fclose (from );
31- else
31+ fclose (from );
32+ if (to != stdout )
3233 fclose (to );
3334
3435 return 0 ;
You can’t perform that action at this time.
0 commit comments