11. March 2012 21:39
A short example of how to us setenv in a c program to set an enviroment variable which is then made avilable for any child processes to use.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv) {
if (setenv("VARNAME", "NEWVALUE", 1) < 0) {
perror("setenv");
exit(EXIT_FAILURE);
}
system("env | grep VARNAME");
return 0;
}
c86a5428-a0b7-425f-9946-3b6dea7e090a|0|.0