Maybe something strange with gdb, or with the compiler?

By convention, there is always supposed to be at least one
argument, argv[0], which should be the same as the pathname
or the last level of the pathname being executed (login shells
typically get the last level of the pathname but prefixed with a
dash; that little trick lets them know to act like login shells rather
than like subshells).

So if that convention is observed, argc will be at least 1.

However, I tried truly passing zero arguments, using cc and dbx; it
worked reasonably:

$ cat aatest.c
#include <unistd.h>
#include <stdio.h>

int
main(int argc, char **argv)
{
        char *empty[] = {NULL};
        execve("/home/rlhamil/atest",empty,empty);
        perror("execve() failed");
        return 1;
}
$ cat atest.c
#include <stdio.h>
int
main(int argc, char **argv)
{
        printf("%d\n",argc);
        return 0;
}

When I ran aatest, 0 was printed (by atest).
 
That's as close to passing no arguments as one can get.  Attempting
to pass NULL rather than an array with one NULL element to
execve() for the arguments (maybe for the environment too) will
get a "Bad Address" error.

Even a situation that violates convention (but isn't strictly wrong) works.

So like I said, I think it's back to a problem with the tools you're using,
or something else you're doing wrong.
-- 
This message posted from opensolaris.org
_______________________________________________
opensolaris-discuss mailing list
[email protected]

Reply via email to