#include <stdlib.h> char *getenv(const char *name);
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.
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
.
getenv
compiles with the POSIX.1 and POSIX.1a standards for C
programs invoked by an exec
function.
#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."); }
clearenv
, execshv
, putenv
, setenv
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.