k9core

Unnamed repository
Log | Files | Refs | LICENSE

commit 2996e211792b182410581bbcb0987d84f2063f90
parent 1d8f3bf01f5d159d605ac7b1378ff6a631f459d7
Author: qorg11 <qorg@vxempire.xyz>
Date:   Mon, 20 Jul 2020 22:51:35 +0200

cp now supports binary data and touch.c uses the saner
creat() instead of open() because using open() there was
simply stupid

Diffstat:
Msrc/cp.c | 28+++++++++++-----------------
Msrc/touch.c | 3+--
2 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/src/cp.c b/src/cp.c @@ -1,33 +1,27 @@ #include <stdio.h> +#include <unistd.h> +#include <fcntl.h> int copy(const char *src, const char *dst) { - FILE *source = fopen(src,"r"); - FILE *destination = fopen(dst,"w"); - if(destination == NULL) + int source = open(src,O_RDONLY); + int destination = creat(dst,0644); + + if(destination == -1) { printf("Error opening destination file\n"); return 1; } - if(source == NULL) + if(source == -1) { printf("Error opening source file\n"); return 1; } - - char c; - - while((c = fgetc(source)) > 0) - { - int value = fputc(c,destination); - if(value == -1) - { - printf("Error\n"); - return 1; - } - } - + int lines; + char buf[8912]; + while((lines = read(source,buf,sizeof(buf))) > 0) + write(destination,buf,lines); return 0; } diff --git a/src/touch.c b/src/touch.c @@ -12,14 +12,13 @@ main(int argc, char *argv[]) return 1; } - int fd = open(argv[1],O_RDWR|O_CREAT); + int fd = creat(argv[1],0644); if(fd == -1) { fprintf(stderr,"Error creating file\n"); return 1; } - chmod(argv[1],420); /* 644 in decimal */ close(fd); return 0; }