man-pages/man3/envz_add.3.html
2021-03-31 01:06:50 +01:00

256 lines
5.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of ENVZ_ADD</TITLE>
</HEAD><BODY>
<H1>ENVZ_ADD</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
envz_add, envz_entry, envz_get, envz_merge,
envz_remove, envz_strip - environment string support
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/envz.h">envz.h</A>&gt;</B>
<B>error_t envz_add(char **</B><I>envz</I><B>, size_t *</B><I>envz_len</I><B>,</B>
<B> const char *</B><I>name</I><B>, const char *</B><I>value</I><B>);</B>
<B>char *envz_entry(const char *</B><I>envz</I><B>, size_t </B><I>envz_len</I><B>, const char *</B><I>name</I><B>);</B>
<B>char *envz_get(const char *</B><I>envz</I><B>, size_t </B><I>envz_len</I><B>, const char *</B><I>name</I><B>);</B>
<B>error_t envz_merge(char **</B><I>envz</I><B>, size_t *</B><I>envz_len</I><B>,</B>
<B> const char *</B><I>envz2</I><B>, size_t </B><I>envz2_len</I><B>, int </B><I>override</I><B>);</B>
<B>void envz_remove(char **</B><I>envz</I><B>, size_t *</B><I>envz_len</I><B>, const char *</B><I>name</I><B>);</B>
<B>void envz_strip(char **</B><I>envz</I><B>, size_t *</B><I>envz_len</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
These functions are glibc-specific.
<P>
An argz vector is a pointer to a character buffer together with a length,
see
<B><A HREF="/cgi-bin/man/man2html?3+argz_add">argz_add</A></B>(3).
An envz vector is a special argz vector, namely one where the strings
have the form &quot;name=value&quot;.
Everything after the first '=' is considered
to be the value.
If there is no '=', the value is taken to be NULL.
(While the value in case of a trailing '=' is the empty string &quot;&quot;.)
<P>
These functions are for handling envz vectors.
<P>
<B>envz_add</B>()
adds the string
name = value
(in case
<I>value</I>
is non-NULL) or
name
(in case
<I>value</I>
is NULL) to the envz vector
(<I>*envz</I>,&nbsp;<I>*envz_len</I>)
and updates
<I>*envz</I>
and
<I>*envz_len</I>.
If an entry with the same
<I>name</I>
existed, it is removed.
<P>
<B>envz_entry</B>()
looks for
<I>name</I>
in the envz vector
(<I>envz</I>,&nbsp;<I>envz_len</I>)
and returns the entry if found, or NULL if not.
<P>
<B>envz_get</B>()
looks for
<I>name</I>
in the envz vector
(<I>envz</I>,&nbsp;<I>envz_len</I>)
and returns the value if found, or NULL if not.
(Note that the value can also be NULL, namely when there is
an entry for
<I>name</I>
without '=' sign.)
<P>
<B>envz_merge</B>()
adds each entry in
<I>envz2</I>
to
<I>*envz</I>,
as if with
<B>envz_add</B>().
If
<I>override</I>
is true, then values in
<I>envz2</I>
will supersede those with the same name in
<I>*envz</I>,
otherwise not.
<P>
<B>envz_remove</B>()
removes the entry for
<I>name</I>
from
(<I>*envz</I>,&nbsp;<I>*envz_len</I>)
if there was one.
<P>
<B>envz_strip</B>()
removes all entries with value NULL.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
All envz functions that do memory allocation have a return type of
<I>error_t</I>,
and return 0 for success, and
<B>ENOMEM</B>
if an allocation error occurs.
<A NAME="lbAF">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>envz_add</B>(),
<B>envz_entry</B>(),
<BR>
<B>envz_get</B>(),
<B>envz_merge</B>(),
<BR>
<B>envz_remove</B>(),
<B>envz_strip</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<P>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
These functions are a GNU extension.
Handle with care.
<A NAME="lbAH">&nbsp;</A>
<H2>EXAMPLE</H2>
#include &lt;<A HREF="file:///usr/include/stdio.h">stdio.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/envz.h">envz.h</A>&gt;
<P>
int
main(int argc, char *argv[], char *envp[])
{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i,&nbsp;e_len&nbsp;=&nbsp;0;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;*str;
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;envp[i]&nbsp;!=&nbsp;NULL;&nbsp;i++)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e_len&nbsp;+=&nbsp;strlen(envp[i])&nbsp;+&nbsp;1;
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;str&nbsp;=&nbsp;envz_entry(*envp,&nbsp;e_len,&nbsp;&quot;HOME&quot;);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;%s\n&quot;,&nbsp;str);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;str&nbsp;=&nbsp;envz_get(*envp,&nbsp;e_len,&nbsp;&quot;HOME&quot;);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;%s\n&quot;,&nbsp;str);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_SUCCESS);
}
<A NAME="lbAI">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+argz_add">argz_add</A></B>(3)
<A NAME="lbAJ">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="4"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="5"><A HREF="#lbAF">ATTRIBUTES</A><DD>
<DT id="6"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="7"><A HREF="#lbAH">EXAMPLE</A><DD>
<DT id="8"><A HREF="#lbAI">SEE ALSO</A><DD>
<DT id="9"><A HREF="#lbAJ">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:39 GMT, March 31, 2021
</BODY>
</HTML>