[PATCH 3/3] commands/test: Implement -b and -c to test for character and block devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



These match the same options on coreutil's test(1).

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxxxx>
---
 commands/test.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/commands/test.c b/commands/test.c
index 9070e4907496..86636de1c283 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;
 
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux