...
The
getenvfunction searches the list of environment variables forvarname.getenvis not case sensitive in the Windows operating system.getenvand_putenvuse the copy of the environment pointed to by the global variable_environto access the environment.getenvoperates only on the data structures accessible to the run-time library and not on the environment "segment" created for the process by the operating system. Therefore, programs that use theenvpargument tomainorwmainmay retrieve invalid information.
When compiled with gcc-GCC version 3.4.6 and run on Andrew Linux-2.6.16.29a 32-bit Intel GNU/Linux test machine, the following code:
| Code Block |
|---|
extern char **environ;
/* ... */
int main(int argc, char const *argv[], char const *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);
}
|
...