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 **restrict envz, size_t *restrict envz_len,
13                      const char *restrict name, const char *restrict value);
14
15       char *envz_entry(const char *restrict envz, size_t envz_len,
16                      const char *restrict name);
17
18       char *envz_get(const char *restrict envz, size_t envz_len,
19                      const char *restrict name);
20
21       error_t envz_merge(char **restrict envz, size_t *restrict envz_len,
22                      const char *restrict envz2, size_t envz2_len,
23                      int override);
24
25       void envz_remove(char **restrict envz, size_t *restrict envz_len,
26                      const char *restrict name);
27
28       void envz_strip(char **restrict envz, size_t *restrict envz_len);
29

DESCRIPTION

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

RETURN VALUE

64       All envz functions that do memory allocation have a return type of  er‐
65       ror_t (an integer type), and return 0 for success, and ENOMEM if an al‐
66       location error occurs.
67

ATTRIBUTES

69       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
70       tributes(7).
71
72       ┌────────────────────────────────────────────┬───────────────┬─────────┐
73Interface                                   Attribute     Value   
74       ├────────────────────────────────────────────┼───────────────┼─────────┤
75envz_add(), envz_entry(), envz_get(),       │ Thread safety │ MT-Safe │
76envz_merge(), envz_remove(), envz_strip()   │               │         │
77       └────────────────────────────────────────────┴───────────────┴─────────┘
78

CONFORMING TO

80       These functions are a GNU extension.
81

EXAMPLES

83       #include <stdio.h>
84       #include <stdlib.h>
85       #include <envz.h>
86
87       int
88       main(int argc, char *argv[], char *envp[])
89       {
90           int e_len = 0;
91           char *str;
92
93           for (int i = 0; envp[i] != NULL; i++)
94               e_len += strlen(envp[i]) + 1;
95
96           str = envz_entry(*envp, e_len, "HOME");
97           printf("%s\n", str);
98           str = envz_get(*envp, e_len, "HOME");
99           printf("%s\n", str);
100           exit(EXIT_SUCCESS);
101       }
102

SEE ALSO

104       argz_add(3)
105

COLOPHON

107       This page is part of release 5.12 of the Linux  man-pages  project.   A
108       description  of  the project, information about reporting bugs, and the
109       latest    version    of    this    page,    can     be     found     at
110       https://www.kernel.org/doc/man-pages/.
111
112
113
114                                  2021-03-22                       ENVZ_ADD(3)
Impressum