getenv
function, which retrieves the value of a named environment variable. Both
the name and value are character strings. The ISO/ANSI C standard does not
describe the
meaning of environment variables, how they might be set, or even whether it is
possible to define them. However, the getenv
function should
be similar to the getenv
function under the UNIX environment, and
if the host operating system has a facility similar to UNIX environment
variables, getenv
should provide a means of accessing that facility.
These properties are fundamental to the behavior of UNIX environment variables:
export HOME=/u/george
system
function),
the calling program's environment variables are passed to the called program.
The communication is one way; that is, the caller passes the environment to the
called program, but any changes the called program makes to its environment are
not available to the caller.
exec
function enable a program to pass control to
another program with a specially built environment.
Secondary properties of UNIX environment variables include
environ
, which addresses the list of
environment variables. Many older programs access environ
for environmental
information rather than calling getenv
.
environ
.
Some versions of the UNIX environment implement functions like putenv
to
modify the environment, but these functions are not portable.
The most difficult aspect of implementing environment variables under the MVS and CMS operating systems is that native methods for invoking other programs (ATTACH, CMSCALL) do not provide for a list of variables. For this reason, the SAS/C environment variable implementations provide somewhat different semantics in which variables are shared by all programs in a session, regardless of how the programs are invoked. The implementation was modeled after CMS global variables (also called GLOBALV variables) so that C environment variables could be used as a way of accessing and modifying these variables under CMS. This implementation is adequate for porting many UNIX programs that use environment variables, in particular, for all programs that do not modify their own environment. SAS/C software implements environment variables similar to GLOBALV under CMS, TSO, and CICS. Also, for programs running under the OpenEdition shell, the environment variable implementation complies with POSIX.1 and traditional UNIX usage.
exec
functions is used.
Program-scope environment variables are set in one of two ways. First, they
may be specified on the program's command line as described in Chapter 8,
"Run-Time Argument Processing," in the SAS/C Compiler and Library User's Guide, Fourth Edition . Or, for programs invoked by the
OpenEdition exec
system call, they may be passed by the caller of
exec
.
There are no limits on the size of program scope variable names or values. The
names are case insensitive; that is, home
, Home
, and HOME
are considered to identify the same variable. (See OpenEdition Considerations
for an exception.)
SAS/C implements program-scope environment variables in all environments. It implements external- and permanent-scope environment variables under TSO, CMS, and CICS.
When a program calls the getenv
function to retrieve the value of an
environment variable, the scopes are searched in order. That is, first the
program-scope variables are checked, then the external-scope variables, and then
the permanent-scope variables. This enables you or the program to override the
usual value with a more temporary value for the duration of a program or session.
When a program calls the putenv
or setenv
function to modify or add
an environment variable, the change is made at program scope unless some other
scope is explicitly specified. Thus, a portable program that changes its own
environment will not affect any other program. Scopes are indicated to putenv
by a prefix on the environment variable name followed by a colon, for example,
external:TZ
. Because colons are not commonly used in UNIX environment variable
names, this extension has little effect on portability.
LC370.MACLIBS
defines the variable MACLIBS
in the group LC370
.
An environment variable without a group name is considered to have a default group
name of CENV
.
CMS group names are limited to eight characters. For this reason, in certain cases,
environment variable names containing periods may behave differently in different
scopes. For example, the two environment variables TOOLONGFORME.NAME
and
TOOLONGFORANYONE.NAME
refer to the same variable for an external scope but
different variables for a program scope. This should not be a problem in normal usage.
Because environment variables in traditional UNIX usage do not normally contain periods, this extension does not ordinarily cause portability problems.
exec
function),
program-scope environment variables are considered case sensitive. For all other
programs, these names remain case insensitive for compatibility with CMS and
previous releases.
exec
-linkage programs, the original form of the variable is
preserved even though the case of an environment
variable is not considered significant. (That is, the variable MyName
is stored as MyName
, not
as myname
or MYNAME
even though these are all names for the same
variable.) If a program calls exec
to pass control to an
exec
-linkage program, the called program receives the environment
variables with their original case information intact.
environ
. SAS/C now makes the program-scope environment variables
accessible by environ
for all programs. However, variables of other scopes
are never accessible by environ
. Similarly, when an exec
function
is called, only the program-scope environment variables are passed to the called
program.
environ
and the list it addresses. SAS/C supports this
modification but
does not recommend it. The POSIX.1a function setenv
should be used to
update the environment whenever possible. In particular, you should not use both
setenv
and update environ
simultaneously. This is a restriction stated by the
POSIX.1a draft standard.
environ
variable is not strictly ISO/ANSI conforming
because environ
is in the name space reserved by ISO/ANSI for users. For this
reason, the name environ
is accessible only to programs compiled with the
posix
option. Additionally, the name environ
is valid only in the
main
load module of a program. To access environ
from another load
module, declare
extern char ***_environ;and use
*_environ
in place of environ
. This produces correct results
in any load module but is not portable. _environ
can be used in
programs that are not compiled with the posix
option.
clearenv
function, which removes all environment
variables. It has an effect only on program-scope variables. That is, external- and
permanent-scope variables are unaffected.
Note: Under CMS, when you update a permanent-scope environment variable, the new value is also assigned to the external-scope variable of the same name.
Environment variable names are limited under TSO to 254 characters, and values are limited to 255 characters.
putenv
function with a PERMANENT scope. If the
request is a getenv
function, the file is not created.
CENV
. A line of the form =group defines a
group, and a line of the form var=value defines a variable. If
var=value uses more than 254 characters, it takes up two lines in
the file and is split at the equal sign.
Assume that the content of a userid.C@ENV.PERM file is as follows:
NAME=Fred MISC.AVERYLONGNAME= averylongvalueIn this example, two PERMANENT environment variables are defined: NAME has a value of Fred, and MISC.AVERYLONGNAME has a value of averylongvalue.
TSO environment variables are kept in subpool 78 memory for the life of the session. They are located through an anchor field at offset 260 from the RLGB (relogon buffer), which is a field reserved by IBM. Before using this field, the C environment variable routines check the field to see if it is already being used by either IBM or the site. If the field is unavailable, then EXTERNAL environment variables are also stored in a file, rather than in memory. In this case, access is slower because the variables are not in memory.
If the DDname T@ENV is allocated, the DDname is used for EXTERNAL environment variables. If T@ENV is not allocated, a temporary data set is created and allocated to this DDname.
The TSO environment variable implementation stores environment
variables in shared subpool 78 storage. If a task that does not share
subpool 78 with the rest of TSO invokes putenv
, the putenv
function fails. Also, use of setenv
by such tasks may
involve substantial extra processing.
By default, the library uses the VTAM netname as a queue name and only accesses the first record in the queue. The queue name is set in the user-replaceable routine L$UEVQN. This routine enables a site to use some other scheme for assigning a queue name, including the option of sharing a single queue between all programs. See the source code in the SASC.SOURCE data set (under MVS) or the LSU MACLIB (under CMS) for complete details.
Because Temporary Storage is a shared facility on CICS, some potential problems exist with the technique of using the VTAM netname as a queue name. Some of those problems are:
Environment variable names are limited in CICS to 254 characters, and values are limited to 255 characters.
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.