From patchwork Thu Jan 24 11:16:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 10778755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E04413B5 for ; Thu, 24 Jan 2019 11:17:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D35F2E974 for ; Thu, 24 Jan 2019 11:17:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01F2F2E9D4; Thu, 24 Jan 2019 11:17:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAAA62EB51 for ; Thu, 24 Jan 2019 11:17:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726105AbfAXLRI (ORCPT ); Thu, 24 Jan 2019 06:17:08 -0500 Received: from foss.arm.com ([217.140.101.70]:54808 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbfAXLRH (ORCPT ); Thu, 24 Jan 2019 06:17:07 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DBA941596; Thu, 24 Jan 2019 03:17:06 -0800 (PST) Received: from login12.euhpc.arm.com (login12.euhpc.arm.com [10.6.27.168]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C37AC3F237; Thu, 24 Jan 2019 03:17:05 -0800 (PST) From: Alexandru Elisei To: kvm@vger.kernel.org Cc: drjones@redhat.com, kvmarm@lists.cs.columbia.edu, andre.przywara@arm.com, vladimir.murzin@arm.com Subject: [kvm-unit-tests PATCH 6/7] lib: argv: Implement argv_find() for test parameters Date: Thu, 24 Jan 2019 11:16:33 +0000 Message-Id: <20190124111634.4727-7-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190124111634.4727-1-alexandru.elisei@arm.com> References: <20190124111634.4727-1-alexandru.elisei@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- lib/argv.h | 1 + lib/argv.c | 11 +++++++++++ 2 files changed, 12 insertions(+) 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; +}