From 7fac2a75260699b57c539616d3b9ada5a1e4c4d3 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 25 Apr 2023 14:50:26 +0300 Subject: [PATCH] Userspace: Simple stdio test --- userspace/test.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/userspace/test.c b/userspace/test.c index 722ac1da..ef1c60a0 100644 --- a/userspace/test.c +++ b/userspace/test.c @@ -2,7 +2,32 @@ int main() { - if (printf("Hello %s!", "World") == -1) - perror(NULL); + FILE* fp = fopen("/boot/grub/grub.cfg", "r"); + if (fp == NULL) + { + perror("fopen"); + return 1; + } + + for (;;) + { + char buffer[128]; + size_t nread = fread(buffer, 1, sizeof(buffer) - 1, fp); + if (nread == 0) + { + if (ferror(fp)) + perror("fread"); + break; + } + buffer[nread] = '\0'; + fputs(buffer, stdout); + } + + if (fclose(fp) == EOF) + { + perror("fclose"); + return 1; + } + return 0; }