From 54f272ddb4511319d37a4498107e68b47ebeec5d Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 14 Oct 2024 23:09:47 +0200 Subject: [PATCH] Mon 14 Oct 23:09:15 CEST 2024 --- user/test/filedescribetest.c | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 user/test/filedescribetest.c diff --git a/user/test/filedescribetest.c b/user/test/filedescribetest.c new file mode 100644 index 0000000..e27452d --- /dev/null +++ b/user/test/filedescribetest.c @@ -0,0 +1,42 @@ +#include "library/errno.h" +#include "library/syscalls.h" +#include "library/string.h" +#include "library/user-io.h" +#include "library/malloc.h" + +#define TAG_BUFFER_SIZE 256 + +int main(int argc, char *argv[]) +{ + char *tag_value = "A simple tag string"; + + printf("Generating/typing all file descriptors.\n"); + int type = -2; + int tag = -3; + + int window_descriptor = syscall_open_window(KNO_STDWIN, 1, 1, 1, 1); + if(!window_descriptor) { + return 1; + } + + syscall_object_set_tag(window_descriptor, tag_value); + + int last_descriptor = syscall_object_max(); + printf("Highest allocated FD: %d\nLast Descriptor: %d\n", window_descriptor, last_descriptor); + + char *tag_string = malloc(sizeof(char) * TAG_BUFFER_SIZE); + + for(int descriptor = 0; descriptor <= last_descriptor; descriptor++) { + type = syscall_object_type(descriptor); + tag = syscall_object_get_tag(descriptor, tag_string, TAG_BUFFER_SIZE); + printf("FD: %d is of type: %d, with tag: ", descriptor, type); + if(tag != 0) { + printf("\"%s\"\n", tag_string); + } + if(tag == 0) { + printf("%d\n", tag); + } + } + + return 0; +}