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 ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.