1ENVZ_ADD(3)                Linux Programmer's Manual               ENVZ_ADD(3)
2
3
4

NAME

6       envz_add,  envz_entry,  envz_get, envz_merge, envz_remove, envz_strip -
7       environment string support
8

SYNOPSIS

10       #include <envz.h>
11
12       error_t envz_add(char **envz, size_t *envz_len,
13                    const char *name, const char *value);
14
15       char *envz_entry(const char *envz, size_t *envz_len, const char *name);
16
17       char *envz_get(const char *envz, size_t *envz_len, const char *name);
18
19       error_t envz_merge(char **envz, size_t *envz_len,
20                    const char *envz2, size_t envz2_len, int override);
21
22       void envz_remove(char **envz, size_t *envz_len, const char *name);
23
24       void envz_strip(char **envz, size_t *envz_len);
25

DESCRIPTION

27       These functions are glibc-specific.
28
29       An argz vector is a pointer to  a  character  buffer  together  with  a
30       length,  see  argz_add(3).   An  envz  vector is a special argz vector,
31       namely one where the strings have the  form  "name=value".   Everything
32       after the first '=' is considered to be the value.  If there is no '=',
33       the value is taken to be NULL.  (While the value in case of a  trailing
34       '=' is the empty string "".)
35
36       These functions are for handling envz vectors.
37
38       envz_add()  adds the string "name=value" (in case value is non-NULL) or
39       "name" (in case value is NULL) to the  envz  vector  (*envz, *envz_len)
40       and  updates  *envz  and  *envz_len.   If  an  entry with the same name
41       existed, it is removed.
42
43       envz_entry() looks for name in the  envz  vector  (envz, envz_len)  and
44       returns the entry if found, or NULL if not.
45
46       envz_get()  looks  for  name  in  the  envz vector (envz, envz_len) and
47       returns the value if found, or NULL if not.  (Note that the  value  can
48       also be NULL, namely when there is an entry for name without '=' sign.)
49
50       envz_merge()  adds each entry in envz2 to *envz, as if with envz_add().
51       If override is true, then values in envz2 will supersede those with the
52       same name in *envz, otherwise not.
53
54       envz_remove()  removes  the  entry  for name from (*envz, *envz_len) if
55       there was one.
56
57       envz_strip() removes all entries with value NULL.
58

RETURN VALUE

60       All envz functions that do memory allocation  have  a  return  type  of
61       error_t,  and  return  0 for success, and ENOMEM if an allocation error
62       occurs.
63

CONFORMING TO

65       These functions are a GNU extension.  Handle with care.
66

EXAMPLE

68       #include <stdio.h>
69       #include <stdlib.h>
70       #include <envz.h>
71
72       int
73       main(int argc, char *argv[], char *envp[])
74       {
75           int i, e_len = 0;
76           char *str;
77
78           for (i = 0; envp[i] != NULL; i++)
79               e_len += strlen(envp[i]) + 1;
80
81           str = envz_entry(*envp, e_len, "HOME");
82           printf("%s\n", str);
83           str = envz_get(*envp, e_len, "HOME");
84           printf("%s\n", str);
85           exit(EXIT_SUCCESS);
86       }
87

SEE ALSO

89       argz_add(3)
90

COLOPHON

92       This page is part of release 3.25 of the Linux  man-pages  project.   A
93       description  of  the project, and information about reporting bugs, can
94       be found at http://www.kernel.org/doc/man-pages/.
95
96
97
98                                  2007-05-18                       ENVZ_ADD(3)
Impressum