From 9b775a39c921e352eef21f8ca3a101edb66ff610 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 10 Oct 2021 15:50:47 +0000 Subject: init/shell: implement a half-broken cat --- src/init/shell.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/init') diff --git a/src/init/shell.c b/src/init/shell.c index a43bd20..12ec5f6 100644 --- a/src/init/shell.c +++ b/src/init/shell.c @@ -45,6 +45,21 @@ static int readline(char *buf, size_t max) { return -1; // error } +static void cmd_cat(const char *args) { + int fd = _syscall_open(args, strlen(args)); + static char buf[256]; + int len = 256; + + if (fd < 0) { + printf("couldn't open.\n"); + return; + } + + len = _syscall_read(fd, buf, len, 0); + _syscall_write(tty_fd, buf, len, 0); + _syscall_close(fd); +} + void shell_loop(void) { static char cmd[256]; char *args; @@ -55,6 +70,8 @@ void shell_loop(void) { args = split(cmd); if (!strcmp(cmd, "echo")) { printf("%s\n", args); + } else if (!strcmp(cmd, "cat")) { + cmd_cat(args); } else { printf("unknown command :(\n"); } -- cgit v1.2.3