summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/init/shell.c17
1 files changed, 17 insertions, 0 deletions
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");
}