Basic functionality
This commit is contained in:
parent
f621349ca7
commit
261174c8c4
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user