ScrapExplorer - cp.c
Home / usr / light_builtins Lines: 2 | Size: 1447 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* Light builtins's (C version) 2 * cp - copy files and directories 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#include <sys/stat.h> 13#include <sys/types.h> 14 15#include "config.h" 16 17int main(int argc, char *argv[]) { 18 if (argc >= 2 && 19 (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) { 20 printf("Light Builtins (C) %d.%d.%d-%s\n", VERSION_MAJOR, VERSION_MINOR, 21 VERSION_PATCH, EXTRA_VERSION); 22 return 0; 23 } 24 FILE *fp1, *fp2; 25 int c; 26 char *file1, *file2; 27 28 if (argc == 1) { 29 printf("cp: usage: cp [file1] [file2]"); 30 exit(1); 31 } else if (argc == 2) { 32 printf("cp: usage: cp [file1] [file2]"); 33 exit(1); 34 } else if (argc == 3) { 35 file1 = argv[1]; 36 file2 = argv[2]; 37 if ((fp1 = fopen(file1, "r")) == NULL) { 38 printf("cp: can't open %s", file1); 39 exit(1); 40 } else if ((fp2 = fopen(file2, "w")) == NULL) { 41 printf("cp: can't open %s", file2); 42 exit(1); 43 } else { 44 while ((c = getc(fp1)) != EOF) { 45 putc(c, fp2); 46 } 47 fclose(fp1); 48 fclose(fp2); 49 } 50 } 51 return 0; 52}[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.