ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/evgetenv.htm

244 lines
7.1 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<!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>getenv()--Get Value of 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 -->
<!-- UNIX1 SCRIPT A converted by B2H R4.1 (346) (CMS) by V2DCIJB at -->
<!-- RCHVMW2 on 1 Jun 1999 at 16:17:47 -->
<!-- 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>getenv()--Get Value of Environment Variable</h2>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;Syntax
<pre>
#include &lt;stdlib.h&gt;
char *getenv(const char <em>*name</em>);
</pre>
&nbsp;&nbsp;Service Program Name: QP0ZCPA<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Yes. See Usage Notes for more information.<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>getenv()</strong> function searches the job-level environment
list for a string of the form <samp>name=value</samp>, where <samp>name</samp>
is the environment variable and <samp>value</samp> is the value of the
variable.</p>
<p>The <em>name</em> parameter does not include the equal (=) symbol or the
<samp>value</samp> of the environment variable <samp>name=value</samp>
pair.</p>
<br>
<!-- Please NOTE: DO NOT DELETE THIS SECTION if this API has no authorities and locks. -->
<!-- Instead, use the commented out coding below to indicate NONE. -->
<h3>Authorities and Locks</h3>
<!-- Use this if there are no authorities and locks. -->
<p>None.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong><em>name</em></strong></dt>
<dd>(Input) The name of an environment variable.</dd>
</dl>
<br>
<h3>Return Value</h3>
<table width="100%">
<tr>
<td align="left" valign="top" width="10%"><strong><em>value</em></strong></td>
<td align="left" valign="top" width="90%"><strong>getenv()</strong>
successfully found the environment string. The value returned is a pointer to
the string containing the <samp>value</samp> for the specified <samp>
name</samp> in the current environment.</td>
</tr>
<tr>
<td align="left" valign="top" width="10%"><strong><em>NULL</em></strong></td>
<td align="left" valign="top" width="90%"><strong>getenv()</strong> could not
find the environment string. The <em>errno</em> variable is set to indicate the
error.</td>
</tr>
</table>
<br>
<br>
<h3>Error Conditions</h3>
<p>If <strong>getenv()</strong> is not successful, <em>errno</em> indicates one
of the following errors.</p>
<dl compact>
<dt><em>[EDAMAGE]</em></dt>
<dd>
<p>A damaged object was encountered.</p>
<p>A referenced object is damaged. The object cannot be used.</p>
</dd>
<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>[ENOENT]</em></dt>
<dd>
<p>No such path or directory.</p>
<p>The directory or a component of the path name specified does not exist.</p>
<p>A named file or directory does not exist or is an empty string.</p>
<p>No entry found for name specified.</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>Although <strong>getenv()</strong> is threadsafe, if a thread calls an
environment variable function while another thread is accessing an environment
variable from the environ array the thread may see undefined results. The
environ array can be accessed directly or by using a pointer returned from the
<strong>getenv()</strong> or <strong>Qp0zGetEnv()</strong> functions. The
environment contents are only protected during calls to the environment
variable functions.<br>
<br>
</li>
<li>All environment variables are stored with an associated CCSID (coded
character set identifier). Unless a different CCSID is specified, such as by
using <strong>Qp0zPutEnv()</strong>, the default CCSID for the job is used as
the CCSID associated with each environment variable string.<br>
<br>
</li>
<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><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>
<li><a href="evputsev.htm">Qp0zPutSysEnv()</a>--Change or Add a System-Level
Environment</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>See the example of using <strong>getenv()</strong> in <a href=
"evputenv.htm">putenv()</a>--Change or Add Environment Variable.</p>
<p>For other examples, see the following:</p>
<ul>
<li><a href="../apiref/apiexusvar.htm">Using Environment Variables</a><br>
</li>
<li><a href="../apiref/apiexuspro.htm">Using the Spawn Process and Wait for Child
Process APIs</a><br>
</li>
<li><a href="spawnu.htm#spawnuexmp">Using the Spawn Process (using NLS-enabled
path name)</a></li>
</ul>
<br>
<hr>
API introduced: V3R6
<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>