From 05e8d17929460825ac9415112bfa930fb9f53a7d Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 14 Oct 2024 23:10:01 +0200 Subject: [PATCH] Mon 14 Oct 23:09:15 CEST 2024 --- user/copy.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 user/copy.c diff --git a/user/copy.c b/user/copy.c new file mode 100644 index 0000000..7339bec --- /dev/null +++ b/user/copy.c @@ -0,0 +1,39 @@ +/* +Copyright (C) 2016-2019 The University of Notre Dame +This software is distributed under the GNU General Public License. +See the file LICENSE for details. +*/ + +#include "library/syscalls.h" +#include "library/string.h" +#include "library/errno.h" + +int main(int argc, char *argv[]) +{ + if(argc!=3) { + printf("%s: \n",argv[0]); + return 1; + } + + int src = syscall_open_file(KNO_STDDIR,argv[1],0,0); + if(src<0) { + printf("couldn't open %s: %s\n",argv[1],strerror(src)); + return 1; + } + + int dst = syscall_open_file(KNO_STDDIR,argv[2],0,0); + if(dst<0) { + printf("couldn't open %s: %s\n",argv[2],strerror(dst)); + return 1; + } + + printf("copying %s to %s...\n",argv[1],argv[2]); + int result = syscall_object_copy(src,dst); + if(result<0) { + printf("copy failed: %s\n",strerror(result)); + return 1; + } + + printf("copy complete\n"); + return 0; +}