Untitled attachment
https://meds.lab.nyanide.com/media/f8/5c/8b/f85c8b8db135f36d4cf029d8791706b2b7263b6b0ebd825378b743e5dc72a009.png
@mir you do not need the length of the file nor do you need a buffer containing the entire file really, if you just want to print to stdout you could simplify down to these lines
#include <stdio.h> #include <unistd.h> void cat(char *filename) { FILE *fp = fopen(filename, "r"); char c; if (fp == NULL) { fprintf(stderr, "error: unable to open file\n"); _exit(-1); } while ((c = fgetc(fp)) != EOF) putchar(c); fclose(fp); } int main(int argc, char **argv) { if (argc <= 1) { fprintf(stderr, "error: no file specified\n"); _exit(-1); } for (int i = 1; i < argc; i++) cat(argv[i]); return 0; }
here's the implementation in action
GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.
All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.