aboutsummaryrefslogtreecommitdiff
path: root/test cases/common/207 tap tests/cat.c
blob: 4b92010adee7c05b3d917cb0f292df2a39c9b695 (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
#include <errno.h>
#include <stdio.h>

int main(int argc, char **argv) {
    char buf[1024];
    size_t len;
    FILE *fh;

    if (argc != 2) {
        fprintf(stderr, "Incorrect number of arguments, got %i\n", argc);
        return 1;
    }
    fh = fopen(argv[1], "r");
    if (fh == NULL) {
        fprintf(stderr, "Opening %s: errno=%i\n", argv[1], errno);
        return 1;
    }
    do {
        len = fread(buf, 1, sizeof(buf), fh);
        if (len > 0) {
            fwrite(buf, 1, len, stdout);
        }
    } while (len > 0);
    fclose(fh);
    return 0;
}