diff options
author | dzwdz | 2022-05-01 18:35:18 +0200 |
---|---|---|
committer | dzwdz | 2022-05-01 18:35:18 +0200 |
commit | 935eccb23be9464091ea0f6be3873c6450ff040c (patch) | |
tree | 592be8e676b79254e891ad90a17cf83743ff51cf /src/init | |
parent | cad354b671cc7fa783a3fd0631a0f85c40b69a0c (diff) |
init/cat: read files until EOF
Diffstat (limited to 'src/init')
-rw-r--r-- | src/init/shell.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/init/shell.c b/src/init/shell.c index 6314721..7714c38 100644 --- a/src/init/shell.c +++ b/src/init/shell.c @@ -48,6 +48,7 @@ static void cmd_cat_ls(const char *args, bool ls) { int fd; static char buf[512]; int len; // first used for strlen(args), then length of buffer + size_t pos = 0; if (!args) args = "/"; len = strlen(args); @@ -69,17 +70,23 @@ static void cmd_cat_ls(const char *args, bool ls) { return; } - len = _syscall_read(fd, buf, sizeof buf, 0); - if (ls) - for (int i = 0; i < len; i++) - if (buf[i] == '\0') buf[i] = '\n'; + while (true) { + len = _syscall_read(fd, buf, sizeof buf, pos); + if (len <= 0) break; + pos += len; + + if (ls) { + for (int i = 0; i < len; i++) + if (buf[i] == '\0') buf[i] = '\n'; + } + _syscall_write(__stdout, buf, len, 0); + } - _syscall_write(__stdout, buf, len, 0); _syscall_close(fd); } static void cmd_hexdump(const char *args) { - static uint8_t buf[513]; + static uint8_t buf[512]; int fd, len; fd = _syscall_open(args, strlen(args)); |