From: Paolo Bonzini Subject: Re: [kvm-unit-tests PATCH] Add a proper header for the lib/argv.c file Date: Tue, 27 Jun 2017 14:29:25 +0200 Message-ID: References: <1498538647-2721-1-git-send-email-thuth@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Drew Jones To: Thomas Huth , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:46576 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751453AbdF0M3f (ORCPT ); Tue, 27 Jun 2017 08:29:35 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39A177F3F7 for ; Tue, 27 Jun 2017 12:29:30 +0000 (UTC) In-Reply-To: <1498538647-2721-1-git-send-email-thuth@redhat.com> Content-Language: en-US Sender: kvm-owner@vger.kernel.org List-ID: On 27/06/2017 06:44, Thomas Huth wrote: > 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 > --- > 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; > Applied, thanks. Paolo