#include <lclib.h> int putenv(const char *string);
putenv
function creates an environment variable with a specified
name and value, or replaces an existing environment variable with a
new value. The name and value are specified by the string pointed
to by the argument string
. For example,
[[scope]:][[groupname].]varname[=value]For portable use, the scope and groupname parts of the string must be omitted, and a value must be present. The parts are
scope is not case sensitive. The uppercase letters indicate the minimum abbreviation that may be specified for the scope name. See Environment Variables for a definition of the environment-variable scopes. The SEssion scope is CMS specific and refers to GLOBALV SESSION variables. For all other systems, a SEssion-scope specification is treated as if it were an External-scope specification. If you do not specify scope, PRogram scope is assumed. Scopes other than PRogram are valid only under TSO, CMS, and CICS.
""
is assumed. For nonprogram-scope
variables, the value is truncated if it is longer than supported for
that scope.
putenv
returns 0 if successful or - 1 if unsuccessful.
environ
or the data it points to in a program that uses putenv
.
The putenv
function
may cause the value of environ
to change.
putenv
is defined by many UNIX and MS-DOS C compilers. Scopes and groups
for environment variables are SAS/C extensions.
getenv
always returns the value of shortest duration. For example, if
a program-scope variable is defined, getenv
always returns its value.
HOME
, if it does
not already exist, and then invokes an OpenEdition shell command:
#include <stdio.h> #include <lclib.h> #include <lcstring.h> main() { char home[17]; char cmd[300]; int rc; /* if environment variable HOME not defined */ if (!getenv("HOME")) { strcpy(home, "HOME=/u/"); cuserid(home+8); /* Append userid to directory name. */ strlwr(home); /* Translate to lowercase letters. */ rc = putenv(home); /* Define HOME environment variable. */ if (rc != 0) { perror("putenv failure"); exit(EXIT_FAILURE); } } puts("Enter shell command"); memcpy(cmd, "//sh:", 5); /* prefix for system function */ gets(cmd+5); rc = system(cmd); /* Invoke the shell command. */ printf("shell command status code was %d.n", rc); exit(rc); }
clearenv
, getenv
, setenv
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.