envz_add(3)
β¨ envz_add(3) β¨ β the envz girlies' manual (Library Functions Manual)
okay so bestie, buckle UP, because this is the envz_add(3) page and it's literally the whole environment-string-support squad: envz_add, envz_entry, envz_get, envz_merge, envz_remove, and envz_strip. this is a <pink>Library Functions Manual</pink> situation and you're gonna eat it up π
πΈ LIBRARY πΈ
Standard C library (libc, -lc) β yes ma'am, the classic, the icon, the one you already link against π
β¨ SYNOPSIS β¨
#include <envz.h>
error_t envz_add(char **restrict envz, size_t *restrict envz_len,
const char *restrict name, const char *restrict value);
char *envz_entry(const char *restrict envz, size_t envz_len,
const char *restrict name);
char *envz_get(const char *restrict envz, size_t envz_len,
const char *restrict name);
error_t envz_merge(char **restrict envz, size_t *restrict envz_len,
const char *restrict envz2, size_t envz2_len,
int override);
void envz_remove(char **restrict envz, size_t *restrict envz_len,
const char *restrict name);
void envz_strip(char **restrict envz, size_t *restrict envz_len);
like look at all those restrict keywords, they're giving main character energy fr fr π«Ά
π DESCRIPTION π
okay first thing first, these functions are glibc-specific. not portable, not POSIX, just glibc doing its thing. iykyk β¨
An argz vector is a pointer to a character buffer together with a length, see argz_add(3). An envz vector is basically an argz vector that went to finishing school π β specifically one where the strings have the form "name=value". Everything after the first '=' is considered to be the value. If there's no '=', the value gets taken as NULL. (but bestie, if there IS a trailing '=', the value is the empty string "" β not even kidding, those are two different things π)
These functions are for handling envz vectors. that's the whole job. that's the assignment. π
envz_add()β adds the string"name=value"(when value is non-NULL) or"name"(when value isNULL) to the envz vector(*envz, *envz_len)and updates*envzand*envz_len. And if an entry with the same name already existed? gone. removed. not invited to the function anymore πenvz_entry()β looks for name in the envz vector(envz, envz_len)and returns the entry if it's found, orNULLif it's not. simple, clean, no drama.envz_get()β looks for name in the envz vector(envz, envz_len)and returns the value if found, orNULLif not. (and bestie, heads up: the value itself can also beNULL, namely when there's an entry for name with no'='sign. soNULLis doing double duty here, lowkey iconic of it π)envz_merge()β adds each entry in envz2 to*envz, as if withenvz_add(). If override is true, then values in envz2 will supersede those with the same name in*envz, otherwise not. so override is basically the "new girl wins" button πenvz_remove()β removes the entry for name from(*envz, *envz_len)if there was one. if there wasn't one, it just kinda shrugs. π€·envz_strip()β removes all entries with valueNULL. that's it. that's the whole function. spring cleaning fr fr π§Ή
π RETURN VALUE π
All the envz functions that do memory allocation have a return type of error_t (which is an integer type, ngl), and they return 0 for success, and ENOMEM if an allocation error occurs. so if you see ENOMEM, the allocator said no and you should probably go lie down π
β ATTRIBUTES β
for an explanation of the terms used in this section, see attributes(7). the original vibes were a whole table but we're doing bullets and honestly it hits the same:
- Interface:
envz_add(),envz_entry(),envz_get(),envz_merge(),envz_remove(),envz_strip()β Attribute: Thread safety β Value:MT-Safe
so yeah, all six of them are MT-Safe. go forth and thread, bestie π§
π STANDARDS π
GNU. that's it. that's the standard. GNU said "this is ours" and honestly, slay. π
π₯ EXAMPLES π₯
here's the example, verbatim, no notes, because it's perfect:
#include <envz.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[], char *envp[])
{
char *str;
size_t e_len = 0;
for (size_t i = 0; envp[i] != NULL; i++)
e_len += strlen(envp[i]) + 1;
str = envz_entry(*envp, e_len, "HOME");
printf("%s\n", str);
str = envz_get(*envp, e_len, "HOME");
printf("%s\n", str);
exit(EXIT_SUCCESS);
}
see how it walks envp to compute e_len, then asks for "HOME" both as an entry and as a value? that's the whole double-duty NULL thing from earlier showing up in real life. obsessed. β¨
π SEE ALSO π
reminder bestie: this is glibc-only territory, so don't go shipping it to some other libc and acting surprised when it ghosts you. π
and that's the page!! this was envz_add(3) from Linux man-pages 6.20, dated 2026-02-08 β okay bye, love you, go read argz_add(3) next, mwah ππ
π¦
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: GPL-1.0-or-later
- Copyright 2002, Walter Harms <walter.harms@informatik.uni-oldenburg.de>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms