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

int main(int argc, char *argv[])
{
    FILE *f;
    int ch;

    openconsole(&dev_stdcon_r, &dev_stdcon_w);

    if (argc < 2) {
	fprintf(stderr, "Usage: cat.c32 filename\n");
	return 1;
    }

    f = fopen(argv[1], "r");
    if (!f) {
	fprintf(stderr, "File \"%s\" does not exist.\n", argv[1]);
	return 1;
    }

    while ((ch = getc(f)) != EOF)
	putchar(ch);

    fclose(f);

    return 0;
}