// Written by retoor@molodetz.nl

// This code provides a simple implementation of a reverse cat (rcat) function, which attempts to read a file in binary mode and outputs its
// contents to the standard output.

// No external libraries apart from the standard C library are used here.

// MIT License

#ifndef RCAT_H
#define RCAT_H

#include <stdio.h>
#include <stdlib.h>

void rcat(char *filename) {
    FILE *f = fopen(filename, "rb");
    if (!f) {
        printf("rcat: couldn't open \"%s\" for read.\n", filename);
        return;
    }
    unsigned char c;
    while ((c = fgetc(f)) != EOF) {
        printf("%c", c);
    }
    fclose(f);
    fflush(stdout);
}

int rcat_main(int argc, char *argv[]) {
    if (argc < 2) {
        printf("Usage: [filename]\n");
        return 1;
    }
    rcat(argv[1]);
    return 0;
}

#endif