Info | ||
---|---|---|
| ||
Perhaps this might be more appropriate: ENV31-C. Use environ instead of envp. |
Under many UNIX systems it is possible to access the environment through a modified form of main
:
Code Block |
---|
main(int argc, char **argv, char **envp) \{\}
|
According to C99,
In a hosted environment, the main function receives a third argument, char *envp[], that points to a null-terminated array of pointers to char, each of which points to a string that provides information about the environment for this execution of the program.
However, any environment variables added using the setenv()
or putenv()
functions will not show up in the envp
array. If you need to directly access or manipulate the environment, it is safer to use environ
If an environment variable could have changed during program execution, get a fresh copy using getenv()
. Relying on the old one might leave you with incorrect data or a dangling pointer.
Non-Compliant Coding Example
...