aboutsummaryrefslogtreecommitdiffstats
path: root/com32/modules/cat.c
blob: 2a7683f2708b075bc03b8055fc2b7b1151d72770 (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
#include <stdio.h>
#include <stdlib.h>
#include <console.h>

int main(int argc, char *argv[])
{
    FILE *f;
    int i;
    int len;
    char buf[4096];

    if (argc < 2) {
	fprintf(stderr, "Usage: %s filename...\n", argv[0]);
	return 1;
    }

    for (i = 1; i < argc; i++) {
	f = fopen(argv[i], "r");
	if (!f) {
	    fprintf(stderr, "%s: %s: file not found\n", argv[0], argv[i]);
	    return 1;
	}

	while ((len = fread(buf, 1, sizeof buf, f)) > 0)
	    fwrite(buf, 1, len, stdout);
	
	fclose(f);
    }

    return 0;
}