ext-toolchain-wrapper.c: Handle an arbitrary amount of arguments
PATCH v3 1/1 ext-toolchain-wrapper.c: Handle an arbitrary amount of arguments
Even though MAXARGS 1000 seems large, it wasn't enought for at least QtWebKit package. This new version does not have any predefined limits.
Closes #3907
Many thanks to Thomas for tracing the source of the build error.
---
New in v3:
* Really add the changes mentioned in v2;
- Removed unused variable 'i'
* Add __FILE__ to perror() for easy tracking failures (even though it's unlikely to happen)
.../toolchain-external/ext-toolchain-wrapper.c | 31 +++++++++++++------- 1 files changed, 20 insertions(+), 11 deletions(-)
toolchain/toolchain-external/ext-toolchain-wrapper.c +20 -11
@@ -4,6 +4,7 @@* to ensure the external toolchain uses the correct configuration. * * (C) 2011 Peter Korsgaard <[email protected]> +* (C) 2011 Daniel Nystr?m <[email protected]> * * This file is licensed under the terms of the GNU General Public License * version 2. This program is licensed "as is" without any warranty of any
@@ -14,12 +15,11 @@#include <string.h> #include <limits.h> #include <unistd.h> - -#define MAXARGS 1000 +#include <stdlib.h> static char path[PATH_MAX ] =BR_CROSS_PATH ; -static char *args[MAXARGS ] = { +static char *predef_args[] = { path,"--sysroot" ,BR_SYSROOT , #ifdef BR_ARCH
@@ -54,22 +54,31 @@ static const char *get_basename(const char *name)int main (int argc,char **argv) { -int i; - -for (i=0 ; args[i]; i++); +char **args, **cur; -if ((argc+i) >=MAXARGS ) { -fputs ("Too many arguments\n" , stderr); -return 1 ; + cur = args =malloc (sizeof (predef_args) + (sizeof (char *) * argc)); +if (args ==NULL ) { +perror (__FILE__": malloc" ); +abort (); } -/* forward args */ -memcpy (&args[i], &argv[1 ],sizeof (argv[0 ]) * (argc -1 )); +/* start with predefined args */ +memcpy (cur, predef_args,sizeof (predef_args)); + cur +=sizeof (predef_args) /sizeof (predef_args[0 ]); + +/* append forward args */ +memcpy (cur, &argv[1 ],sizeof (char *) * (argc -1 )); + cur += argc -1 ; + +/* finish with NULL termination */ + *cur =NULL ;strcat (path,get_basename (argv[0 ]));if (execv (path, args))perror (path); +free (args); +return 2 ; }
Signature · 1 line
1.7.4.1
PATCH v3 1/1 ext-toolchain-wrapper.c: Handle an arbitrary amount of arguments
2011/6/21 Daniel Nystr?m:
Quoted 1 line
Even though MAXARGS 1000 seems large, it wasn't enought for at least
enought -> enough
Quoted 1 line
+ ? ? ? cur +=
sizeof(predef_args)/sizeof(predef_args[0]);
looks like you should add an ARRAY_SIZE define to the top of the file
Quoted 1 line
+ ? ? ?
memcpy(cur, &argv[1], sizeof(char *) * (argc - 1));
in practice there's probably no difference, but this should be sizeof(argv[0]) -mike
PATCH v3 1/1 ext-toolchain-wrapper.c: Handle an arbitrary amount of arguments
Thanks for your comments, Mike!
2011/6/21 Mike Frysinger <[email protected]>:
Quoted 4 lines
2011/6/21 Daniel Nystr?m:
Quoted 1 line
Even though MAXARGS 1000 seems large, it wasn't enought for at least
enought -> enough
Thanks. I'm sure Peter will fix the spelling when committing.
Quoted 7 lines
Quoted 1 line
+ ? ? ? cur +=
sizeof(predef_args)/sizeof(predef_args[0]);looks like you should add an
ARRAY_SIZEdefine to the top of the fileQuoted 1 line
+ ? ? ?
memcpy(cur, &argv[1], sizeof(char *) * (argc - 1));in practice there's probably no difference, but this should be
sizeof(argv[0])
I actually had both of these in mind, but ended up with this since I think it looks most "clean". But I guess it's a matter of taste.
PATCH v3 1/1 ext-toolchain-wrapper.c: Handle an arbitrary amount of arguments
In reply to Daniel NyströmQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Daniel" == Daniel Nystr?m <[email protected]> writes:
Daniel> Even though MAXARGS 1000 seems large, it wasn't enought for at least Daniel> QtWebKit package. This new version does not have any predefined limits.
Daniel> Closes #3907
Daniel> Many thanks to Thomas for tracing the source of the build error.
Daniel> Signed-off-by: Daniel Nystr?m <[email protected]> Daniel> Reported-by: Thomas Bj?rk <[email protected]>
Committed, thanks!
Signature · 1 line
Bye, Peter Korsgaard