On Fri, Jun 05, 2009 at 12:27:12PM -0400, Ted Unangst wrote:
On Fri, Jun 5, 2009 at 12:15 PM, Ted Walther <[email protected]> wrote:
execve() wants ? char *const envp[]
environ provides char **
environ is provided by execve from envp.

How do I pass the environment into execve without raising a compiler
warning about incompatible pointer types?

What warning are you getting?  What's your source?

My apologies. I was abusing "const".  I must have been using the
function prototype from an other OS than OpenBSD.

Here was my sample that caused the error:

====
#include <unistd.h>
#include <stdlib.h>

extern char **environ;

void
my_exec(const char *f, const char *const *a, const char *const *e) {
        /* do some stuff ... then: */
        execve(f,a,e);
}

int
main(int argc, char **argv) {
        my_exec(*argv,argv+1,environ);
        exit(0);
}
====

The fix was to remove the extraneous consts from arg2 and arg3.

-my_exec(const char *f, const char *const *a, const char *const *e) {
+my_exec(const char *f, char *const a[], char *const e[]) {

Ted
--
           There's a party in your skull.  And you're invited!

Name:    Ted Walther
Phone:   604-755-7732
Skype:   tederific
Email:   [email protected]
Address: 1755 246 St, LANGLEY BC  V2Z1G4

Reply via email to