C standard library functions getenv
and setenv
can be used to access environment variables for a process.
In Linux, there is a documented global variable environ
which holds environment variable value strings, so one could in principle use it directly and not use getenv
and setenv
.
My questions are:
Why is
environ
exposed and documented to the application programmer, where it seems unnecessary to do so?Does any software now, or is future software likely, to use
environ
directly?
environ
, becausesetenv
andgetenv
didn't exist. And there may very well be some legacy programs which still do it that way.getenv
is standard C, butenviron main(,,envp) setenv unsetenv putenv
are only POSIX and there are non-POSIX implementations of C.