Correct way to call execve?

Tim Kientzle kientzle at acm.org
Sun Jul 20 14:10:48 PDT 2003


I can find no way to call execve
that actually compiles without warnings.

If I use:
   char *argv[2];
   argv[0] = _PATH_BSHELL;
   argv[1] = NULL;
   execve(_PATH_BSHELL,argv,environ);

then the first assignment is "discarding
qualifiers".

If I declare argv as "const char *",
then the call to execve() warns about
"incompatible pointer type" for the
second argument.

Reading through SUSv3 I find that the committee
thought that the second argument to execve()
should have been "const char * const *", but
they didn't want old code to generate compiler
warnings.  (Of course, compilers that correctly
type constant strings as "const char *" break
that.)

Does anyone know a good way out of this mess?
(Suggestions to turn off compiler warnings
will be ignored. ;-)

Tim Kientzle




More information about the freebsd-hackers mailing list