diff options
Diffstat (limited to 'Userland/sh.cpp')
-rw-r--r-- | Userland/sh.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Userland/sh.cpp b/Userland/sh.cpp index 9a4706dc52..e20dbb9d1a 100644 --- a/Userland/sh.cpp +++ b/Userland/sh.cpp @@ -6,6 +6,7 @@ #include <LibC/stdlib.h> #include <LibC/utsname.h> #include <LibC/pwd.h> +#include <sys/mman.h> #include <signal.h> #include <AK/FileSystemPath.h> @@ -112,6 +113,32 @@ static int sh_wt(int, const char**) return 0; } +static int sh_mf(int, const char**) +{ + int rc; + int fd = open("/Banner.txt", O_RDONLY); + if (fd < 0) { + perror("open(/Banner.txt)"); + return 1; + } + printf("opened /Banner.txt, calling mmap...\n"); + byte* data = (byte*)mmap(nullptr, getpagesize(), PROT_READ, MAP_PRIVATE, fd, 0); + if (data == MAP_FAILED) { + perror("mmap()"); + goto close_it; + } + printf("mapped file @ %p\n", data); + printf("contents: %b %b %b %b\n", data[0], data[1], data[2], data[3]); + + rc = munmap(data, getpagesize()); + printf("munmap() returned %d\n", rc); + +close_it: + rc = close(fd); + printf("close() returned %d\n", rc); + return 0; +} + static int sh_exit(int, const char**) { printf("Good-bye!\n"); @@ -190,6 +217,10 @@ static bool handle_builtin(int argc, const char** argv, int& retval) retval = sh_wt(argc, argv); return true; } + if (!strcmp(argv[0], "mf")) { + retval = sh_mf(argc, argv); + return true; + } if (!strcmp(argv[0], "fork")) { retval = sh_fork(argc, argv); return true; |