From d81c11b00ed62b76c528312f700e80289db14f91 Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 14 Oct 2024 23:09:46 +0200 Subject: [PATCH] Mon 14 Oct 23:09:15 CEST 2024 --- user/test/open.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 user/test/open.c diff --git a/user/test/open.c b/user/test/open.c new file mode 100644 index 0000000..0b80b59 --- /dev/null +++ b/user/test/open.c @@ -0,0 +1,31 @@ +/* +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/user-io.h" + +int main(int argc, char *argv[]) +{ + syscall_chdir("/"); + printf("got root\n"); + int dir_fd = syscall_open_file("/", 0, 0); + syscall_object_set_tag(dir_fd, "ROOT"); + printf("Opened root directory\n"); + int fd = syscall_open_file("ROOT:/data/words", 0, 0); + char buffer[1000]; + int n; + printf("reading file...\n"); + while((n = syscall_object_read(fd, buffer, 100)) > 0) { + buffer[n] = 0; + printf("%s", buffer); + flush(); + } + syscall_object_close(fd); + syscall_process_exit(0); + + return 0; +}