From 99e15199ef24d4f262683b47a529f1b239c4dcd9 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Fri, 5 Aug 2022 15:54:32 +0200 Subject: add _syscall_getsize --- src/user/app/shell/builtins.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/user/app/shell') diff --git a/src/user/app/shell/builtins.c b/src/user/app/shell/builtins.c index d409bfd..53534ed 100644 --- a/src/user/app/shell/builtins.c +++ b/src/user/app/shell/builtins.c @@ -48,6 +48,23 @@ static void cmd_echo(int argc, char **argv) { printf("\n"); } +void cmd_getsize(int argc, char **argv) { + if (argc < 2) { + eprintf("missing arguments"); + return; + } + + for (int i = 1; i < argc; i++) { + handle_t h = _syscall_open(argv[i], strlen(argv[i]), 0); + if (h < 0) { + eprintf("error opening %s", argv[i]); + continue; + } + printf("%s: %d\n", argv[i], (int)_syscall_getsize(h)); + _syscall_close(h); + } +} + void cmd_hexdump(int argc, char **argv) { const size_t buflen = 512; uint8_t *buf = malloc(buflen); @@ -141,6 +158,7 @@ static void cmd_touch(int argc, char **argv) { struct builtin builtins[] = { {"cat", cmd_cat}, {"echo", cmd_echo}, + {"getsize", cmd_getsize}, {"hexdump", cmd_hexdump}, {"ls", cmd_ls}, {"sleep", cmd_sleep}, -- cgit v1.2.3