diff options
author | dzwdz | 2022-08-05 15:54:32 +0200 |
---|---|---|
committer | dzwdz | 2022-08-05 15:54:32 +0200 |
commit | 99e15199ef24d4f262683b47a529f1b239c4dcd9 (patch) | |
tree | 7d4514964c91fc1c46da39cb830fdec165166730 /src/user/app/shell | |
parent | 0f3c70649a3d8035b0c0f9658705505948b2c60a (diff) |
add _syscall_getsize
Diffstat (limited to 'src/user/app/shell')
-rw-r--r-- | src/user/app/shell/builtins.c | 18 |
1 files changed, 18 insertions, 0 deletions
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}, |