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);
|
old = open(argv[1], O_RDONLY);
|
||||||
new = open(argv[2], O_CREAT | O_WRONLY);
|
new = open(argv[2], O_CREAT | O_WRONLY);
|
||||||
char buffer[BUFFER_SIZE];
|
char buffer[BUFFER_SIZE];
|
||||||
|
int read_bytes;
|
||||||
|
|
||||||
int read_bytes = read(old, buffer, sizeof(buffer));
|
while ((read_bytes = read(old, buffer, sizeof(buffer))) > 0) {
|
||||||
if (read_bytes < 0) {
|
|
||||||
fprintf(stderr, "There was a problem with reading a file!\n");
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
printf("%d bytes were read", read_bytes);
|
|
||||||
write(new, buffer, read_bytes);
|
write(new, buffer, read_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
close(old);
|
close(old);
|
||||||
close(new);
|
close(new);
|
||||||
|
Loading…
Reference in New Issue
Block a user