ILE C/C++ Run-Time Library Functions


getenv() -- Search for Environment Variables

Format

#include <stdlib.h>
char *getenv(const char *varname);

Language Level: ANSI

Threadsafe: Yes.

Description

The getenv() function searches the list of environment variables for an entry corresponding to varname.

Note:
This function accepts and returns only EBCDIC character strings. When LOCALETYPE(*LOCALEUTF) is specified on the compilation command, the user may need to convert any non-EBCDIC character strings to EBCDIC before calling this function and convert any resulting EBCDIC character strings to the correct CCSID.

Return Value

The getenv() function returns a pointer to the string containing the value for the specified varname in the current environment. If getenv() cannot find the environment string, NULL is returned, and errno is set to indicate the error.

Example that uses getenv()


#include  <stdlib.h>
#include  <stdio.h>
 
/* Where the environment variable 'PATH' is set to a value. */
 
int main(void)
{
   char *pathvar;
 
   pathvar = getenv("PATH");
   printf("pathvar=%s",pathvar);
}

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]