5 ms·
The problem with `setenv` is that people expect one process to have one set of environment variables, which is shared across multiple languages running in that
by dgrunwald 2y ago
The problem with `setenv` is that people expect one process to have one set of environment variables, which is shared across multiple languages running in that process. This implies every language must let its environment variables be managed by a central language-independent library -- and on POSIX systems, that's libc.
So if libc refuses to provide thread-safety, that impacts not just C, but all possible languages (except for those that cannot call into C-libraries; as those don't need to bother synchronizing the environment with libc).
- PaulDavisThe1st 2y agoIt's not just that "libc refuses to provide thread-safety" ... the POSIX standard specifies that these functions are non-reentrant.
- saagarjha 2y agoA conformant implementation can make a non-reentrant function actually safe under the hood for people that call into it erroneously. Unfortunately, there is no way to do this for getenv/setenv, because of the API they expose (specifically, when environ is accessed directly).