summaryrefslogtreecommitdiff
path: root/src/user/app
diff options
context:
space:
mode:
authordzwdz2022-07-14 17:23:50 +0200
committerdzwdz2022-07-14 17:23:50 +0200
commitc5ad54a55123582b09f9d9d8046623916c2dec4a (patch)
tree0945ecd0d2fbd454504fa15ee5f5db76b2194785 /src/user/app
parent22a3e004cdf41cb3a48d9087f8bf87e56cc4cbe9 (diff)
user/shell/cat: support reading from stdin until eof
Diffstat (limited to 'src/user/app')
-rw-r--r--src/user/app/shell.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/user/app/shell.c b/src/user/app/shell.c
index 3a08af4..952b9b7 100644
--- a/src/user/app/shell.c
+++ b/src/user/app/shell.c
@@ -46,21 +46,24 @@ static void cmd_cat_ls(const char *args, bool ls) {
static char buf[512];
int len; // first used for strlen(args), then length of buffer
- if (!args) args = "/";
- len = strlen(args);
- memcpy(buf, args, len + 1); // no overflow check - the shell is just a PoC
-
- if (ls) { // paths to directories always have a trailing slash
- char *p = buf;
- while (*p) p++;
- if (p[-1] != '/') {
- p[0] = '/';
- p[1] = '\0';
- len++;
+ if (args) {
+ len = strlen(args);
+ memcpy(buf, args, len + 1); // no overflow check - the shell is just a PoC
+
+ if (ls) { // paths to directories always have a trailing slash
+ if (buf[len-1] != '/') {
+ buf[len] = '/';
+ buf[len+1] = '\0';
+ }
}
+
+ file = file_open(buf, 0);
+ } else if (ls) { /* ls default argument */
+ file = file_open("/", 0);
+ } else { /* cat default argument */
+ file = file_clone(stdin);
}
- file = file_open(buf, 0);
if (!file) {
printf("couldn't open.\n");
return;