blob: a767a87ad9636245df0482849eaf50792becf15a [file] [log] [blame]
<!--
Documentation/_templates/layout.html
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. The
ASF licenses this file to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
-->
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Environment Variables &mdash; NuttX latest documentation</title>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/tabs.css" type="text/css" />
<link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
<link rel="shortcut icon" href="../../_static/favicon.ico"/>
<!--[if lt IE 9]>
<script src="../../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="File System Interfaces" href="10_filesystem.html" />
<link rel="prev" title="Pthread Interfaces" href="08_pthread.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> NuttX
<img src="../../_static/NuttX.png" class="logo" alt="Logo"/>
</a>
<!-- this version selector is quite ugly, should be probably replaced by something
more modern -->
<div class="version-selector">
<select onchange="javascript:location.href = this.value;">
<option value="../../../latest" selected="selected">latest</option>
<option value="../../../10.0.0" >10.0.0</option>
<option value="../../../10.0.1" >10.0.1</option>
<option value="../../../10.1.0" >10.1.0</option>
<option value="../../../10.2.0" >10.2.0</option>
<option value="../../../10.3.0" >10.3.0</option>
<option value="../../../11.0.0" >11.0.0</option>
<option value="../../../12.0.0" >12.0.0</option>
<option value="../../../12.1.0" >12.1.0</option>
<option value="../../../12.2.0" >12.2.0</option>
<option value="../../../12.2.1" >12.2.1</option>
<option value="../../../12.3.0" >12.3.0</option>
<option value="../../../12.4.0" >12.4.0</option>
<option value="../../../12.5.0" >12.5.0</option>
<option value="../../../12.5.1" >12.5.1</option>
<option value="../../../12.6.0" >12.6.0</option>
<option value="../../../12.7.0" >12.7.0</option>
<option value="../../../12.8.0" >12.8.0</option>
<option value="../../../12.9.0" >12.9.0</option>
<option value="../../../12.10.0" >12.10.0</option>
<option value="../../../12.11.0" >12.11.0</option>
</select>
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Table of Contents</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../introduction/index.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../quickstart/index.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../contributing/index.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../introduction/inviolables.html">The Inviolable Principles of NuttX</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../platforms/index.html">Supported Platforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../components/index.html">OS Components</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../applications/index.html">Applications</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">API Reference</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="index.html">Userspace API</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="01_task_control.html">Task Control Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="02_task_scheduling.html">Task Scheduling Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="03_task_control.html">Task Control Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="04_message_queue.html">Named Message Queue Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="05_counting_semaphore.html">Counting Semaphore Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="06_clocks_timers.html">Clocks and Timers</a></li>
<li class="toctree-l3"><a class="reference internal" href="07_signals.html">Signal Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="08_pthread.html">Pthread Interfaces</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">Environment Variables</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#programming-interfaces">Programming Interfaces</a></li>
<li class="toctree-l4"><a class="reference internal" href="#disabling-environment-variable-support">Disabling Environment Variable Support</a></li>
<li class="toctree-l4"><a class="reference internal" href="#functions">Functions</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="10_filesystem.html">File System Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="11_network.html">Network Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="12_shared_memory.html">Shared Memory Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="13_boardctl.html">Board IOCTL</a></li>
<li class="toctree-l3"><a class="reference internal" href="13_logging.html">Logging</a></li>
<li class="toctree-l3"><a class="reference internal" href="structures.html">OS Data Structures</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../os/index.html">Architecture APIs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../faq/index.html">FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../guides/index.html">Guides</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary.html">Glossary</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">NuttX</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
<li><a href="../index.html">API Reference</a> &raquo;</li>
<li><a href="index.html">Userspace API</a> &raquo;</li>
<li>Environment Variables</li>
<li class="wy-breadcrumbs-aside">
<a href="../../_sources/reference/user/09_env_vars.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="environment-variables">
<h1>Environment Variables<a class="headerlink" href="#environment-variables" title="Permalink to this headline"></a></h1>
<p>NuttX supports environment variables that can be used to
control the behavior of programs. In the spirit of NuttX the environment
variable behavior attempts to emulate the behavior of environment
variables in the multi-processing OS:</p>
<ul class="simple">
<li><p><strong>Task environments</strong>. When a new task is created using
<a class="reference external" href="#taskcreate">task_create</a>, the environment of the child task is
an inherited, exact copy of the environment of the parent. However,
after child task has been created, subsequent operations by the child
task on its environment does not alter the environment of the parent.
No do operations by the parent effect the child’s environment. The
environments start identical but are independent and may diverge.</p></li>
<li><p><strong>Thread environments</strong>. When a pthread is created using
<a class="reference external" href="#pthreadcreate">pthread_create</a>, the child thread also inherits
that environment of the parent. However, the child does not receive a
copy of the environment but, rather, shares the same environment.
Changes to the environment are visible to all threads with the same
parentage.</p></li>
</ul>
<div class="section" id="programming-interfaces">
<h2>Programming Interfaces<a class="headerlink" href="#programming-interfaces" title="Permalink to this headline"></a></h2>
<p>The following environment variable
programming interfaces are provided by NuttX and are described in detail
in the following paragraphs.</p>
<blockquote>
<div><ul class="simple">
<li><p><a class="reference internal" href="#c.getenv" title="getenv"><code class="xref c c-func docutils literal notranslate"><span class="pre">getenv()</span></code></a></p></li>
<li><p><a class="reference internal" href="#c.putenv" title="putenv"><code class="xref c c-func docutils literal notranslate"><span class="pre">putenv()</span></code></a></p></li>
<li><p><a class="reference internal" href="#c.clearenv" title="clearenv"><code class="xref c c-func docutils literal notranslate"><span class="pre">clearenv()</span></code></a></p></li>
<li><p><a class="reference internal" href="#c.setenv" title="setenv"><code class="xref c c-func docutils literal notranslate"><span class="pre">setenv()</span></code></a></p></li>
<li><p><a class="reference internal" href="#c.unsetenv" title="unsetenv"><code class="xref c c-func docutils literal notranslate"><span class="pre">unsetenv()</span></code></a></p></li>
</ul>
</div></blockquote>
</div>
<div class="section" id="disabling-environment-variable-support">
<h2>Disabling Environment Variable Support<a class="headerlink" href="#disabling-environment-variable-support" title="Permalink to this headline"></a></h2>
<p>All support for environment
variables can be disabled by setting <code class="docutils literal notranslate"><span class="pre">CONFIG_DISABLE_ENVIRON</span></code> in the
board configuration file.</p>
</div>
<div class="section" id="functions">
<h2>Functions<a class="headerlink" href="#functions" title="Permalink to this headline"></a></h2>
<dl class="c function">
<dt id="c.getenv">
<span class="pre">FAR</span> <span class="pre">char</span> <span class="pre">*</span><code class="sig-name descname"><span class="pre">getenv</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">const</span></em> <span class="pre">char</span> <span class="pre">*</span><em><span class="pre">name</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.getenv" title="Permalink to this definition"></a><br /></dt>
<dd><p>Searches the environment list for a string that matches
the string pointed to by <code class="docutils literal notranslate"><span class="pre">name</span></code>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>name</strong> – The name of the variable to find.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The value of the variable (read-only) or NULL on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt id="c.putenv">
<span class="pre">int</span> <code class="sig-name descname"><span class="pre">putenv</span></code><span class="sig-paren">(</span><span class="pre">char</span> <span class="pre">*</span><em><span class="pre">string</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.putenv" title="Permalink to this definition"></a><br /></dt>
<dd><p>Adds or changes the value of environment variables. The
argument string is of the form <code class="docutils literal notranslate"><span class="pre">name=value</span></code>. If name does
not already exist in the environment, then string is added
to the environment. If name does exist, then the value of name in the
environment is changed to value.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>string</strong><code class="docutils literal notranslate"><span class="pre">name=value</span></code> string describing the environment setting to
add/modify.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Zero on success.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt id="c.clearenv">
<span class="pre">int</span> <code class="sig-name descname"><span class="pre">clearenv</span></code><span class="sig-paren">(</span><span class="pre">void</span><span class="sig-paren">)</span><a class="headerlink" href="#c.clearenv" title="Permalink to this definition"></a><br /></dt>
<dd><p>Clears the environment of all name-value pairs and sets
the value of the external variable environ to NULL.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>Zero on success.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt id="c.setenv">
<span class="pre">int</span> <code class="sig-name descname"><span class="pre">setenv</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">const</span></em> <span class="pre">char</span> <span class="pre">*</span><em><span class="pre">name</span></em>, <em class="property"><span class="pre">const</span></em> <span class="pre">char</span> <span class="pre">*</span><em><span class="pre">value</span></em>, <span class="pre">int</span> <em><span class="pre">overwrite</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.setenv" title="Permalink to this definition"></a><br /></dt>
<dd><p>Adds the variable <code class="docutils literal notranslate"><span class="pre">name</span></code> to the environment with the specified
<code class="docutils literal notranslate"><span class="pre">value</span></code> if the variable <code class="docutils literal notranslate"><span class="pre">name</span></code> does not exist. If the <code class="docutils literal notranslate"><span class="pre">name</span></code>
does exist in the environment, then its value is changed to <code class="docutils literal notranslate"><span class="pre">value</span></code>
if <code class="docutils literal notranslate"><span class="pre">overwrite</span></code> is non-zero; if
<code class="docutils literal notranslate"><span class="pre">overwrite</span></code> is zero, then the value of <code class="docutils literal notranslate"><span class="pre">name</span></code> is unaltered.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>name</strong> – The name of the variable to change.</p></li>
<li><p><strong>value</strong> – The new value of the variable.</p></li>
<li><p><strong>value</strong> – Replace any existing value if non-zero.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Zero on success.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt id="c.unsetenv">
<span class="pre">int</span> <code class="sig-name descname"><span class="pre">unsetenv</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">const</span></em> <span class="pre">char</span> <span class="pre">*</span><em><span class="pre">name</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.unsetenv" title="Permalink to this definition"></a><br /></dt>
<dd><p>Deletes the variable <code class="docutils literal notranslate"><span class="pre">name</span></code> from the environment.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>name</strong> – The name of the variable to delete.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Zero on success.</p>
</dd>
</dl>
</dd></dl>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="10_filesystem.html" class="btn btn-neutral float-right" title="File System Interfaces" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
<a href="08_pthread.html" class="btn btn-neutral float-left" title="Pthread Interfaces" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&#169; Copyright 2020, The Apache Software Foundation.
</p>
</div>
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>