getenv -- Get Value of Environment Variable

SYNOPSIS

 #include <stdlib.h>

 char *getenv(const char *name);
 

DESCRIPTION

The getenv function searches an environment-variable list for the string name and returns a corresponding value. The variable name may be translated to uppercase letters, depending on the operating environment, as described in Environment Variables . In some contexts, environment-variable names are limited to about 250 characters.

Depending on the environment, if name contains a period, the portion of the name preceding the period is interpreted as a group name, as described in Environment Variables . Group names are limited to 8 characters.

See Chapter 4, "Compiling C Programs" and Chapter 8, "Run-Time Argument Processing," in the SAS/C Compiler and Library User's Guide, Fourth Edition for information on defining environment variables.

RETURN VALUE

getenv returns a pointer to the environment-variable value if name was found. This pointer may address a static buffer, which is reused by the next call to getenv. If name is not found in the environment-variable list, getenv returns NULL.

CAUTIONS

Environment-variable values are not altered by the C library. However, environment variables specified on the TSO or CMS command line may be converted to uppercase letters by TSO or CMS before control is given to the C program.

PORTABILITY

getenv compiles with the POSIX.1 and POSIX.1a standards for C programs invoked by an exec function.

EXAMPLE

  #include <stdlib.h>
  #include <string.h>
  #include <stdio.h>

  main()
  {
     char *locale_string;
     locale_string = getenv("_LOCALE");

     if (locale_string)
        printf("The current default locale is %sn", locale_string);
     else puts("The _LOCALE environment variable is not set.");
  }


 

RELATED FUNCTIONS

clearenv, execshv, putenv, setenv

SEE ALSO


Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.