1envz_add(3)                Library Functions 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

LIBRARY

10       Standard C library (libc, -lc)
11

SYNOPSIS

13       #include <envz.h>
14
15       error_t envz_add(char **restrict envz, size_t *restrict envz_len,
16                      const char *restrict name, const char *restrict value);
17
18       char *envz_entry(const char *restrict envz, size_t envz_len,
19                      const char *restrict name);
20
21       char *envz_get(const char *restrict envz, size_t envz_len,
22                      const char *restrict name);
23
24       error_t envz_merge(char **restrict envz, size_t *restrict envz_len,
25                      const char *restrict envz2, size_t envz2_len,
26                      int override);
27
28       void envz_remove(char **restrict envz, size_t *restrict envz_len,
29                      const char *restrict name);
30
31       void envz_strip(char **restrict envz, size_t *restrict envz_len);
32

DESCRIPTION

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)
47       and  updates  *envz  and *envz_len.  If an entry with the same name ex‐
48       isted, it is removed.
49
50       envz_entry() looks for name in the envz vector (envz, envz_len) and re‐
51       turns the entry if found, or NULL if not.
52
53       envz_get()  looks  for name in the envz vector (envz, envz_len) and re‐
54       turns 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

RETURN VALUE

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

ATTRIBUTES

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

STANDARDS

83       GNU.
84

EXAMPLES

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

SEE ALSO

107       argz_add(3)
108
109
110
111Linux man-pages 6.04              2023-03-30                       envz_add(3)
Impressum