ScrapExplorer - cat.c

Home / usr / light_builtins Lines: 4 | Size: 1092 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* Light builtins's (C version) 2 * cat - concatenate files and print on the standard output 3 * A lightweight repository of useful shell commands 4 * GitHub: https://www.github.com/0x4248/light_builtins 5 * Licence: GNU General Public License v3.0 6 * By: 0x4248 7 */ 8 9#include <stdio.h> 10#include <stdlib.h> 11#include <string.h> 12 13#include "config.h" 14 15int main(int argc, char *argv[]) { 16 if (argc >= 2 && 17 (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) { 18 printf("Light Builtins (C) %d.%d.%d-%s\n", VERSION_MAJOR, VERSION_MINOR, 19 VERSION_PATCH, EXTRA_VERSION); 20 return 0; 21 } 22 FILE *fp; 23 int c; 24 25 if (argc == 1) { 26 printf("cat: usage: cat [file ...]\n"); 27 exit(1); 28 } 29 while (--argc > 0) { 30 if ((fp = fopen(*++argv, "r")) == NULL) { 31 printf("cat: can't open %s\n", *argv); 32 exit(1); 33 } else { 34 while ((c = getc(fp)) != EOF) { 35 putchar(c); 36 } 37 fclose(fp); 38 } 39 } 40 return 0; 41}
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.