Add a proper header for the lib/argv.c file
Subsystems (2)
PATCH 1/1 Add a proper header for the lib/argv.c file
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.
--- 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
lib/argv.c +7 -9
@@ -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)
lib/argv.h new file +10 -0
@@ -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);
lib/arm/setup.c +1 -2
@@ -14,6 +14,7 @@#include <libfdt/libfdt.h> #include <devicetree.h> #include <alloc.h> +#include <argv.h> #include <asm/thread_info.h> #include <asm/setup.h> #include <asm/page.h>
@@ -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;
lib/powerpc/setup.c +1 -2
@@ -14,14 +14,13 @@#include <libfdt/libfdt.h> #include <devicetree.h> #include <alloc.h> +#include <argv.h> #include <asm/setup.h> #include <asm/page.h> #include <asm/hcall.h> 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;
lib/s390x/io.c +1 -1
@@ -11,10 +11,10 @@* under the terms of the GNU Library General Public License version 2. */ #include <libcflat.h> +#include <argv.h> #include <asm/spinlock.h> #include "sclp.h" -extern void setup_args_progname (const char *args);extern char ipl_args[];static struct spinlock lock;
Signature · 1 line
1.8.3.1
Quoted 8 lines · Thomas Huth
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 inargv.caccordingly.Signed-off-by Thomas Huth <[email protected]>---
Signature · 3 lines
Thanks, David
Quoted 7 lines · Thomas Huth
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 inargv.caccordingly.Signed-off-by Thomas Huth <[email protected]>
Quoted 9 lines
--- 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
Quoted 143 lines · Thomas Huth
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 inargv.caccordingly.Signed-off-by Thomas Huth <[email protected]>--- 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.hlib/argv.c +7
-9@@ -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)lib/argv.h new file +10
-0@@ -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);lib/arm/setup.c +1
-2@@ -14,6 +14,7 @@#include <libfdt/libfdt.h> #include <devicetree.h> #include <alloc.h> +#include <argv.h> #include <asm/thread_info.h> #include <asm/setup.h> #include <asm/page.h> @@ -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;lib/powerpc/setup.c +1
-2@@ -14,14 +14,13 @@#include <libfdt/libfdt.h> #include <devicetree.h> #include <alloc.h> +#include <argv.h> #include <asm/setup.h> #include <asm/page.h> #include <asm/hcall.h> 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;lib/s390x/io.c +0
-0@@ -11,10 +11,10 @@* under the terms of the GNU Library General Public License version 2.
lib/s390x/io.c line 20
Quoted 10 lines
lib/s390x/io.c +1
-1*/ #include <libcflat.h> +#include <argv.h> #include <asm/spinlock.h> #include "sclp.h" -extern void setup_args_progname (const char *args);extern char ipl_args[];static struct spinlock lock;
Applied, thanks.
Paolo