...
However, modifying the environment by using the setenv()
or putenv()
functions, or by any other means, may cause the environment memory to be reallocated, with the reuslt result that envp
now references an incorrect location. For example, when compiled with gcc version n.n -3.4.6 and run on Linux version n.nAndrew Linux-2.6.16.29, the following code:
Code Block |
---|
extern char **environ; int main(int argc, char *argv[], char *envp[]) { printf("environ: %p\n", environ); printf("envp: %p\n", envp); setenv("MY_NEW_VAR", "new_value", 1); puts("--Added MY_NEW_VAR--"); printf("environ: %p\n", environ); printf("envp: %p\n", envp); } |
...