diff --git a/Topic-1/main.c b/Topic-1/main.c index a2ea912..a33bec6 100644 --- a/Topic-1/main.c +++ b/Topic-1/main.c @@ -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; + while ((read_bytes = read(old, buffer, sizeof(buffer))) > 0) { + write(new, buffer, read_bytes); } - printf("%d bytes were read", read_bytes); - write(new, buffer, read_bytes); close(old); close(new);