346 lines
9.5 KiB
HTML
346 lines
9.5 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
|
|
<title>Qp0zPutSysEnv()--Change or Add a System-Level Environment
|
|
Variable</title>
|
|
<!-- Begin Header Records ========================================== -->
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<!-- Change History: -->
|
|
<!-- YYMMDD USERID Change description -->
|
|
<!-- Direct1 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
|
|
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
|
|
<!-- This file has undergone html cleanup on 04/29/02 by JET -->
|
|
<!-- End Header Records -->
|
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
|
</head>
|
|
<body>
|
|
<!-- Java sync-link -->
|
|
<script language="Javascript" src="../rzahg/synch.js" type="text/javascript">
|
|
</script>
|
|
|
|
<a name="Top_Of_Page"></a>
|
|
|
|
<h2>Qp0zPutSysEnv()--Change or Add a System-Level Environment Variable</h2>
|
|
|
|
<div class="box" style="width: 60%;">
|
|
<br>
|
|
Syntax
|
|
|
|
<pre>
|
|
#include <qp0z1170.h>
|
|
|
|
int Qp0zPutSysEnv(const char <em>*string</em>, int <em>ccsid</em>,
|
|
void <em>*reserved</em>);
|
|
</pre>
|
|
|
|
Service Program Name: QP0ZSYSE<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Default Public Authority: *USE<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Threadsafe: Yes<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
</div>
|
|
|
|
<p><strong>Qp0zPutSysEnv()</strong> function sets the value of a system-level
|
|
environment variable by altering an existing variable or creating a new
|
|
variable. In addition, it specifies a CCSID (coded character set identifier) to
|
|
be associated with the environment variable.</p>
|
|
|
|
<p>The <em>string</em> parameter points to a string of the form <samp>
|
|
name=value</samp>, where <samp>name</samp> is the environment variable and
|
|
<samp>value</samp> is the new value for it.</p>
|
|
|
|
<p>The <samp>name</samp> cannot contain a blank. For example,</p>
|
|
|
|
<pre>
|
|
PATH NAME=/my_lib/joe_user
|
|
</pre>
|
|
|
|
<p>is not valid because of the blank between <samp>PATH</samp> and <samp>
|
|
NAME</samp>. The name can contain an equal (=) symbol, but the system
|
|
interprets all characters following the first equal symbol as being the value
|
|
of the environment variable. For example,</p>
|
|
|
|
<pre>
|
|
PATH=NAME=/my_lib/joe_user
|
|
</pre>
|
|
|
|
<p>will result in a value of 'NAME=/my_lib/joe_user' for the variable PATH.</p>
|
|
|
|
<br>
|
|
<h3>Parameters</h3>
|
|
|
|
<dl>
|
|
<dt><strong><em>string</em></strong></dt>
|
|
|
|
<dd>(Input) A pointer to the <samp>name=value</samp> string.<br>
|
|
</dd>
|
|
|
|
<dt><strong><em>ccsid</em></strong></dt>
|
|
|
|
<dd>(Input) A CCSID to be associated with this environment variable. If 0 is
|
|
specified, the default CCSID for the job is used.<br>
|
|
</dd>
|
|
|
|
<dt><strong><em>reserved</em></strong></dt>
|
|
|
|
<dd>(Input) Reserved for future use. Currently, the only allowed value is
|
|
NULL.</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
<h3>Authorities</h3>
|
|
|
|
<p>*JOBCTL special authority is required to add or change a system-level
|
|
environment variable.</p>
|
|
|
|
<br>
|
|
<h3>Return Value</h3>
|
|
|
|
<table cellpadding="5">
|
|
<!-- cols="10 90" -->
|
|
<tr>
|
|
<td align="left" valign="top"><em>0</em></td>
|
|
<td align="left" valign="top"><strong>Qp0zPutSysEnv()</strong> was
|
|
successful.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top"><em>errval</em></td>
|
|
<td align="left" valign="top"><strong>Qp0zPutSysEnv()</strong> was not
|
|
successful. <em>errval</em> is set to indicate the error.</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br>
|
|
<br>
|
|
<h3>Error Conditions</h3>
|
|
|
|
<p>If <strong>Qp0zPutSysEnv()</strong> is not successful, <em>errval</em>
|
|
indicates one of the following errors.</p>
|
|
|
|
<dl compact>
|
|
<dt><em>[EFAULT]</em></dt>
|
|
|
|
<dd>
|
|
<p>The address used for an argument is not correct.</p>
|
|
|
|
<p>In attempting to use an argument in a call, the system detected an address
|
|
that is not valid.</p>
|
|
|
|
<p>While attempting to access a parameter passed to this function, the system
|
|
detected an address that is not valid.</p>
|
|
</dd>
|
|
|
|
<dt><em>[EINVAL]</em></dt>
|
|
|
|
<dd>
|
|
<p>The value specified for the argument is not correct.</p>
|
|
|
|
<p>A function was passed incorrect argument values, or an operation was
|
|
attempted on an object and the operation specified is not supported for that
|
|
type of object.</p>
|
|
|
|
<p>An argument value is not valid, out of range, or NULL.</p>
|
|
|
|
<p>For example, the <em>string</em> parameter was not in the correct format or
|
|
the value for the <em>reserved</em> parameter was not NULL.</p>
|
|
</dd>
|
|
|
|
<dt><em>[ENOMEM]</em></dt>
|
|
|
|
<dd>
|
|
<p>Storage allocation request failed.</p>
|
|
|
|
<p>A function needed to allocate storage, but no storage is available.</p>
|
|
|
|
<p>There is not enough memory to perform the requested function. (There is a
|
|
limit of 4095 system-level environment variables.)</p>
|
|
</dd>
|
|
|
|
<dt><em>[EOPNOTSUPP]</em></dt>
|
|
|
|
<dd>
|
|
<p>Operation not supported.</p>
|
|
|
|
<p>The operation, though supported in general, is not supported for the
|
|
requested object or the requested arguments.</p>
|
|
|
|
<p>This error is returned if the environment variable that is being added is
|
|
QIBM_CHILD_JOB_SNDINQMSG. See <strong>spawn()</strong> in or <strong>
|
|
spawnp()</strong> in for details on QIBM_CHILD_JOB_SNDINQMSG.</p>
|
|
</dd>
|
|
|
|
<dt><em>[EPERM]</em></dt>
|
|
|
|
<dd>
|
|
<p>Operation not permitted.</p>
|
|
|
|
<p>You must have appropriate privileges or be the owner of the object or other
|
|
resource to do the requested operation.</p>
|
|
|
|
<p>You must have *JOBCTL special authority to add or change system-level
|
|
environment variables.</p>
|
|
</dd>
|
|
|
|
<dt><em>[EUNKNOWN]</em></dt>
|
|
|
|
<dd>
|
|
<p>Unknown system state.</p>
|
|
|
|
<p>The operation failed because of an unknown system state. See any messages in
|
|
the job log and correct any errors that are indicated, then retry the
|
|
operation.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
<h3>Usage Notes</h3>
|
|
|
|
<ol>
|
|
<li>No translation is done based on the CCSID. The CCSID is just stored and
|
|
retrieved as an integer value associated with each environment variable.</li>
|
|
</ol>
|
|
|
|
<br>
|
|
<h3>Related Information</h3>
|
|
|
|
<ul>
|
|
<li>The <<strong>qp0z1170.h</strong>> file (see <a href="unix13.htm">
|
|
Header Files for UNIX-Type Functions</a>)</li>
|
|
|
|
<li><a href="evgetenv.htm">getenv()</a>--Get Value of Environment Variable</li>
|
|
|
|
<li><a href="evputenv.htm">putenv()</a>--Change or Add Environment
|
|
Variable</li>
|
|
|
|
<li><a href="evdltenv.htm">Qp0zDltEnv()</a>--Delete an Environment
|
|
Variable</li>
|
|
|
|
<li><a href="evdltsev.htm">Qp0zDltSysEnv()</a>--Delete a System-Level
|
|
Environment Variable</li>
|
|
|
|
<li><a href="evgetall.htm">Qp0zGetAllSysEnv()</a>--Get All System-Level
|
|
Environment Variables</li>
|
|
|
|
<li><a href="evgenvxt.htm">Qp0zGetEnv()</a>--Get Value of Environment Variable
|
|
(Extended)</li>
|
|
|
|
<li><a href="evgetsev.htm">Qp0zGetSysEnv()</a>--Get Value of System-Level
|
|
Environment Variable</li>
|
|
|
|
<li><a href="evinenv.htm">Qp0zInitEnv()</a>--Initialize Environment for
|
|
Variables</li>
|
|
|
|
<li><a href="evpenvxt.htm">Qp0zPutEnv()</a>--Change or Add Environment Variable
|
|
(Extended)</li>
|
|
</ul>
|
|
|
|
<br>
|
|
<h3>Example</h3>
|
|
|
|
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
|
|
for information pertaining to code examples.</p>
|
|
|
|
<p>The following example uses <strong>Qp0zPutSysEnv()</strong>, <strong>
|
|
Qp0zGetSysEnv()</strong>, and <strong>Qp0zDltSysEnv()</strong>.</p>
|
|
|
|
<pre>
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <qp0z1170.h>
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
char *var1 = "PATH=/:/home";
|
|
char *name1 = "PATH";
|
|
char *val1 = NULL;
|
|
int rc, ccsid, size;
|
|
|
|
/* Add the system-level variable PATH */
|
|
/* using default ccsid */
|
|
ccsid = 0;
|
|
rc = Qp0zPutSysEnv(var1, ccsid, NULL);
|
|
if(rc != 0)
|
|
{
|
|
printf("Error from Qp0zPutSysEnv while adding <%s>\n",var1);
|
|
printf("errno = %d\n",rc);
|
|
return rc;
|
|
}
|
|
|
|
printf("<%s> added to system-level env var list\n",var1);
|
|
|
|
/* Get the value of the variable PATH */
|
|
size = 100;
|
|
val1 = (char *)malloc(size);
|
|
|
|
rc = Qp0zGetSysEnv(name1, val1, &size, &ccsid, NULL);
|
|
if(rc == ENOSPC)
|
|
{
|
|
/* The buffer size was not enough to get the value */
|
|
/* Increase the buffer to size */
|
|
val1 = (char *)realloc(val1, size);
|
|
rc = Qp0zGetSysEnv(name1, val1, &size, &ccsid, NULL);
|
|
}
|
|
|
|
if(rc != 0)
|
|
{
|
|
printf("Error from Qp0zGetSysEnv while retrieving");
|
|
printf("<%s>, errno = %d\n", name1, rc);
|
|
return rc;
|
|
}
|
|
|
|
printf("<%s> retrieved, value is <%s>\n",name1,val1);
|
|
|
|
/* Delete the PATH variable */
|
|
rc = Qp0zDltSysEnv(name1, NULL);
|
|
if(rc != 0)
|
|
{
|
|
printf("Error from Qp0zDltSysEnv while deleting");
|
|
printf("<%s>, errno = %d\n", name1, rc);
|
|
return rc;
|
|
}
|
|
|
|
printf("<%s> deleted from system-level env var list\n",name1);
|
|
|
|
return 0;
|
|
}
|
|
</pre>
|
|
|
|
<p><strong>Output:</strong></p>
|
|
|
|
<pre>
|
|
<PATH=/:/home> added to system-level variable list
|
|
<PATH> retrieved, value is </:/home>
|
|
<PATH> deleted from system-level variable list
|
|
</pre>
|
|
|
|
<p>For other examples, see the two-part example in API <a href="../apiref/apiexmp.htm">
|
|
Examples</a> for saving and restoring system-level environment variables.</p>
|
|
|
|
<br>
|
|
<hr>
|
|
API introduced: V4R4
|
|
|
|
<hr>
|
|
<center>
|
|
<table cellpadding="2" cellspacing="2">
|
|
<tr align="center">
|
|
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
|
|
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
</body>
|
|
</html>
|
|
|