1 .\" Copyright 2002 walter harms (walter.harms@informatik.uni-oldenburg.de)
3 .\" SPDX-License-Identifier: GPL-1.0-or-later
5 .\" based on the description in glibc source and infopages
7 .\" Corrections and additions, aeb
8 .TH ENVZ_ADD 3 2021-03-22 GNU "Linux Programmer's Manual"
10 envz_add, envz_entry, envz_get, envz_merge,
11 envz_remove, envz_strip \- environment string support
14 .RI ( libc ", " \-lc )
19 .BI "error_t envz_add(char **restrict " envz ", size_t *restrict " envz_len ,
20 .BI " const char *restrict " name \
21 ", const char *restrict " value );
23 .BI "char *envz_entry(const char *restrict " envz ", size_t " envz_len ,
24 .BI " const char *restrict " name );
26 .BI "char *envz_get(const char *restrict " envz ", size_t " envz_len ,
27 .BI " const char *restrict " name );
29 .BI "error_t envz_merge(char **restrict " envz ", size_t *restrict " envz_len ,
30 .BI " const char *restrict " envz2 ", size_t " envz2_len ,
31 .BI " int " override );
33 .BI "void envz_remove(char **restrict " envz ", size_t *restrict " envz_len ,
34 .BI " const char *restrict " name );
36 .BI "void envz_strip(char **restrict " envz ", size_t *restrict " envz_len );
39 These functions are glibc-specific.
41 An argz vector is a pointer to a character buffer together with a length,
44 An envz vector is a special argz vector, namely one where the strings
45 have the form "name=value".
46 Everything after the first \(aq=\(aq is considered
48 If there is no \(aq=\(aq, the value is taken to be NULL.
49 (While the value in case of a trailing \(aq=\(aq is the empty string "".)
51 These functions are for handling envz vectors.
55 .RI \&" name = value \&"
62 is NULL) to the envz vector
63 .RI ( *envz ,\ *envz_len )
68 If an entry with the same
70 existed, it is removed.
76 .RI ( envz ,\ envz_len )
77 and returns the entry if found, or NULL if not.
83 .RI ( envz ,\ envz_len )
84 and returns the value if found, or NULL if not.
85 (Note that the value can also be NULL, namely when there is
88 without \(aq=\(aq sign.)
99 is true, then values in
101 will supersede those with the same name in
106 removes the entry for
109 .RI ( *envz ,\ *envz_len )
113 removes all entries with value NULL.
115 All envz functions that do memory allocation have a return type of
118 and return 0 for success, and
120 if an allocation error occurs.
122 For an explanation of the terms used in this section, see
130 Interface Attribute Value
138 T} Thread safety MT-Safe
144 These functions are a GNU extension.
152 main(int argc, char *argv[], char *envp[])
157 for (int i = 0; envp[i] != NULL; i++)
158 e_len += strlen(envp[i]) + 1;
160 str = envz_entry(*envp, e_len, "HOME");
161 printf("%s\en", str);
162 str = envz_get(*envp, e_len, "HOME");
163 printf("%s\en", str);