I tried two ways:
void func(const char *path, const char *arg0, ...){
va_list args;
va_start(args, arg0);
execl(path, arg0, args, NULL);
va_end(args);
}
func("/bin/ls", "ls");
And:
void func(const char *path, const char *arg0, ...){
va_list args;
va_start(args, arg0);
execl(path, arg0, args);
va_end(args);
}
func("/bin/ls", "ls", NULL);
But seems non work as expected after several test…
What’s wrong in my way of wrapping variable length parameters?
Since you don’t know how many arguments you’ll be receiving, you’ll need/want to use
execvinstead ofexecl. You’ll need to walk through the arguments, retrieve a pointer to the beginning of each string, and put them into an array. You’ll then pass the address of that array toexecv.