lundi 29 juin 2015

Attempting to use execvpe(...) but get implicit declaration error - even though I think I'm using the correct argument types


I am getting the following warning when I compile:

execute.c:20:2: warning: implicit declaration of function ‘execvpe’[-Wimplicit-function-declaration] execvpe("ls", args, envp);

^

My understanding is that this occurs when the function you are trying to use has the incorrect types of arguments. However, I am pretty sure that I am supplying the correct arguments to:

int execvpe(const char *file, char *const argv[], char *const envp[]);

as described in the Linux man page

Here are the relevant parts of my code:

#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>

void test_execvpe(char* envp[])
{
    const char* temp = getenv("PATH");
    char path[strlen(temp)+1];
    strcpy(path, temp);
    printf("envp[%d] = %s\n", 23, envp[23]); //print PATH
    char* args[] = {"-l", "/usr", (char*) NULL};
    execvpe("ls", args, envp);
}

int main( int argc, char* argv[], char* envp[])
{

    //test_execlp();
    test_execvpe(envp);
    return 0;

}

Anyone know why I keep getting this error? Thanks!


Aucun commentaire:

Enregistrer un commentaire