Basic functionality

This commit is contained in:
Sergiusz Warga 2021-03-03 16:39:18 +01:00
parent f621349ca7
commit 261174c8c4

View File

@ -30,14 +30,11 @@ int cp(char *argv[]){
old = open(argv[1], O_RDONLY);
new = open(argv[2], O_CREAT | O_WRONLY);
char buffer[BUFFER_SIZE];
int read_bytes;
int read_bytes = read(old, buffer, sizeof(buffer));
if (read_bytes < 0) {
fprintf(stderr, "There was a problem with reading a file!\n");
return 3;
}
printf("%d bytes were read", read_bytes);
while ((read_bytes = read(old, buffer, sizeof(buffer))) > 0) {
write(new, buffer, read_bytes);
}
close(old);
close(new);