summaryrefslogtreecommitdiff
path: root/src/init
diff options
context:
space:
mode:
authordzwdz2021-10-10 15:50:47 +0000
committerdzwdz2021-10-10 15:50:47 +0000
commit9b775a39c921e352eef21f8ca3a101edb66ff610 (patch)
treea675d2d35fa62520fe846c8de836b3fac22bba2b /src/init
parentda69044a4654d86bada80eb1c09b6bf85f34f6a5 (diff)
init/shell: implement a half-broken cat
Diffstat (limited to 'src/init')
-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");
}