2bd4316bd6
* Rationale The question often comes up of how to use multiple time zones in C code. If you're single-threaded, you can just use setenv() to manipulate $TZ. toybox does this, for example. But that's not thread-safe in two distinct ways: firstly, getenv() is not thread-safe with respect to modifications to the environment (and between the way putenv() is specified and the existence of environ, it's not obvious how to fully fix that), and secondly the _caller_ needs to ensure that no other threads are using tzset() or any function that behaves "as if" tzset() was called (which is neither easy to determine nor easy to ensure). This isn't a bigger problem because most of the time the right answer is to stop pretending that libc is at all suitable for any i18n, and switch to icu4c instead. (The NDK icu4c headers do not include ucal_*, so this is not a realistic option for most applications.) But what if you're somewhere in between? Like the rust chrono library, for example? What then? Currently their "least worst" option is to reinvent the entire wheel and read our tzdata files. Which isn't a great solution for anyone, for obvious maintainability reasons. So it's probably time we broke the catch-22 here and joined NetBSD in offering a less broken API than standard C has for the last 40 years. Sure, any would-be caller will have to have a separate "is this Android?" and even "is this API level >= 35?" path, but that will fix itself sometime in the 2030s when developers can just assume "yes, it is", whereas if we keep putting off exposing anything, this problem never gets solved. (No-one's bothered to try to implement the std::chrono::time_zone functionality in libc++ yet, but they'll face a similar problem if/when they do.) * Implementation The good news is that tzcode already implements these functions, so there's relatively little here. I've chosen not to expose `struct state` because `struct __timezone_t` makes for clearer error messages, given that compiler diagnostics will show the underlying type name (`struct __timezone_t*`) rather than the typedef name (`timezone_t`) that's used in calling code. I've moved us over to FreeBSD's wcsftime() rather than keep the OpenBSD one building --- I've long wanted to only have one implementation here, and FreeBSD is already doing the "convert back and forth, calling the non-wide function in the middle" dance that I'd hoped to get round to doing myself someday. This should mean that our strftime() and wcsftime() behaviors can't easily diverge in future, plus macOS/iOS are mostly FreeBSD, so any bugs will likely be interoperable with the other major mobile operating system, so there's something nice for everyone there! The FreeBSD wcsftime() implementation includes a wcsftime_l() implementation, so that's one stub we can remove. The flip side of that is that it uses mbsrtowcs_l() and wcsrtombs_l() which we didn't previously have. So expose those as aliases of mbsrtowcs() and wcsrtombs(). Bug: https://github.com/chronotope/chrono/issues/499 Test: treehugger Change-Id: Iee1b9d763ead15eef3d2c33666b3403b68940c3c |
||
---|---|---|
.. | ||
arch-arm | ||
arch-arm64 | ||
arch-common/bionic | ||
arch-riscv64 | ||
arch-x86 | ||
arch-x86_64 | ||
async_safe | ||
b64/include/bionic | ||
bionic | ||
dns | ||
execinfo/include | ||
fts/include | ||
include | ||
kernel | ||
malloc_debug | ||
malloc_hooks | ||
platform | ||
private | ||
seccomp | ||
stdio | ||
system_properties | ||
tools | ||
tzcode | ||
upstream-freebsd | ||
upstream-netbsd | ||
upstream-openbsd | ||
versioner-dependencies | ||
Android.bp | ||
BUILD | ||
fs_config_generator.py | ||
libc.map.txt | ||
libstdc++.map.txt | ||
MODULE_LICENSE_BSD | ||
NOTICE | ||
SECCOMP_ALLOWLIST_APP.TXT | ||
SECCOMP_ALLOWLIST_COMMON.TXT | ||
SECCOMP_ALLOWLIST_SYSTEM.TXT | ||
SECCOMP_BLOCKLIST_APP.TXT | ||
SECCOMP_BLOCKLIST_COMMON.TXT | ||
SECCOMP_PRIORITY.TXT | ||
SYSCALLS.TXT | ||
version_script.txt |