From 359fc72149bc30f471405e5495e8aa8d69d728c6 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Tue, 28 Jan 2020 14:08:01 +0100 Subject: commands/test: Implement -b and -c to test for character and block devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These match the same options on coreutil's test(1). Signed-off-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- commands/test.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'commands') 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; -- cgit v1.2.3