On Tue, Oct 27, 2009 at 10:47 AM, Peter Korsgaard <[email protected]> wrote:
>>>>>> "walter" == walter harms <[email protected]> writes:
>
> Hi,
>
> >> + int fd = argv[1] ? xopen(argv[1], O_RDONLY) : STDIN_FILENO;
> >> +
>
>
> walter> i did not try; but what will happen if argc==1 ?
> walter> argv[1] should be undefined.
>
> No, argv is afaik guaranteed to be null terminated - E.G. access to
> argv[argc] is OK - But you can ofcourse cheat with execve and get argc
> == 0, so the below is indeed better.
>
> walter> perhaps this is more save
> walter> (argc > 1) ? xopen(argv[1], O_RDONLY) : STDIN_FILENO;
Yes, you can do
int main()
{
static char *argv[1] = { 0 };
execvp("busybox", argv);
return 0;
}
but this way busybox wouldn't even call wall_main, it will segfault earlier.
--
vda
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox