* [PATCH] commands: test: implement test -s for non-zero size check
@ 2026-01-12 8:51 Ahmad Fatoum
0 siblings, 0 replies; only message in thread
From: Ahmad Fatoum @ 2026-01-12 8:51 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
While we have a lot of [ flags already and even some for bash [[,
-s to check if the size is non-zero has so far been missing.
Add it.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
commands/test.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/commands/test.c b/commands/test.c
index 13005b97deb3..c2f2993df406 100644
--- a/commands/test.c
+++ b/commands/test.c
@@ -33,6 +33,7 @@ typedef enum {
OPT_BLOCK,
OPT_CHAR,
OPT_SYMBOLIC_LINK,
+ OPT_NONZERO_SIZE,
OPT_MAX,
} test_opts;
@@ -56,6 +57,7 @@ static char *test_options[] = {
[OPT_BLOCK] = "-b",
[OPT_CHAR] = "-c",
[OPT_SYMBOLIC_LINK] = "-L",
+ [OPT_NONZERO_SIZE] = "-s",
};
static int parse_opt(const char *opt)
@@ -201,6 +203,7 @@ static int do_test(int argc, char *argv[])
case OPT_BLOCK:
case OPT_CHAR:
case OPT_SYMBOLIC_LINK:
+ case OPT_NONZERO_SIZE:
adv = 2;
if (left < 2)
break;
@@ -235,6 +238,10 @@ static int do_test(int argc, char *argv[])
expr = 1;
break;
}
+ if (opt == OPT_NONZERO_SIZE && statbuf.st_size) {
+ expr = 1;
+ break;
+ }
}
break;
@@ -295,7 +302,7 @@ static const char * const test_aliases[] = { "[", "[[", NULL};
BAREBOX_CMD_HELP_START(test)
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_TEXT("\t!, =, !=, -eq, -ne, -ge, -gt, -le, -lt, -o, -a, -z, -n, -d, -e,")
-BAREBOX_CMD_HELP_TEXT("\t-f, -L; see 'man test' on your PC for more information.")
+BAREBOX_CMD_HELP_TEXT("\t-s, -f, -L; see 'man test' on your PC for more information.")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(test)
--
2.47.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-01-12 8:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-12 8:51 [PATCH] commands: test: implement test -s for non-zero size check Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox