Commit graph

11238 commits

Author SHA1 Message Date
Elliott Hughes
2bd4316bd6 Expose tzalloc()/localtime_rz()/mktime_z()/tzfree().
* 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
2023-06-16 08:10:47 -07:00
Treehugger Robot
5c6961ff6d Merge "Nullability check for wctype module." 2023-06-15 00:29:25 +00:00
Treehugger Robot
42e7ac10ed Merge "<iconv.h>: clarify the docs a bit more." 2023-06-14 23:16:06 +00:00
Elliott Hughes
db14a74701 Merge "<arpa/nameser.h>: don't use __INTRODUCED_IN_64 in a defined(__LP64__) block." 2023-06-14 22:39:55 +00:00
zijunzhao
f0fb41851b Nullability check for modules in /platform directory.
Bugs: b/245972273
Test: adb shell
Change-Id: Iaefd0231de760455b24fb09aada0144a84379689
2023-06-14 22:27:49 +00:00
zijunzhao
1ee9fb5002 Nullability check for wctype module.
Bugs: b/245972273
Test: adb shell
Change-Id: I0f10db338876eb93a89be35130b097ebe19d2c15
2023-06-14 21:54:35 +00:00
Elliott Hughes
bac2573c87 <iconv.h>: clarify the docs a bit more.
Bug: https://github.com/android/ndk/issues/1895
Test: N/A
Change-Id: I68542e3b4d98ec5ae0e0ed1d199c2b4b23e98f6d
2023-06-14 20:55:58 +00:00
zijunzhao
cc475cf28d Implement C23 scanf 'wf' length modifiers
wfN: Specifies that a following b, d, i, o, u, x, or X conversion specifier applies to a fastest minimum-width integer argument with a specific width where N is a positive decimal integer with no leading zeros (the argument will have been promoted according to the integer promotions, but its value shall be converted to the unpromoted type); or that a following n conversion specifier applies to a pointer to a fastest minimum-width integer type argument with a width of N bits. All fastest minimum-width integer types (7.22.1.3) defined in the header <stdint.h> shall be supported. Other supported values of N are implementation-defined.

Bug: b/271903607
Test: adb shell
Change-Id: Iaa1f6d87251144de0b763672ca93f23272880ad1
2023-06-14 17:15:58 +00:00
zijunzhao
1e28d06667 Nullability check for socket module.
Bugs: b/245972273
Test: adb shell
Change-Id: I7b6b00705ad7476fabf30727347555eeafff6eda
2023-06-13 21:15:34 +00:00
Treehugger Robot
cf2090b962 Merge "<complex.h>: stop using __INTRODUCED_IN_(32|64)." 2023-06-13 21:05:29 +00:00
Elliott Hughes
826ea44822 Merge "Remove PAGE_SIZE call sites." 2023-06-13 20:36:45 +00:00
Zijun Zhao
0594346633 Merge "Fix iconv_open(3) docs." 2023-06-13 17:20:41 +00:00
Elliott Hughes
7a5d9925b7 Fix iconv_open(3) docs.
Strictly the _doc comment_ is correct, but the names of the parameters
are the wrong way round. (Although iconv_open() follows the usual C
tradition of "destination first", iconv() itself doesn't, so these
functions are inherently confused/confusing.)

Bug: https://github.com/android/ndk/issues/1895
Test: N/A
Change-Id: Iafc9bd630ece1d3c55986b04bb9a99c477716530
2023-06-13 07:38:02 -07:00
Peter Collingbourne
bb11ee6d9c Remove PAGE_SIZE call sites.
To enable experiments with non-4KiB page sizes, introduce
an inline page_size() function that will either return the runtime
page size (if PAGE_SIZE is not 4096) or a constant 4096 (elsewhere).
This should ensure that there are no changes to the generated code on
unaffected platforms.

Test: source build/envsetup.sh
      lunch aosp_cf_arm64_16k_phone-userdebug
      m -j32 installclean
      m -j32
Test: launch_cvd \
  -kernel_path /path/to/out/android14-5.15/dist/Image \
  -initramfs_path /path/to/out/android14-5.15/dist/initramfs.img \
  -userdata_format=ext4
Bug: 277272383
Bug: 230790254
Change-Id: Ic0ed98b67f7c6b845804b90a4e16649f2fc94028
2023-06-12 10:59:39 -07:00
Elliott Hughes
8fc6fcdfab <complex.h>: stop using __INTRODUCED_IN_(32|64).
Although the existing annotations were strictly true (see
https://github.com/android/ndk/issues/1888#issuecomment-1581773348 for
the gory details), given the Play Store requirement that 32-bit code
must have a 64-bit version, it's not obviously useful to offer a
function for 32-bit before 64-bit.

Test: treehugger
Change-Id: I8ca11b874c26dfaa632690f510cb5409d95012e9
2023-06-12 10:22:12 -07:00
Zijun Zhao
71a03774d5 Merge "Nullability check for string modules." 2023-06-12 16:57:00 +00:00
Elliott Hughes
6dd4a906b8 <arpa/nameser.h>: don't use __INTRODUCED_IN_64 in a defined(__LP64__) block.
Test: treehugger
Change-Id: I1e75d1c15abd7753e2c9f1decc57346895a7c7f8
2023-06-12 08:09:56 -07:00
Elliott Hughes
197677cfd9 Merge "Remove __INTRODUCED_IN_ architecture macros." 2023-06-12 13:40:47 +00:00
Treehugger Robot
26add4eae0 Merge "Remove __RENAME_STAT64." 2023-06-10 01:20:11 +00:00
zijunzhao
6d23a08717 Nullability check for string modules.
Bugs: b/245972273
Test: adb shell
Change-Id: I13852702ae87c1ca14ec4f073b5f4b3d42926929
2023-06-10 00:08:50 +00:00
Elliott Hughes
421b0ac28c Remove __INTRODUCED_IN_ architecture macros.
No longer used.

Test: treehugger
Change-Id: I90c2565d80fb65ab9bf3100fb85c897c3ed0afc2
2023-06-09 23:34:17 +00:00
Elliott Hughes
f242ef6f98 Remove __RENAME_STAT64.
Now API level 21 is our lowest supported API level, __RENAME_STAT64 is
useless.

Test: treehugger
Change-Id: I708b2142b30dfcf6c74e1a14475da690a8c25f59
2023-06-09 15:59:23 -07:00
Treehugger Robot
31849368bb Merge "Nullability check for fcntl module." 2023-06-09 18:38:00 +00:00
Treehugger Robot
6a65763b12 Merge "Nullability check for stdlib module." 2023-06-09 18:37:32 +00:00
Elliott Hughes
87e170df01 Merge "Remove __RENAME_LDBL." 2023-06-09 13:38:40 +00:00
zijunzhao
725c96c005 Nullability check for fcntl module.
Bugs: b/245972273
Test: adb shell
Change-Id: I8a60f54dfc0d3104f848cbb78d05aa0f96cd783a
2023-06-09 00:53:12 +00:00
zijunzhao
f40b4247e8 Nullability check for stdlib module.
Bugs: b/245972273
Test: adb shell
Change-Id: I0033d720b9da633d62b0b047563004e084829388
2023-06-09 00:52:55 +00:00
zijunzhao
7890484cae Implement C23 scanf 'w' length modifiers
wN: Specifies that a following b, d, i, o, u, x, or X conversion specifier applies to an integer argument with a specific width where N is a positive decimal integer with no leading zeros (the argument will have been promoted according to the integer promotions, but its value shall be converted to the unpromoted type); or that a following n conversion specifier applies to a pointer to an integer type argument with a width of N bits. All minimum-width integer types (7.22.1.2) and exact-width integer types (7.22.1.1) defined in the header <stdint.h> shall be supported. Other supported values of N are implementation-defined.

Bug: b/271903607
Test: adb shell
Change-Id: I595fd2ac7bc40d9fb7f1935b39933a6cc068eeff
2023-06-08 21:41:26 +00:00
Elliott Hughes
81e8402db3 Merge "Implement rvv version mem* and str* for riscv64" 2023-06-08 20:17:01 +00:00
Treehugger Robot
cb5188d4c8 Merge "Nullability check for poll module." 2023-06-08 02:06:03 +00:00
zijunzhao
b40e600ba8 Nullability check for poll module.
Bugs: b/245972273
Test: adb shell
Change-Id: Ia44d82bbc0382066ec420f2e7b676f16e1f6d90b
2023-06-07 23:57:12 +00:00
zijunzhao
a8d42a44bb Nullability check for threads_inlines module.
Bugs: b/245972273
Test: adb shell
Change-Id: I4ebf0598527857fc7bfbfc6ed07342af89de57b1
2023-06-07 23:03:46 +00:00
Elliott Hughes
ab2d3e1049 Remove __RENAME_LDBL.
Discussion of this during my recent minor cleanup convinced me that we
should just remove __RENAME_LDBL. There's no obvious benefit to being
able to build something for 32-bit if you can't build the same code for
64-bit, given that most new hardware (and entire verticals such as Auto)
are 64-bit-only, and the Play Store requires any app with 32-bit code to
also ship 64-bit code.

Test: treehugger
Change-Id: I1c5503b968ca66925d7bd125bd3630c41ec1bfd0
2023-06-07 17:20:53 +00:00
Treehugger Robot
063b6bfd65 Merge "Nullability check for stdatomic module." 2023-06-07 15:34:21 +00:00
Treehugger Robot
27713a5b02 Merge "Nullability check for termios_inlines module." 2023-06-07 00:10:39 +00:00
Treehugger Robot
4e22f30960 Merge "<math.h>: more use of __RENAME_LDBL." 2023-06-07 00:10:27 +00:00
zijunzhao
d909dffcca Nullability check for stdatomic module.
Bugs: b/245972273
Test: adb shell
Change-Id: I8d20606555f88b535259a589517f4c60b65f6761
2023-06-07 00:10:26 +00:00
Treehugger Robot
79600ce16b Merge "<fenv.h>: documentation, and __INTRODUCED_IN removal." 2023-06-06 22:37:59 +00:00
Treehugger Robot
c5774b8945 Merge "Nullability check for unistd module." 2023-06-06 22:36:04 +00:00
Treehugger Robot
fa203f18cc Merge "<sched.h>: __INTRODUCED_IN_ removal." 2023-06-06 22:22:27 +00:00
zijunzhao
9e19785d76 Nullability check for termios_inlines module.
Bugs: b/245972273
Test: adb shell
Change-Id: I0284efc272ed1c3352d4a72deb0760f697b1e877
2023-06-06 21:58:45 +00:00
zijunzhao
30cf6d09d5 Nullability check for unistd module.
Bugs: b/245972273
Test: adb shell
Change-Id: I958166bcea67399638c28d424b5976be29660232
2023-06-06 20:39:07 +00:00
Elliott Hughes
9cf6036048 <fenv.h>: documentation, and __INTRODUCED_IN removal.
Now the NDK doesn't support API levels below 21, we don't actually need
the different arm32 vs x86 annotations. In general we haven't been
removing this historical information because it might be interesting to
someone, and there's no real reason to remove it, but we've had
versioner bugs recently with these more complex cases.

Test: treehugger
Change-Id: I9460109a2648b9d05d7e21e397935293d3fea8eb
2023-06-06 20:32:12 +00:00
zijunzhao
acd090d585 Nullability check for stdio module.
Bugs: b/245972273
Test: adb shell
Change-Id: I3fe777e75f68b06b944830b96d091cf9d973e0db
2023-06-06 18:43:52 +00:00
Treehugger Robot
0428fc1a9c Merge "Nullability check for thread_properties module." 2023-06-06 00:18:33 +00:00
zijunzhao
70586d6a99 Nullability check for thread_properties module.
Bugs: b/245972273
Test: adb shell
Change-Id: I8f2c640d74d73576d81453973d63568472b2676e
2023-06-05 22:07:50 +00:00
Yun Hsiang
40a82d005c Implement rvv version mem* and str* for riscv64
Add vector version mem* and str* functions and only build them when the
vector extension is enabled.
The original implementation comes from
https://github.com/sifive/sifive-libc, which we agree to contribute to
the Android Open Source Project.

Test: mma

Change-Id: I11b671a5bc571d7c783a657f272f282df7d16c29
Signed-off-by: Yun Hsiang <yun.hsiang@sifive.com>
2023-05-31 09:32:42 +08:00
Treehugger Robot
32ce2d5c82 Merge "time.h: add doc comments." 2023-05-26 20:11:05 +00:00
Elliott Hughes
e17ebfd51a <math.h>: more use of __RENAME_LDBL.
Now the NDK doesn't support API levels below 21, we don't actually need
weird x86-specific annotations. In general we haven't been removing
this historical information because it might be interesting to someone,
and there's no real reason to remove it, but we've had versioner bugs
recently with these more complex cases.

Test: treehugger
Change-Id: Ia457bb338ecf55af8e319e411ec3bf48a03f3c03
2023-05-26 13:00:51 -07:00
Elliott Hughes
db36e0829b <sched.h>: __INTRODUCED_IN_ removal.
Now the NDK doesn't support API levels below 21, we don't actually need
the different arm32 vs x86 annotations. In general we haven't been
removing this historical information because it might be interesting to
someone, and there's no real reason to remove it, but we've had
versioner bugs recently with these more complex cases.

Test: treehugger
Change-Id: Id9c9b8ecc01d232becd5dd8741509c104a8b6e19
2023-05-26 12:58:14 -07:00