O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Looking at the Environment

Another way to influence program behavior is through environment variables. Environment variables, such as those in Figure 4.2, are key-value pairs that are under user control via the shell. The getenv() function is used to read the variables the user has set (directly or indirectly) in the environment from which your program has been run.

Figure 4.2  Environment variables

Environment variables

Supply getenv() with the name of the environment variable you want. If the variable does not exist in the environment, you get NULL back. If it does exist, you will get back a string with the value. The system owns the memory for the string returned ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required