Correct way to call execve?

Tim Kientzle kientzle at acm.org
Mon Jul 21 08:50:47 PDT 2003


Leo Bicknell wrote:
> In a message written on Sun, Jul 20, 2003 at 02:13:52PM -0700, Tim Kientzle wrote:
>>If I declare argv as "const char *",
>>then the call to execve() warns about
>>"incompatible pointer type" for the
>>second argument.
> 
> Almost, but the other order is important here, this passes gcc -Wall:
> 
> #include <unistd.h>
> #include <paths.h>
> 
> int main(int argc, char *const argv[], char *const envp[]) {
>   char *const execargv[] = { _PATH_BSHELL, NULL };
> 
>   execve(_PATH_BSHELL,execargv,envp);
> 
>   return 0;
> }

Actually, this example passes -Wall if you declare
"execargv" as simply "char *[]".  However, I'm looking
for something that passes gcc -Wwrite-strings, which this
example does not.

I honestly don't believe it is possible to call
execve() in a const-correct fashion with -Wwrite-strings
unless you copy over all of the arguments into
non-const storage. <sigh>  I'd love to be proven wrong, though.

Tim Kientzle






More information about the freebsd-hackers mailing list