From 261174c8c4cf41505b169e06cceeb0189c686172 Mon Sep 17 00:00:00 2001 From: EdwardEisenhauer Date: Wed, 3 Mar 2021 16:39:18 +0100 Subject: [PATCH] Basic functionality --- Topic-1/main.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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);