From 05f93a814a9b5fa6b0f3223fc51566c84b92d158 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Fri, 19 Aug 2022 15:37:42 +0200 Subject: user/libc: fextflags, add nonbuffering mode for fread useful for e.g. `hexdump -r /kdev/eth` to see packets as they come in --- src/user/app/shell/builtins.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/user/app/shell') diff --git a/src/user/app/shell/builtins.c b/src/user/app/shell/builtins.c index 4a7b79c..23a8221 100644 --- a/src/user/app/shell/builtins.c +++ b/src/user/app/shell/builtins.c @@ -26,6 +26,7 @@ static void cmd_cat(int argc, char **argv) { eprintf("couldn't open %s", argv[i]); return; } + if (!strcmp(argv[i], "!stdin")) fextflags(file, FEXT_NOFILL); for (;;) { int len = fread(buf, 1, sizeof buf, file); if (len <= 0) break; @@ -76,10 +77,11 @@ void cmd_hexdump(int argc, char **argv) { bool canonical = !strcmp(argv[0], "hd"); size_t readlen = ~0; size_t pos = 0; + bool raw = false; int c; optind = 0; - while ((c = getopt(argc, argv, "Cn:s:")) != -1) { + while ((c = getopt(argc, argv, "Cn:s:r")) != -1) { switch (c) { case 'C': canonical = true; @@ -90,6 +92,9 @@ void cmd_hexdump(int argc, char **argv) { case 's': pos = strtol(optarg, NULL, 0); break; + case 'r': /* "raw" mode, print data as soon as it's read without buffering */ + raw = true; + break; default: return; } @@ -103,6 +108,7 @@ void cmd_hexdump(int argc, char **argv) { eprintf("couldn't open %s", argv[optind]); return; } + if (raw) fextflags(file, FEXT_NOFILL); fseek(file, pos, SEEK_SET); bool skipped = false; while (pos < readlen) { -- cgit v1.2.3