Chapter Contents |
Previous |
Next |
getenv |
Portability: | ISO/ANSI C conforming, UNIX compatible, POSIX.1 conforming |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
CAUTIONS | |
PORTABILITY | |
EXAMPLE | |
RELATED FUNCTIONS | |
SEE ALSO |
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.
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 |
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 %s\n", locale_string); else puts("The _LOCALE environment variable is not set."); }
RELATED FUNCTIONS |
clearenv
,
execshv
,
putenv
,
setenv
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.