1ENVZ_ADD(3) Library Functions Manual ENVZ_ADD(3)
2
3
4
6 envz_add, envz_entry, envz_get, envz_merge, envz_remove, envz_strip -
7 environment string support
8
10 #include <envz.h>
11
12 error_t
13 envz_add(char **envz, size_t *envz_len,
14 const char *name, const char *value);
15
16 char *
17 envz_entry(const char *envz, size_t *envz_len, const char *name);
18
19 char *
20 envz_get(const char *envz, size_t *envz_len, const char *name);
21
22 error_t
23 envz_merge(char **envz, size_t *envz_len,
24 const char *envz2, size_t envz2_len, int override);
25
26 void
27 envz_remove(char **envz, size_t *envz_len, const char *name);
28
29 void
30 envz_strip(char **envz, size_t *envz_len);
31
32
34 These functions are glibc-specific.
35
36 An argz vector is a pointer to a character buffer together with a
37 length, see argz_add(3). An envz vector is a special argz vector,
38 namely one where the strings have the form "name=value". Everything
39 after the first '=' is considered to be the value. If there is no '=',
40 the value is taken to be NULL. (While the value in case of a trailing
41 '=' is the empty string "".)
42
43 These functions are for handling envz vectors.
44
45 envz_add() adds the string "name=value" (in case value is non-NULL) or
46 "name" (in case value is NULL) to the envz vector (*envz,*envz_len) and
47 updates *envz and *envz_len. If an entry with the same name existed,
48 it is removed.
49
50 envz_entry() looks for name in the envz vector (envz,envz_len) and
51 returns the entry if found, or NULL if not.
52
53 envz_get() looks for name in the envz vector (envz,envz_len) and
54 returns the value if found, or NULL if not. (Note that the value can
55 also be NULL, namely when there is an entry for name without '=' sign.)
56
57 envz_merge() adds each entry in envz2 to *envz, as if with envz_add().
58 If override is true, then values in envz2 will supersede those with the
59 same name in *envz, otherwise not.
60
61 envz_remove() removes the entry for name from (*envz,*envz_len) if
62 there was one.
63
64 envz_strip() removes all entries with value NULL.
65
67 All envz functions that do memory allocation have a return type of
68 error_t, and return 0 for success, and ENOMEM if an allocation error
69 occurs.
70
72 #include <stdio.h>
73 #include <envz.h>
74 int
75 main(int argc, char *argv[], char *envp[]) {
76 int i, e_len = 0;
77 char *str;
78
79 for (i=0; envp[i] != NULL; i++)
80 e_len += strlen(envp[i]) + 1;
81
82 str = envz_entry(*envp, e_len, "HOME");
83 printf("%s\n", str);
84 str = envz_get(*envp, e_len, "HOME");
85 printf("%s\n", str);
86 return 0;
87 }
88
90 These functions are a GNU extension. Handle with care.
91
93 argz(3)
94
95
96
97 ENVZ_ADD(3)