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 is NULL) to the envz vector (*envz, *envz_len) and updates *envz and *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, or NULL if 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, or NULL if not. (and bestie, heads up: the value itself can also be NULL, namely when there's an entry for name with no '=' sign. so NULL is doing double duty here, lowkey iconic of it 😭)
  • envz_merge() β€” adds each entry in envz2 to *envz, as if with envz_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 value NULL. 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms