Just finished libenv, a generic library for handling environment variables on UNIX-like operating systems. It includes a wrapper for the missing POSIX compliant environment functions:
char *posix_getenv(const char *);
int posix_setenv(const char *, const char *, int);
int posix_unsetenv(const char *);
It is not a delegating layer (to putenv() et.al) but a reimplementation of those functions with a different interface. It uses its own memory management for environment variables, which is the reason it must always be initialized first using env_init(). This initialization copies the current environment pointed to by the char **environ parameter of main() to a library internal storage pool which can then be manipulated using the new API.
From that point, the program has two environment pools: the original one (manipulated through putenv(), ...) and the libenv pool (manipulated through env_* functions.)
The library is useful when you need the POSIX interfaces in a single project and do not rely, specifically, on the need of inheriting environment variables from one process to its child(s). These variables would still be copied from the original environment pool.
This library is used, among others, in the Python 3.10.6 port from the last bounty.
Get the source code at:
http://gitea.irixce.org/TruHobbyist/libenv-1.0.0