diff mbox series

[kvm-unit-tests,6/7] lib: argv: Implement argv_find() for test parameters

Message ID 20190124111634.4727-7-alexandru.elisei@arm.com (mailing list archive)
State New, archived
Headers show
Series arm/arm64: Add support for running under kvmtool | expand

Commit Message

Alexandru Elisei Jan. 24, 2019, 11:16 a.m. UTC
The current behavior when searching for a specific parameter is to exit
with an error when the first unexpected parameter is found.

The function argv_find() will search for a specific parameter, ignoring all
other parameters.

Consumers for the function will be added in a later patch.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 lib/argv.h |  1 +
 lib/argv.c | 11 +++++++++++
 2 files changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/lib/argv.h b/lib/argv.h
index 2104dd42748d..efc390ae4fae 100644
--- a/lib/argv.h
+++ b/lib/argv.h
@@ -8,3 +8,4 @@ 
 extern void __setup_args(void);
 extern void setup_args_progname(const char *args);
 extern void setup_env(char *env, int size);
+extern int argv_find(const char *needle, int argc, char **argv);
diff --git a/lib/argv.c b/lib/argv.c
index f0e183a8f02f..6e4593997e0b 100644
--- a/lib/argv.c
+++ b/lib/argv.c
@@ -144,3 +144,14 @@  void setup_env(char *env, int size)
 		*env++ = '\0';
 	}
 }
+
+int argv_find(const char *needle, int argc, char **argv)
+{
+	int i;
+
+	for (i = 0; i < argc; i++)
+		if (strcmp(argv[i], needle) == 0)
+			return i;
+
+	return -1;
+}