39 lines
834 B
C
Raw Normal View History

// 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
2025-01-14 18:53:15 +01:00
#ifndef RCAT_H
#define RCAT_H
2025-01-14 18:53:15 +01:00
#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) {
2025-01-14 18:53:15 +01:00
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