Skip to content
Snippets Groups Projects
NuttxUserGuide.html 224 KiB
Newer Older
patacongo's avatar
patacongo committed
    #include <pthread.h>
    int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
<p>
<b>Input Parameters:</b>
<p>
<ul>
  <li><code>To be provided</code>.</li>
</ul>
<p>
<b>Returned Values:</b>
<p>
If successful, the <I>pthread_cond_init()</I> function will return
patacongo's avatar
patacongo committed
zero (<I>OK</I>).  Otherwise, an error number will be
returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadconddestroy">2.9.40 pthread_cond_destroy</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_cond_destroy(pthread_cond_t *cond);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
<p>
<b>Input Parameters:</b>
<p>
<ul>
  <li><code>To be provided</code>.</li>
</ul>
<p>
<b>Returned Values:</b>
<p>
If successful, the <I>pthread_cond_destroy()</I> function will return
patacongo's avatar
patacongo committed
zero (<I>OK</I>).  Otherwise, an error number will be
returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadcondbroadcast">2.9.41 pthread_cond_broadcast</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_cond_broadcast(pthread_cond_t *cond);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
<p>
<b>Input Parameters:</b>
<p>
<ul>
  <li><code>To be provided</code>.</li>
</ul>
<p>
<b>Returned Values:</b>
<p>
If successful, the <I>pthread_cond_broadcast()</I> function will return
patacongo's avatar
patacongo committed
zero (<I>OK</I>).  Otherwise, an error number will be
returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadcondsignal">2.9.42 pthread_cond_signal</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_cond_signal(pthread_cond_t *dond);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
<p>
<b>Input Parameters:</b>
<p>
<ul>
  <li><code>To be provided</code>.</li>
</ul>
<p>
<b>Returned Values:</b>
<p>
If successful, the <I>pthread_cond_signal()</I> function will return
patacongo's avatar
patacongo committed
zero (<I>OK</I>).  Otherwise, an error number will be
returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadcondwait">2.9.43 pthread_cond_wait</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
<p>
<b>Input Parameters:</b>
<p>
<ul>
  <li><code>To be provided</code>.</li>
</ul>
<p>
patacongo's avatar
patacongo committed
  <b>Returned Values:</b>
patacongo's avatar
patacongo committed
<p>
If successful, the <I>pthread_cond_wait()</I> function will return
patacongo's avatar
patacongo committed
zero (<I>OK</I>).  Otherwise, an error number will be
returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadcondtimedwait">2.9.44 pthread_cond_timedwait</a></H3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
				  const struct timespec *abstime);
patacongo's avatar
patacongo committed
</pre>
<p>
  <b>Description:</b>
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
patacongo's avatar
patacongo committed
  <li><code>To be provided</code>.</li>
patacongo's avatar
patacongo committed
</ul>
<p>
  <b>Returned Values:</b>
</p>
<p>
  If successful, the <code>pthread_cond_timedwait()</code> function will return
  zero (<code>OK</code>).  Otherwise, an error number will be
  returned to indicate the error:
</p>
<ul>
patacongo's avatar
patacongo committed
  <li><code>To be provided</code>. </li>
patacongo's avatar
patacongo committed
</ul>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierattrinit">2.9.45 pthread_barrierattr_init</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrierattr_init(FAR pthread_barrierattr_t *attr);
</pre>
<p>
  <b>Description:</b>
  The <code>pthread_barrierattr_init()</code> function will initialize a barrier
  attribute object <code>attr</code> with the default value for all of the attributes
  defined by the implementation.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<ul>
  <li>
    <code>attr</code>. Barrier attributes to be initialized.
</li>
</ul>
<p>
  <b>Returned Values:</b>
  0 (<code>OK</code>) on success or <code>EINVAL</code> if <code>attr</code> is invalid.
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierattrdestroy">2.9.46 pthread_barrierattr_destroy</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrierattr_destroy(FAR pthread_barrierattr_t *attr);
</pre>
<p>
  <b>Description:</b>
  The <code>pthread_barrierattr_destroy()</code> function will destroy a barrier attributes object.
  A destroyed attributes object can be reinitialized using <code>pthread_barrierattr_init()</code>;
  the results of otherwise referencing the object after it has been destroyed are undefined.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<ul>
  <li>
    <code>attr</code>. Barrier attributes to be destroyed.
</li>
</ul>
<p>
  <b>Returned Values:</b> 0 (OK) on success or EINVAL if attr is invalid.
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierattrsetpshared">2.9.47 pthread_barrierattr_setpshared</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrierattr_setpshared(FAR pthread_barrierattr_t *attr, int pshared);
</pre>
<p>
  <b>Description:</b>
  The process-shared attribute is set to <code>PTHREAD_PROCESS_SHARED</code> to permit
  a barrier to be operated upon by any thread that has access to the memory where the
  barrier is allocated.
  If the process-shared attribute is <code>PTHREAD_PROCESS_PRIVATE</code>, the barrier can
  only be operated upon by threads created within the same process as the thread that
  initialized the barrier.
  If threads of different processes attempt to operate on such a barrier, the behavior is undefined.
  The default value of the attribute is <code>PTHREAD_PROCESS_PRIVATE</code>.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<ul>
  <li><code>attr</code>. Barrier attributes to be modified.</li>
  <li><code>pshared</code>. The new value of the pshared attribute.</li>
</ul>
<p>
  <b>Returned Values:</b>  0 (<code>OK</code>) on success or <code>EINVAL</code> if either
  <code>attr</code> is invalid or <code>pshared</code> is not one of
  <code>PTHREAD_PROCESS_SHARED</code> or <code>PTHREAD_PROCESS_PRIVATE</code>.
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierattrgetpshared">2.9.48 pthread_barrierattr_getpshared</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrierattr_getpshared(FAR const pthread_barrierattr_t *attr, FAR int *pshared);
</pre>
<p>
  <b>Description:</b>
  The <code>pthread_barrierattr_getpshared()</code> function will obtain the value of the
  process-shared attribute from the attributes object referenced by <code>attr</code>.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li><code>attr</code>. Barrier attributes to be queried.</li>
  <li><code>pshared</code>. The location to stored the current value of the pshared attribute.</li>
</ul>
<p>
  <b>Returned Values:</b> 0 (<code>OK</code>) on success or <code>EINVAL</code> if
  either <code>attr</code> or <code>pshared</code> is invalid.
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierinit">2.9.49 pthread_barrier_init</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrier_init(FAR pthread_barrier_t *barrier,
                             FAR const pthread_barrierattr_t *attr, unsigned int count);
</pre>
<p>
  <b>Description:</b>
  The <code>pthread_barrier_init()</code> function allocates any resources required to
  use the barrier referenced by <code>barrier</code> and initialized the barrier with
  the attributes referenced by <code>attr</code>. 
  If <code>attr</code> is NULL, the default barrier attributes will be used.
  The results are undefined if <code>pthread_barrier_init()</code> is called when any
  thread is blocked on the barrier.
  The results are undefined if a barrier is used without first being initialized.
  The results are undefined if <code>pthread_barrier_init()</code> is called specifying
  an already initialized barrier.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<ul>
  <li>
    <code>barrier</code>.
    The barrier to be initialized.
  </li>
  <li>
    <code>attr</code>.
    Barrier attributes to be used in the initialization.
  </li>
  <li>
    <code>count</code>.
    The count to be associated with the barrier.
    The count argument specifies the number of threads that must call
    <code>pthread_barrier_wait()</code> before any of them successfully return from the call.
    The value specified by count must be greater than zero.
  </li>
</ul>
<p>
  <b>Returned Values:</b>0 (OK) on success or on of the following error numbers:
</p>
<ul>
  <li>
    <code>EAGAIN</code>.
    The system lacks the necessary resources to initialize another barrier.
  </li>
  <li>
    <code>EINVAL</code>.
    The barrier reference is invalid, or the values specified by attr are invalid, or
    the value specified by count is equal to zero.
  </li>
  <li>
    <code>ENOMEM</code>.
    Insufficient memory exists to initialize the barrier.
  </li>
  <li>
    <code>EBUSY</code>.
    The implementation has detected an attempt to reinitialize a barrier while it is in use.
  </li>
</ul>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierdestroy">2.9.50 pthread_barrier_destroy</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrier_destroy(FAR pthread_barrier_t *barrier);
</pre>
<p>
  <b>Description:</b>
  The <code>pthread_barrier_destroy()</code> function destroys the barrier referenced
  by <code>barrie</code> and releases any resources used by the barrier.
  The effect of subsequent use of the barrier is undefined until the barrier is
  reinitialized by another call to <code>pthread_barrier_init()</code>.
  The results are undefined if <code>pthread_barrier_destroy()</code> is called when
  any thread is blocked on the barrier, or if this function is called with an
  uninitialized barrier.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<ul>
  <li><code>barrier</code>. The barrier to be destroyed.</li>
</ul>
<p>
  <b>Returned Values:</b> 0 (<code>OK</code>) on success or on of the following error numbers:
</p>
<ul>
  <li>
    <code>EBUSY</code>.
    The implementation has detected an attempt to destroy a barrier while it is in use.
  </li>
  <li>
    <code>EINVAL</code>.
    The value specified by barrier is invalid.
  </li>
</ul>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierwait">2.9.51 pthread_barrier_wait</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrier_wait(FAR pthread_barrier_t *barrier);
</pre>
<p>
  <b>Description:</b>
  The <code>pthread_barrier_wait()</code> function synchronizse participating
  threads at the barrier referenced by <code>barrier</code>.
  The calling thread is blocked until the required number of threads have called
  <code>pthread_barrier_wait()</code> specifying the same <code>barrier</code>.
  When the required number of threads have called <code>pthread_barrier_wait()</code>
  specifying the <code>barrier</code>, the constant <code>PTHREAD_BARRIER_SERIAL_THREAD</code>
  will be returned to one unspecified thread and zero will be returned to each of
  the remaining threads.
  At this point, the barrier will be reset to the state it had as a result of the most
  recent <code>pthread_barrier_init()</code> function that referenced it.
</p>
<p>
  The constant <code>PTHREAD_BARRIER_SERIAL_THREAD</code> is defined in 
 <code>pthread.h</code> and its value must be distinct from any other value
  returned by <code>pthread_barrier_wait()</code>.
</p>
<p>
  The results are undefined if this function is called with an uninitialized barrier.
</p>
<p>
  If a signal is delivered to a thread blocked on a barrier, upon return from the
  signal handler the thread will resume waiting at the barrier if the barrier wait
  has not completed.
  Otherwise, the thread will continue as normal from the completed barrier wait.
  Until the thread in the signal handler returns from it, it is unspecified whether
  other threads may proceed past the barrier once they have all reached it.
</p>
<p>
  A thread that has blocked on a barrier will not prevent any unblocked thread that
  is eligible to use the same processing resources from eventually making forward
  progress in its execution.
  Eligibility for processing resources will be determined by the scheduling policy.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<ul>
  <li><code>barrier</code>. The barrier on which to wait.</li>
</ul>
<p>
  <b>Returned Values:</b> 0 (<code>OK</code>) on success or <code>EINVAL</code> if the barrier is not valid.
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>


<h3><a name="pthreadonce">2.9.52 pthread_once</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_once(FAR pthread_once_t *once_control, CODE void (*init_routine)(void));
</pre>
<p>
  <b>Description:</b>
  The  first  call to <code>pthread_once()</code> by any thread with a given
  <code>once_control</code>, will call the <code>init_routine()</code> with no arguments.
  Subsequent calls to <code>pthread_once()</code> with the same <code>once_control</code> will have no effect.
  On return from <code>pthread_once()</code>, <code>init_routine()</code> will have completed.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li>
    <code>once_control</code>.
    Determines if <code>init_routine()</code> should be called.
    <code>once_control</code> should be declared and intialized as follows:
    <ul><pre>pthread_once_t once_control = PTHREAD_ONCE_INIT;
    </pre></ul>
    <code>PTHREAD_ONCE_INIT</code> is defined in <code>pthread.h</code>.
  </li>
  <li>
    <code>init_routine</code>.
    The initialization routine that will be called once.
  </li>
</ul>
<p>
  <b>Returned Values:</b>
  0 (OK) on success or EINVAL if either once_control or init_routine are invalid.
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadkill">2.9.53 pthread_kill</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;signal.h&gt;
    #include &lt;pthread.h&gt;
    int pthread_kill(pthread_t thread, int signo)
</pre>
<p>
  <b>Description:</b>
  The <code>pthread_kill()</code> system call can be used to send any
  signal to a thread.  See <code>kill()</code> for further information
  as this is just a simple wrapper around the <code>kill()</code>
  function.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li>
    <code>thread</code>.
    The id of the thread to receive the signal. Only positive, non-zero values of <code>tthread</code>t are supported.
  </li>
  <li>
    <code>signo</code>.
    The signal number to send.  If <code>signo</code> is zero, no signal is sent, but all error checking is performed.
  </li>
</ul>
<p>
  <b>Returned Values:</b>
</p>
<p>
  On success, the signal was sent and zero is returned.
  On error one of the following error numbers is returned.
</p>
<ul>
  <li>
    <code>EINVAL</code>.
    An invalid signal was specified.
  </li>
  <li>
    <code>EPERM</code>.
    The thread does not have permission to send the signal to the target thread.
  </li>
  <li>
    <code>ESRCH</code>.
    No thread could be found corresponding to that specified by the given thread ID.
  </li>
  <li>
    <code>ENOSYS</code>.
    Do not support sending signals to process groups.
  </li>
</ul>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadsigmask">2.9.54 pthread_sigmask</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;signal.h&gt;
    #include &lt;pthread.h&gt;
    int pthread_sigmask(int how, FAR const sigset_t *set, FAR sigset_t *oset);
</pre>
<p>
  <b>Description:</b>
  This function is a simple wrapper around <code>sigprocmask()</code>.
  See the <code>sigprocmask()</code> function description for further information.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li>
    <code>how</code>. How the signal mast will be changed:
    <ul>
      <li>
        <code>SIG_BLOCK</code>:
        The resulting set is the union of the current set and the signal set pointed to by <code>set</code>.
      </li>
      <li>
        <code>SIG_UNBLOCK</code>:
        The resulting set is the intersection of the current set and the complement of the signal set pointed to by <code>set</code>.
      </li>
      <li>
        <code>SIG_SETMASK</code>:
        The resulting set is the signal set pointed to by <code>set</code>.
      </li>
    </ul>
  </li>
  <li>
    <code>set</code>. Location of the new signal mask.
  </li>
  <li>
    <code>oset</code>. Location to store the old signal mask.
  </li>
</ul>
<p>
  <b>Returned Values:</b>
</p>
<p>
  0 (OK) on succes or EINVAL if <code>how</code> is invalid.
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>
patacongo's avatar
patacongo committed

<h1><a name="Environ">2.10 Environment Variables</a></h1>
<p><b>Overview</b>.
  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 mulit-processing OS:
</p>
<ul>
  <li><b>Task environments</b>.
    When a new task is created using <a 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.
  </li>
  <li><b>Thread environments</b>.
    When a pthread is created using <a href="#pthreadcreate">pthread_create</a>, the child
    thread also inherits that envirnment of the parent.
    However, the child does not recieve a copy of the environment but, rather, shares the same
    environment.
    Changes to the environment are visiable to all threads with the same parentage.
  </li>
</ul>
<p><b>Programming Interfaces</b>.
  The following environment variable programming interfaces are provided by Nuttx and are
  described in detail in the following paragraphs.
</p>
<ul>
  <li><a href="#getenv">2.10.1 <code>getenv</code></a></li>
  <li><a href="#putenv">2.10.2 <code>putenv</code></a></li>
  <li><a href="#clearenv">2.10.3 <code>clearenv</code></a></li>
  <li><a href="#setenv">2.10.4 <code>setenv</code></a></li>
  <li><a href="#unsetenv">2.10.5 <code>unsetenv</code></a></li>
</ul>
<p><b>Disabling Environment Variable Support</b>.
  All support for environment variables can be disabled by setting <code>CONFIG_DISABLE_ENVIRONMENT</code>
  in the board configuration file.
</p>

<h2><a name="getenv">2.10.1 <code>getenv</code></a></h2>
<p>
  <b>Function Prototype:</b>
</p>
<pre>
  #include <stdlib.h>
  FAR char *getenv(const char *name);
</pre>
<p>
  <b>Description:</b>
    The <code>getenv()</code> function searches the environment list for a string that
    matches the string pointed to by <code>name</code>.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li>
    <code>name</code>.
    The name of the variable to find.
  </li>
</ul>
<p>
  <b>Returned Values:</b>
   The value of the valiable (read-only) or NULL on failure.
</p>

<h2><a name="putenv">2.10.2 <code>putenv</code></a></h2>
<p>
  <b>Function Prototype:</b>
</p>
<pre>
  #include <stdlib.h>
  int putenv(char *string);
</pre>
<p>
  <b>Description:</b>
  The <code>putenv()</code> function adds or changes the value of environment variables.
  The argument string is of the form <i>name=value</i>. 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>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li>
    <code>string</code>
    name=value string describing the environment setting to add/modify.
  </li>
</ul>
<p>
  <b>Returned Values:</b>
  Zero on sucess.
</p>

<h2><a name="clearenv">2.10.3 <code>clearenv</code></a></h2>
<p>
  <b>Function Prototype:</b>
</p>
<pre>
  #include <stdlib.h>
  int clearenv(void);
</pre>
<p>
  <b>Description:</b>
  The <code>clearenv()</code> function clears the environment of all name-value pairs
  and sets the value of the external variable environ to NULL.
</p>
<p>
  <b>Input Parameters:</b>
  None
</p>
<p>
  <b>Returned Values:</b>
  Zero on success.
</p>

<h2><a name="setenv">2.10.4 <code>setenv</code></a></h2>
<p>
  <b>Function Prototype:</b>
</p>
<pre>
  #include <stdlib.h>
  int setenv(const char *name, const char *value, int overwrite);
</pre>
<p>
  <b>Description:</b>
  The <code>setenv()</code> function adds the variable <code>name</code> to the environment with the
  specified <code>value</code> if the variable <code>name</code> does not exist. If the <code>name</code>
  does exist in the environment, then its value is changed to <code>value</code> if <code>overwrite</code>
  is non-zero; if <code>overwrite</code> is zero, then the value of <code>name</code> is unaltered.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li>
    <code>name</code>
    The name of the variable to change.
  </li>
  <li>
    <code>value</code>
    The new value of the variable.
  </li>
  <li>
    <code>value</code>
    Replace any existing value if non-zero.
  </li>
</ul>
<p>
  <b>Returned Values:</b>
  Zero on success.
</p>

<h2><a name="unsetenv">2.10.5 <code>unsetenv</code></a></h2>
<p>
  <b>Function Prototype:</b>
</p>
<pre>
  #include <stdlib.h>
  int unsetenv(const char *name);
</pre>
<p>
  <b>Description:</b>
  The <code>unsetenv()</code> function deletes the variable <code>name</code> from the environment.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li>
    <code>name</code>
    The name of the variable to delete.
  </li>
</ul>
<p>
  <b>Returned Values:</b>
  Zero on success.
</p>

patacongo's avatar
patacongo committed
<h1><a name="FileSystem">2.11 File System Interfaces</a></h1>

patacongo's avatar
patacongo committed
<ul>
  <li><a href="#FileSystemOverview">2.11.1 NuttX File System Overview</a></li>
  <li><a href="#driveroperations">2.11.2 Driver Operations</a></li>
  <li><a href="#directoryoperations">2.11.3 Directory Operations</a></li>
  <li><a href="#standardio">2.11.4 Standard I/O</a></li>
  <li><a href="#PipesNFifos">2.11.5 Pipes and FIFOs</a></li>
  <li><a href="#fatsupport">2.11.6 FAT File System Support</a></li>
</ul>

<h2><a name="FileSystemOverview">2.11.1 NuttX File System Overview</a></h2>
patacongo's avatar
patacongo committed

patacongo's avatar
patacongo committed
<p><b>Overview</b>.
  NuttX includes an optional, scalable file system.
  This file-system may be omitted altogther; NuttX does not depend on the presence
  of any file system.
</p>

<p><b>Pseudo Root File System</b>.
  Or, a simple <i>in-memory</i>, <i>psuedo</i> file system can be enabled.
  This simple file system can be enabled setting the CONFIG_NFILE_DESCRIPTORS
  option to a non-zero value.
  This is an <i>in-memory</i> file system because it does not require any
  storage medium or block driver support.
  Rather, file system contents are generated on-the-fly as referenced via
  standard file system operations (open, close, read, write, etc.).
  In this sense, the file system is <i>psuedo</i> file system (in the
  same sense that the Linux <code>/proc</code> file system is also
  referred to as a psuedo file system).
</p>

<p>
  Any user supplied data or logic can be accessed via the psuedo-file system.
  Built in support is provided for character and block drivers in the
  <code>/dev</code> psuedo file system directory.
</p>

<p><b>Mounted File Systems</b>
  The simple in-memory file system can be extended my mounting block
  devices that provide access to true file systems backed up via some
  mass storage device.
  NuttX supports the standard <code>mount()</code> command that allows
  a block driver to be bound to a mountpoint within the psuedo file system
  and to a a file system.
  At present, NuttX supports only the VFAT file system.
</p>

<p><b>Comparison to Linux</b>
  From a programming perspective, the NuttX file system appears very similar
  to a Linux file system.
  However, there is a fundamental difference:
  The NuttX root file system is a psuedo file system and true file systems may be
  mounted in the psuedo file system.
  In the typical Linux installation by comparison, the Linux root file system
  is a true file system and psuedo file systems may be mounted in the true,
  root file system.
  The approach selected by NuttX is intended to support greater scalability
  from the very tiny platform to the moderate platform.
</p>

<p><b>File System Interfaces</b>.
  The NuttX file system simply supports a set of standard, file system APIs
  (<code>open()</code>, <code>close()</code>, <code>read()</code>, <code>write</code>, etc.)
  and a registration mechanism that allows devices drivers to a associated with <i>nodes</i>
  in a file-system-like name space.
</p>

patacongo's avatar
patacongo committed
<h2><a name="driveroperations">2.11.2 Driver Operations</a></h2>
<a name="drvrfcntlops">
<ul><pre>
  #include &lt;fcntl.h&gt;
  int open(const char *path, int oflag, ...);
</pre></ul>
<a name="drvrunistdops">
<ul><pre>
  #include &lt;unistd.h&gt;
patacongo's avatar
patacongo committed
  int     close(int fd);
  int     dup(int fildes);
  int     dup2(int fildes1, int fildes2);
  off_t   lseek(int fd, off_t offset, int whence);
  ssize_t read(int fd, void *buf, size_t nbytes);
  int     unlink(const char *path);
  ssize_t write(int fd, const void *buf, size_t nbytes);
</pre></ul>
<a name="drvrioctlops">
<ul><pre>
  #include &lt;sys/ioctl.h&gt;
patacongo's avatar
patacongo committed
  int     ioctl(int fd, int req, unsigned long arg);
</pre></ul>
patacongo's avatar
patacongo committed
<h2><a name="directoryoperations">2.11.3 Directory Operations</a></h2>
<a name="dirdirentops">
<ul><pre>
  #include &lt;dirent.h&gt;
  int        closedir(DIR *dirp);
  FAR DIR   *opendir(const char *path);
  FAR struct dirent *readdir(FAR DIR *dirp);
  int        readdir_r(FAR DIR *dirp, FAR struct dirent *entry, FAR struct dirent **result);
  void       rewinddir(FAR DIR *dirp);
  void       seekdir(FAR DIR *dirp, int loc);
  int        telldir(FAR DIR *dirp);
</pre></ul>
</a>

<a name="dirunistdops">
patacongo's avatar
patacongo committed
<ul><pre>
  #include &lt;unistd.h&gt;
  int       chdir(FAR const char *path);
  FAR char *getcwd(FAR char *buf, size_t size);
</pre></ul>
patacongo's avatar
patacongo committed
<h2><a name="standardio">2.11.4 Standard I/O</a></h2>
<ul><pre>
  #include &lt;stdio.h&gt;
  int    fclose(FILE *stream);
  int    fflush(FILE *stream);
  int    feof(FILE *stream);                               /* Prototyped but not implemented */
  int    ferror(FILE *stream);                             /* Prototyped but not implemented */
  int    fgetc(FILE *stream);
  int    fgetpos(FILE *stream, fpos_t *pos);
  char  *fgets(char *s, int n, FILE *stream);
  FILE  *fopen(const char *path, const char *type);
  int    fprintf(FILE *stream, const char *format, ...);
  int    fputc(int c, FILE *stream);
  int    fputs(const char *s, FILE *stream);
  size_t fread(void *ptr, size_t size, size_t n_items, FILE *stream);
  int    fseek(FILE *stream, long int offset, int whence);
  int    fsetpos(FILE *stream, fpos_t *pos);
  long   ftell(FILE *stream);
  size_t fwrite(const void *ptr, size_t size, size_t n_items, FILE *stream);
  char  *gets(char *s);

  int    printf(const char *format, ...);
  int    puts(const char *s);
  int    rename(const char *source, const char *target);
  int    sprintf(char *dest, const char *format, ...);
  int    ungetc(int c, FILE *stream);
  int    vprintf(const char *s, va_list ap);
  int    vfprintf(FILE *stream, const char *s, va_list ap);
  int    vsprintf(char *buf, const char *s, va_list ap);

  FILE  *fdopen(int fd, const char *type);
  int    fstat(int fd, FAR struct stat *buf);              /* Prototyped but not implemented */
  int    mkdir(const char *path, mode_t mode);
  int    rmdir(const char *path);
  int    stat(const char *path, FAR struct stat *buf);
  int    statfs(const char *path, FAR struct statfs *buf); /* Prototyped but not implemented */
</pre></ul>

patacongo's avatar
patacongo committed
<h2><a name="PipesNFifos">2.11.5 Pipes and FIFOs</a></h2>