Correct way to call execve?

Leo Bicknell bicknell at
Mon Jul 21 11:59:31 PDT 2003

You know, my own thinking made me figure this one out:

% cat exec.c

#include <unistd.h>
#include <paths.h>
#include <string.h>

int main(int argc, char *const argv[], char *const envp[]) {
  char *const execargv[] = { _PATH_BSHELL, NULL };


  return 0;
% cc -fwritable-strings -Wcast-qual -Wwrite-strings exec.c

There you go.  By default strings are read-only, and indeed smart
compilers use that to compress them and do other nifty tricks.  However,
in this case you really want a string to be "char *", eg writable.
So, tell the compiler to do that with "-fwritable-strings", poof,
strings are now "char *", the cast away the cost problem goes away,
"-Wcast-qual" works fine.

It always seemed to me a lot of things included -fwritable-strings for
no good reason, maybe this is part of the reason. :)

       Leo Bicknell - bicknell at - CCIE 3440
        PGP keys at
Read TMBG List - tmbg-list-request at,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url :

More information about the freebsd-hackers mailing list