4 ms·
Another library can call setlocale and it will impact my code? I've never, ever written locale-specific code, so this is kinda surprise.
by 0xr0kk3r 3y ago
Another library can call setlocale and it will impact my code? I've never, ever written locale-specific code, so this is kinda surprise.
- teddyh 3y agoLocale is process-wide, so yes. But they shouldn’t; libraries should not call setlocale(). If it does, you should probably report it as a bug. It’s like if a library called chdir(); there are some things which libraries should not do, and setlocale() is one of them.
- JohnFen 3y agoI would be a bit more nuanced than that. I think it's OK if libraries change process state as long as they restore it as it was before the library call returns. And as long as this behavior is clearly documented.
- teddyh 3y agoMany state changes are not as reversible as one might think. Even chdir() can be non-reversible if the mountpoint has since changed. And if the locale has not been set, and then a library sets it, AFAIK you can’t “unset” it, only set it to something else.