summaryrefslogtreecommitdiffstats
path: root/commands/test.c
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2020-01-28 14:08:01 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2020-02-10 09:42:43 +0100
commit359fc72149bc30f471405e5495e8aa8d69d728c6 (patch)
treeed745489593f1183b10cb6c0639fae4ed879028f /commands/test.c
parent7b95857a7ad911e698dc18261deceffdfd7d9fdb (diff)
downloadbarebox-359fc72149bc30f471405e5495e8aa8d69d728c6.tar.gz
barebox-359fc72149bc30f471405e5495e8aa8d69d728c6.tar.xz
commands/test: Implement -b and -c to test for character and block devices
These match the same options on coreutil's test(1). Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/test.c')
-rw-r--r--commands/test.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/commands/test.c b/commands/test.c
index 9070e49074..86636de1c2 100644
--- a/commands/test.c
+++ b/commands/test.c
@@ -40,6 +40,8 @@ typedef enum {
OPT_DIRECTORY,
OPT_FILE,
OPT_EXISTS,
+ OPT_BLOCK,
+ OPT_CHAR,
OPT_SYMBOLIC_LINK,
OPT_MAX,
} test_opts;
@@ -60,6 +62,8 @@ static char *test_options[] = {
[OPT_FILE] = "-f",
[OPT_DIRECTORY] = "-d",
[OPT_EXISTS] = "-e",
+ [OPT_BLOCK] = "-b",
+ [OPT_CHAR] = "-c",
[OPT_SYMBOLIC_LINK] = "-L",
};
@@ -142,6 +146,8 @@ static int do_test(int argc, char *argv[])
case OPT_FILE:
case OPT_DIRECTORY:
case OPT_EXISTS:
+ case OPT_BLOCK:
+ case OPT_CHAR:
case OPT_SYMBOLIC_LINK:
adv = 2;
if (left < 2)
@@ -169,6 +175,14 @@ static int do_test(int argc, char *argv[])
expr = 1;
break;
}
+ if (opt == OPT_BLOCK && S_ISBLK(statbuf.st_mode)) {
+ expr = 1;
+ break;
+ }
+ if (opt == OPT_CHAR && S_ISCHR(statbuf.st_mode)) {
+ expr = 1;
+ break;
+ }
}
break;