07 August 2010

How to access environments variables in your C program under UNIX

"The ISO/ANSI C standard requires that a C library include the getenv function, which retrieves the value of a named environment variable. Both the name and value are character strings."

Use getenv function! Don't use getpwuid(getuid())->pw_dir to access struct passwd! getenv is a handy function to access environments variables like HOME and PWD.

No comments: