getenv()--Get Value of Environment Variable

 #include <stdlib.h>

 char *getenv(const char *name);  

  Service Program Name: QP0ZCPA

  Default Public Authority: *USE

  Threadsafe: Yes. See Usage Notes for more information.

The getenv() function searches the job-level environment list for a string of the form name=value, where name is the environment variable and value is the value of the variable.

The name parameter does not include the equal (=) symbol or the value of the environment variable name=value pair.

Authorities and Locks



(Input) The name of an environment variable.

Return Value

Error Conditions

If getenv() is not successful, errno indicates one of the following errors.


A damaged object was encountered.

A referenced object is damaged. The object cannot be used.


The address used for an argument is not correct.

In attempting to use an argument in a call, the system detected an address that is not valid.

While attempting to access a parameter passed to this function, the system detected an address that is not valid.


No such path or directory.

The directory or a component of the path name specified does not exist.

A named file or directory does not exist or is an empty string.

No entry found for name specified.


Unknown system state.

The operation failed because of an unknown system state. See any messages in the job log and correct any errors that are indicated, then retry the operation.

Usage Notes

  1. Although getenv() is threadsafe, if a thread calls an environment variable function while another thread is accessing an environment variable from the environ array the thread may see undefined results. The environ array can be accessed directly or by using a pointer returned from the getenv() or Qp0zGetEnv() functions. The environment contents are only protected during calls to the environment variable functions.

  2. All environment variables are stored with an associated CCSID (coded character set identifier). Unless a different CCSID is specified, such as by using Qp0zPutEnv(), the default CCSID for the job is used as the CCSID associated with each environment variable string.

  3. No translation is done based on the CCSID. The CCSID is just stored and retrieved as an integer value associated with each environment variable.

Related Information


See the example of using getenv() in putenv()--Change or Add Environment Variable.

For other examples, see the following:

API introduced: V3R6

[ Back to top | UNIX-Type APIs | APIs by category ]