05-25-06 12:18 PM
skylazart@gmail.com wrote:
> How Can I change the argv?
>
> I know its works:
> memset (argv[0], 'A', strlen (argv[0]));
>
> But, When I need a new arg bigger than argv[0] size?
>
> I have to create a new array?
The only portable way I can think of is to create a new array and
then use re-execute the program with this array. Something like this
(disclaimer: the code below may contain defects).
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static char *faker = "faker";
int main(int argc, char *argv[])
{
int i;
char **array;
if (strcmp(argv[0], faker) != 0) {
/* Build new array */
array = calloc(argc + 1, sizeof(*array));
if (array) {
array[0] = faker;
for (i = 1; i < argc; ++i) {
array[i] = argv[i];
}
execvp(argv[0], array);
}
}
/* Do your normal stuff here */
sleep(60);
return 0;
}
--
mail1dotstofanetdotdk
[ Post a follow-up to this message ]
|