From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH] commands: test: implement test -s for non-zero size check
Date: Mon, 12 Jan 2026 09:51:37 +0100 [thread overview]
Message-ID: <20260112085137.2950183-1-a.fatoum@barebox.org> (raw)
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
reply other threads:[~2026-01-12 8:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260112085137.2950183-1-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox