I would like to add my folmer /myBin/bin which have executable inside to the PATH environment variable so i can execvp() these.
The setenv() doesn't seems to add my directory to the PATH, what am I missing ?
Thank you
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <stdio.h>
int main(void){
char binDir[PATH_MAX+1];
strcpy(binDir,"~/myBin/bin");
char pathDir[PATH_MAX+1];
strcpy(pathDir,"PATH");
printf("Variable d'environnement (%s)\n\n\n", getenv("PATH"));
setenv(pathDir,binDir,0);
printf("Variable d'environnement (%s)\n", getenv("PATH"));
return 0;
}
You have set last argument of setenv to 0, as per setenv documentation "if overwrite is zero, then the value of name is not changed. ", you may try passing 1 as overwrite arguent to setenv