summaryrefslogtreecommitdiff
path: root/t/helper/test-crontab.c
blob: e7c0137a4779ff005d3b440e1874d570a2d5d797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "test-tool.h"
#include "cache.h"

/*
 * Usage: test-tool cron <file> [-l]
 *
 * If -l is specified, then write the contents of <file> to stdout.
 * Otherwise, write from stdin into <file>.
 */
int cmd__crontab(int argc, const char **argv)
{
	int a;
	FILE *from, *to;

	if (argc == 3 && !strcmp(argv[2], "-l")) {
		from = fopen(argv[1], "r");
		if (!from)
			return 0;
		to = stdout;
	} else if (argc == 2) {
		from = stdin;
		to = fopen(argv[1], "w");
	} else
		return error("unknown arguments");

	while ((a = fgetc(from)) != EOF)
		fputc(a, to);

	if (argc == 3)
		fclose(from);
	else
		fclose(to);

	return 0;
}