man-pages/man3/envz_add.3

140 lines
3.1 KiB
Groff
Raw Normal View History

2004-11-03 13:51:07 +00:00
.\" Copyright 2002 walter harms (walter.harms@informatik.uni-oldenburg.de)
.\" Distributed under GPL
.\" based on the description in glibc source and infopages
.\"
2004-11-03 13:51:07 +00:00
.\" Corrections and additions, aeb
.TH ENVZ_ADD 3 2007-05-18 "" "Linux Programmer's Manual"
2004-11-03 13:51:07 +00:00
.SH NAME
envz_add, envz_entry, envz_get, envz_merge,
envz_remove, envz_strip \- environment string support
.SH SYNOPSIS
.nf
.B "#include <envz.h>"
2008-01-01 13:44:49 +00:00
2007-12-22 22:01:09 +00:00
.BI "error_t envz_add(char **" envz ", size_t *" envz_len ,
.ti 20n
2004-11-03 13:51:07 +00:00
.BI "const char *" name ", const char *" value );
2008-01-01 13:44:49 +00:00
2007-12-22 22:01:09 +00:00
.BI "char *envz_entry(const char *" envz ", size_t *" envz_len \
", const char *" name );
2008-01-01 13:44:49 +00:00
2007-12-22 22:01:09 +00:00
.BI "char *envz_get(const char *" envz ", size_t *" envz_len \
", const char *" name );
2008-01-01 13:44:49 +00:00
2007-12-22 22:01:09 +00:00
.BI "error_t envz_merge(char **" envz ", size_t *" envz_len ,
.ti 20n
2004-11-03 13:51:07 +00:00
.BI "const char *" envz2 ", size_t " envz2_len ", int " override );
2008-01-01 13:44:49 +00:00
2007-12-22 22:01:09 +00:00
.BI "void envz_remove(char **" envz ", size_t *" envz_len \
", const char *" name );
2008-01-01 13:44:49 +00:00
2007-12-22 22:01:09 +00:00
.BI "void envz_strip(char **" envz ", size_t *" envz_len );
2007-12-23 21:05:57 +00:00
.fi
2004-11-03 13:51:07 +00:00
.SH DESCRIPTION
2007-12-25 21:28:09 +00:00
These functions are glibc-specific.
2004-11-03 13:51:07 +00:00
.LP
An argz vector is a pointer to a character buffer together with a length,
see
.BR argz_add (3).
An envz vector is a special argz vector, namely one where the strings
have the form "name=value".
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 "".)
2004-11-03 13:51:07 +00:00
.LP
These functions are for handling envz vectors.
.LP
.BR envz_add ()
2004-11-03 13:51:07 +00:00
adds the string
.RI \&" name = value \&"
(in case
.I value
is non-NULL) or
.RI \&" name \&"
(in case
.I value
is NULL) to the envz vector
2007-12-22 22:01:09 +00:00
.RI ( *envz ,\ *envz_len )
2004-11-03 13:51:07 +00:00
and updates
2007-12-22 22:01:09 +00:00
.I *envz
2004-11-03 13:51:07 +00:00
and
2007-12-22 22:01:09 +00:00
.IR *envz_len .
2004-11-03 13:51:07 +00:00
If an entry with the same
.I name
existed, it is removed.
.LP
.BR envz_entry ()
2004-11-03 13:51:07 +00:00
looks for
.I name
in the envz vector
2007-12-22 22:01:09 +00:00
.RI ( envz ,\ envz_len )
2004-11-03 13:51:07 +00:00
and returns the entry if found, or NULL if not.
.LP
.BR envz_get ()
2004-11-03 13:51:07 +00:00
looks for
.I name
in the envz vector
2007-12-22 22:01:09 +00:00
.RI ( envz ,\ envz_len )
2004-11-03 13:51:07 +00:00
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
without \'=\' sign.)
2004-11-03 13:51:07 +00:00
.LP
.BR envz_merge ()
2004-11-03 13:51:07 +00:00
adds each entry in
.I envz2
to
2007-12-22 22:01:09 +00:00
.IR *envz ,
2004-11-03 13:51:07 +00:00
as if with
.BR envz_add ().
2004-11-03 13:51:07 +00:00
If
.I override
is true, then values in
.I envz2
will supersede those with the same name in
2007-12-22 22:01:09 +00:00
.IR *envz ,
2004-11-03 13:51:07 +00:00
otherwise not.
.LP
.BR envz_remove ()
2004-11-03 13:51:07 +00:00
removes the entry for
.I name
from
2007-12-22 22:01:09 +00:00
.RI ( *envz ,\ *envz_len )
2004-11-03 13:51:07 +00:00
if there was one.
.LP
.BR envz_strip ()
2004-11-03 13:51:07 +00:00
removes all entries with value NULL.
.SH "RETURN VALUE"
All envz functions that do memory allocation have a return type of
2005-10-19 13:17:47 +00:00
\fIerror_t\fP, and return 0 for success, and \fBENOMEM\fP
2004-11-03 13:51:07 +00:00
if an allocation error occurs.
.SH "CONFORMING TO"
These functions are a GNU extension.
Handle with care.
2004-11-03 13:51:07 +00:00
.SH EXAMPLE
.nf
#include <stdio.h>
#include <stdlib.h>
2004-11-03 13:51:07 +00:00
#include <envz.h>
2007-04-05 12:36:57 +00:00
2004-11-03 13:51:07 +00:00
int
2007-04-05 12:36:57 +00:00
main(int argc, char *argv[], char *envp[])
{
int i, e_len = 0;
char *str;
2004-11-03 13:51:07 +00:00
2007-04-05 12:36:57 +00:00
for (i=0; envp[i] != NULL; i++)
e_len += strlen(envp[i]) + 1;
2004-11-03 13:51:07 +00:00
2007-04-05 12:36:57 +00:00
str = envz_entry(*envp, e_len, "HOME");
printf("%s\en", str);
str = envz_get(*envp, e_len, "HOME");
printf("%s\en", str);
exit(EXIT_SUCCESS);
2004-11-03 13:51:07 +00:00
}
.fi
.SH "SEE ALSO"
2007-12-05 20:53:01 +00:00
.BR argz_add (3)