From patchwork Tue Jun 27 04:44:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 9810787 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3FF4D6020A for ; Tue, 27 Jun 2017 04:44:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 360CA2853E for ; Tue, 27 Jun 2017 04:44:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A48A28550; Tue, 27 Jun 2017 04:44:15 +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=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 B570D2853E for ; Tue, 27 Jun 2017 04:44:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751524AbdF0EoL (ORCPT ); Tue, 27 Jun 2017 00:44:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49300 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751519AbdF0EoK (ORCPT ); Tue, 27 Jun 2017 00:44:10 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 404494E33D for ; Tue, 27 Jun 2017 04:44:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 404494E33D Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=thuth@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 404494E33D Received: from thh440s.redhat.com (ovpn-116-48.ams2.redhat.com [10.36.116.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id F10A377DC5; Tue, 27 Jun 2017 04:44:08 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Drew Jones Subject: [kvm-unit-tests PATCH] Add a proper header for the lib/argv.c file Date: Tue, 27 Jun 2017 06:44:07 +0200 Message-Id: <1498538647-2721-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 27 Jun 2017 04:44:10 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of declaring the prototypes for these functions in various C files, introduce a proper header for them. This change also revealed that the prototypes of setup_args_progname() did not match the implementation - the argument can be a "const char *", so change the code in argv.c accordingly. Signed-off-by: Thomas Huth Reviewed-by: David Hildenbrand Reviewed-by: Andrew Jones --- lib/argv.c | 16 +++++++--------- lib/argv.h | 10 ++++++++++ lib/arm/setup.c | 3 +-- lib/powerpc/setup.c | 3 +-- lib/s390x/io.c | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 lib/argv.h diff --git a/lib/argv.c b/lib/argv.c index f2466d4..f0e183a 100644 --- a/lib/argv.c +++ b/lib/argv.c @@ -6,10 +6,11 @@ */ #include "libcflat.h" +#include "argv.h" #include "auxinfo.h" int __argc; -char *__args; +const char *__args; char *__argv[100]; char *__environ[200]; @@ -22,7 +23,7 @@ static char *copy_ptr = args_copy; #define isalpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z') || (c) == '_') #define isalnum(c) (isalpha(c) || ((c) >= '0' && (c) <= '9')) -static char *skip_blanks(char *p) +static const char *skip_blanks(const char *p) { while (isblank(*p)) ++p; @@ -31,7 +32,7 @@ static char *skip_blanks(char *p) void __setup_args(void) { - char *args = __args; + const char *args = __args; char **argv = __argv + __argc; while (*(args = skip_blanks(args)) != '\0') { @@ -43,7 +44,7 @@ void __setup_args(void) __argc = argv - __argv; } -void setup_args(char *args) +static void setup_args(const char *args) { if (!args) return; @@ -52,16 +53,13 @@ void setup_args(char *args) __setup_args(); } -void setup_args_progname(char *args) +void setup_args_progname(const char *args) { __argv[0] = copy_ptr; strcpy(__argv[0], auxinfo.progname); copy_ptr += strlen(auxinfo.progname) + 1; ++__argc; - if (args) { - __args = args; - __setup_args(); - } + setup_args(args); } static char *env_eol(char *env) diff --git a/lib/argv.h b/lib/argv.h new file mode 100644 index 0000000..2104dd4 --- /dev/null +++ b/lib/argv.h @@ -0,0 +1,10 @@ +/* + * Set up arguments for main() and prepare environment variables + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU Library General Public License version 2. + */ + +extern void __setup_args(void); +extern void setup_args_progname(const char *args); +extern void setup_env(char *env, int size); diff --git a/lib/arm/setup.c b/lib/arm/setup.c index 9974b4c..a0b1795 100644 --- a/lib/arm/setup.c +++ b/lib/arm/setup.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -22,8 +23,6 @@ extern unsigned long stacktop; extern void io_init(void); -extern void setup_args_progname(const char *args); -extern void setup_env(char *env, int size); char *initrd; u32 initrd_size; diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index f6cacdc..20a1e37 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -14,14 +14,13 @@ #include #include #include +#include #include #include #include extern unsigned long stacktop; extern void io_init(void); -extern void setup_args_progname(const char *args); -extern void setup_env(char *env, int size); char *initrd; u32 initrd_size; diff --git a/lib/s390x/io.c b/lib/s390x/io.c index 067ecf7..4ab5bd9 100644 --- a/lib/s390x/io.c +++ b/lib/s390x/io.c @@ -11,10 +11,10 @@ * under the terms of the GNU Library General Public License version 2. */ #include +#include #include #include "sclp.h" -extern void setup_args_progname(const char *args); extern char ipl_args[]; static struct spinlock lock;