From a594346d7e2ca97717cae7e705c00d6fe0b9a460 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 2 Dec 2023 18:10:23 +0200 Subject: [SP/P01] Solved exercises from first practice (again) --- Year 3/System programming/Practice01/ex1-cp.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Year 3/System programming/Practice01/ex1-cp.c (limited to 'Year 3/System programming/Practice01/ex1-cp.c') diff --git a/Year 3/System programming/Practice01/ex1-cp.c b/Year 3/System programming/Practice01/ex1-cp.c new file mode 100644 index 0000000..ff39983 --- /dev/null +++ b/Year 3/System programming/Practice01/ex1-cp.c @@ -0,0 +1,25 @@ +#include // open, close, O_RDONLY, ... +#include // perror +#include // read, write + +int main(int argc, char* argv[]) { + int f1 = open(argv[1], O_RDONLY); + if (f1 < 0) { + perror("open"); + return 1; + } + + int f2 = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0755); + if (f2 < 0) { + perror("open"); + return 2; + } + + char buf; + while(read(f1, &buf, 1)) { + write(f2, &buf, 1); + } + + close(f1); + close(f2); +} -- cgit v1.3.1-26-gb76a