Commit graph

65 commits

Author SHA1 Message Date
Dan Albert
a9e914dd2f Make multibyte result constants public.
The magic numbers that C defines are obnoxious. We had partial
definitions for these internally. Add the missing one and move them to
a public header for anyone else that may want to use them.

Bug: None
Test: None
Change-Id: Ia6b8cff4310bcccb23078c52216528db668ac966
2023-08-04 19:48:35 +00:00
Elliott Hughes
655e430b28 Remove the always-true __INTRODUCED_IN() annotations.
The NDK no longer supports API levels earlier than 21.

This *doesn't* include <ctype.h> because I have a separate change
rewriting that (that's blocked on the upcoming libc++ update).

Test: treehugger
Change-Id: I53e915f27011dfc0513e0c78d8799377e183ceca
2023-06-16 12:39:33 -07:00
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
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
zijunzhao
7ce2f95e28 Nullability check for wchar module.
Bugs: b/245972273
Test: adb shell
Change-Id: I9898a1120c2364e5269633a67bf789a8bb943ba5
2023-04-20 01:41:49 +00:00
Elliott Hughes
fa7c0dbf47 Remove libandroidsupport cruft.
The next NDK to take these headers only supports API 21 and later.

Test: treehugger
Change-Id: I084ec887158ce4e40d6927df49da748671bfd127
2023-02-24 19:33:33 +00:00
Elliott Hughes
95c6cd753f Stop using the __ANDROID_API_x__ constants.
Historically we've made a few mistakes where they haven't matched the
right number. And most non-Googlers are much more familiar with the
numbers, so it seems to make sense to rely more on them. Especially in
header files, which we actually expect real people to have to read from
time to time.

Test: treehugger
Change-Id: I0d4a97454ee108de1d32f21df285315c5488d886
2019-12-20 13:26:14 -08:00
Elliott Hughes
3376c23dac Add remaining _l function stubs.
Bug: http://b/65595804
Test: ran tests
Change-Id: I3bea3af20b354d1f0d3e05fd35421a9045f29020
2018-02-13 23:14:12 -08:00
Elliott Hughes
50cda38f1d Use __RENAME for long double functions.
We can cut a lot of stuff out of the NDK's libandroid_support with this,
and reduce unnecessary relocations for all LP32 code. LP64 code should
be unaffected.

Bug: https://issuetracker.google.com/64450768
Bug: https://github.com/android-ndk/ndk/issues/507
Test: ran tests, plus manual readelf on the _test.o files
Change-Id: I3de6015921195304ea9c829ef31665cd34664066
2017-09-14 16:10:43 -07:00
Elliott Hughes
ff26a16c1d Re-submit "Name function arguments in libc headers for Studio."
This reverts commit 9af9120091 (a revert
of 079bff4fa5), now the versioner bug is
fixed.

Bug: http://b/64613623 # header bug
Bug: http://b/64802958 # versioner bug
Change-Id: I1cb9d7832d4b3aecdc57a9285e2291443e59d02d
2017-08-18 00:00:38 +00:00
Colin Cross
9af9120091 Revert "Name function arguments in libc headers for Studio."
This reverts commit 079bff4fa5.

Broke builds with SANITIZE_HOST=address with an asan failure in versioner.

Change-Id: I22b113fd5405589d1a25e5e137c450aaba1ade5f
2017-08-17 18:29:54 +00:00
Elliott Hughes
079bff4fa5 Name function arguments in libc headers for Studio.
Second batch of headers...

Bug: http://b/64613623
Test: builds
Change-Id: I8eef043dbf32afee8ff814e9d005f46aee8fa21f
2017-08-16 16:30:54 -07:00
Elliott Hughes
3f66e74b90 Remove nullability specifications.
Bug: http://b/64251432
Test: builds
Change-Id: I5b1613484783f7478d30b5e694007f77fa626659
2017-08-01 13:24:40 -07:00
Josh Gao
d2ab9ffcb6 versioner: compile with clang -include foo.h -.
At least one warning only triggers in files that are included, instead
of being passed directly. Switch to compiling with -include, and fix
the resulting warnings.

Bug: https://github.com/android-ndk/ndk/issues/474
Test: mma -j && versioner
Test: python tools/versioner/run_tests.py
Change-Id: I784698c18540c9cc30f372f279a1cec1d75721ea
2017-07-28 12:57:16 -07:00
Elliott Hughes
e2d4663b27 Move a <wchar.h> implementation detail into the implementation.
No other C library expose these, and I couldn't find any callers.

Bug: http://b/62531921
Test: builds
Change-Id: I4a3505bc0897286a4036c48066b98d16665b573a
2017-06-15 10:37:26 -07:00
Elliott Hughes
5bc78c8bcd Add and use constants for the Android API levels.
Test: bionic tests still pass
Change-Id: If1b619cfc9db1d3f5d91f14f2ace71058dca0c4a
2016-11-16 16:55:42 -08:00
Dan Albert
a3ce418ca6 Revert "Add legacy inlines for locale aware APIs."
We can't really add these to the unified headers yet since we're
still using the old headers as well, and libandroid_support needs to
work with both. These functions are already defined in
libandroid_support, so when using unified headers we'll get duplicate
definitions.

This was only going to be a temporary solution anyway. Instead we'll
just rely on libandroid_support (and eventually its rewrite) to handle
these.

This reverts commit 6576a3749b.

Test: ./tools/update_headers.py && make ndk && make native
      # Copied into working directory for unified headers NDK work.
      ndk/checkbuild.py
      ndk/run_tests.py --force-unified-headers
Bug: None

Change-Id: I5762e815e2030c89d7f2540df08dd67b6c2d10a5
2016-10-31 16:47:22 -07:00
Elliott Hughes
95fa061678 Rename __pure, __pure2, and __purefunc.
These names were pretty misleading (aka "backwards"), so switch to the
same obvious names glibc uses.

Test: build.
Change-Id: Ia98c9dbbccd0820386116562347654e84669034a
2016-09-28 12:36:38 -07:00
Josh Gao
6cd9fb080c Fix warnings (and errors) in static inline headers.
Bug: http://b/31676510
Change-Id: Idcbc544e498f7e6bbe99c2bf7dc557a5681e96c4
Test: preupload hook
2016-09-23 14:34:03 -07:00
Dan Albert
6576a3749b Add legacy inlines for locale aware APIs.
Test: make checkbuild tests
Bug: http://b/31639993
Change-Id: Ic43d690dff3c6960d7826bd0b064640a3ea0e883
2016-09-22 00:44:37 -07:00
Dan Albert
f45d76a85b Match _Nonnull between char and wchar_t funcs.
The char versions of these functions have `_Nonnull` on these
parameters. Match it in the wide char versions. strxfrm_l also has
`__restrict` on its pointer arguments, I believe we've decided that's
something that shouldn't be proliferated...

Test: make checkbuild tests
Bug: None
Change-Id: Ie533e1af92b2a7c9df657073dbc4c345abf72473
2016-09-21 02:00:18 -07:00
Elliott Hughes
0fe88858f0 Clean up <uchar.h> and <wctype.h> transitive includes.
Bug: http://b/30367366
Change-Id: I63212a34c54ca07223a15aa5be4da3bdc6aa38a8
2016-07-27 10:45:05 -07:00
Elliott Hughes
3b2096a9d6 Remove unnecessary 'extern's.
Change-Id: Iba2b3fb6ff88e504f1657b915120ae43d58a1e03
2016-07-22 18:57:12 -07:00
Elliott Hughes
f47514dd99 Remove __LIBC_ABI_PUBLIC__.
We have much better control over visibility now, so we don't need to
pollute the headers with cruft.

Bug: http://b/24767418
Change-Id: I349f4c3bc30102477375ad9f80926e560c7c1d8b
2016-07-19 13:56:46 -07:00
Elliott Hughes
3ba55f8022 Rationalize visibility.
If it's C or POSIX, it's in. If it's BSD or GNU, it's guarded by __USE_BSD
or __USE_GNU.

Bug: https://code.google.com/p/android/issues/detail?id=194631
Change-Id: Ife51a21c2b37b060db56780d29c929805b199cb6
2016-06-09 17:40:19 -07:00
Josh Gao
14adff1cfa Add versioning information to symbols.
Bug: http://b/28178111
Change-Id: I46bf95accd819f4521afb1173d8badcc5e9df31c
2016-04-29 16:39:50 -07:00
Elliott Hughes
7ba106c784 Fix <wctype.h>.
* Fix the return type of towlower_l/towupper_l.
* Implement wctrans/wctrans_l/towctrans/towctrans_l.
* Move declarations that POSIX says are available from both <wchar.h> and
  <wctype.h> to <bits/wctype.h> and include from both POSIX headers.
* Write the missing tests.

Change-Id: I3221da5f3d7e8a2fb0a7619dc724de45f7b55398
2016-04-28 18:22:06 -07:00
Josh Gao
29226f39ae Tag unavailable functions with macro.
Add an __UNAVAILABLE macro, and use it for several functions which lack
implementations, but need to have visible declarations to be reexported
in the C++ standard library.

Bug: http://b/28178111
Change-Id: Ia4ae0207bbfcb7baa61821f0ef946257b019c0db
2016-04-27 16:50:54 -07:00
Josh Gao
752a82c9ed Remove mbstowcs from <wchar.h>.
Glibc doesn't export the function here, and adding a <bits/...> header
for this function seems unnecessary.

Bug: http://b/28067717
Change-Id: I7304cc1daca14585c85d5c783365c4a43779ff2c
2016-04-07 18:01:59 -07:00
Elliott Hughes
5704c423c8 Implement POSIX lockf.
This has been requested a few times over the years. This is basically
a very late rebase of https://android-review.googlesource.com/45470
which was abandoned years ago. One addition is that this version has
_FILE_OFFSET_BITS=64 support.

POSIX puts this in <unistd.h>. glibc also has it in <fcntl.h>.

Bug: http://b/13077650
Change-Id: I5862b1dc326e326c01ad92438ecc1578d19ba739
2016-01-26 11:09:44 -08:00
Elliott Hughes
3cfb52aab2 Add GNU extensions mempcpy and wmemcpy.
Used by elfutils. On the bright side, they stopped using __mempcpy.

Bug: 18374026
Change-Id: Id29bbe6ef1c5ed5a171bb6c32182f129d8332abb
2015-02-18 22:02:56 -08:00
Christopher Ferris
5c7d9584d9 Add missing function prototypes wcpcpy/wcpncpy.
Also add smoke tests for a few of the wchar functions.

Change-Id: Id1be522f55a6708564d444941f42097548f16497
2014-11-13 18:56:12 -08:00
Elliott Hughes
b20c24456e Implement all the POSIX _l functions.
Strictly speaking, this only implements the _l variants of the functions
we actually have. We're still missing nl_langinfo_l, for example, but we
don't have nl_langinfo either.

Change-Id: Ie711c7b04e7b9100932a13f5a5d5b28847eb4c12
2014-11-06 15:52:22 -08:00
Dan Albert
3c5037f1b3 Fix incorrect parameter types for locale funcs.
strtoll(3), strtoull(3), wcstoll(3), and wcstoull(3) all take an _int_
as a base, not a size_t. This is an ABI compatibility issue.

Bug: 17628622
Change-Id: I17f8eead34ce2112005899fc30162067573023ec
2014-09-23 15:32:24 -07:00
Elliott Hughes
6b841db2ba Add POSIX-2008 fmemopen, open_memstream, and open_wmemstream.
Bug: 17164505
Change-Id: I59e28a08ff8b6ab632230b11a5807cfd5278aeb5
2014-08-20 17:03:46 -07:00
Dan Albert
dfb5ce42bc Revert "Revert "Add locale aware APIs.""
This reverts commit 063e20c269.

Change-Id: Ib8c9004efefe75a5346b3af50dfe37952d91eb21
2014-07-11 16:21:31 +00:00
Dan Albert
063e20c269 Revert "Add locale aware APIs."
Accidentally verified against a dirty tree. Needs the companion change to libc++ to land upstream before I can submit this.

This reverts commit e087eac404.

Change-Id: I317ecd0923114f415eaad7603002f77feffb5e3f
2014-07-09 22:50:43 +00:00
Dan Albert
e087eac404 Add locale aware APIs.
Since we only support the C locale, we can just forward all of these to
their non-locale equivalents for correct behavior.

Change-Id: Ib7be71b7f636309c0cc3be1096a4c1f693f04fbb
2014-07-09 15:41:53 -07:00
Elliott Hughes
d10db82619 Build tzcode with hidden visibility.
Bug: 11156955
Change-Id: Ib98d837b56cbbdfd01687cb3054fe3103eec0da9
2014-06-19 14:49:30 -07:00
Dan Albert
001f8f041b Removes wcswcs from bionic for LP64.
Bug: 13935372
Change-Id: I0deb15e769da4fa81bb65a87f3c86db5163a5796
2014-06-04 12:01:56 -07:00
Calin Juravle
b55f2631dc Change wctype_t from int to long.
On LP64 this brings us on par with the other libcs where wctype_t is 8
bytes.

Bug: 12875898
Change-Id: Ice4f538ccf0634ef6667a8d90d0f7f09cec9e1b0
2014-05-13 13:11:27 +01:00
Calin Juravle
0c472479a2 Change wctype_t from enum to int
This increases bionic source compatibility with other libcs where
"wctype_t foo = 0;" is valid without -fpermissive.

Bug: 14646243
Change-Id: Ia9bd0785bc42c7b46e2bb6c3d9b9a9d3f769d983
2014-05-13 12:47:27 +01:00
Calin Juravle
15a6310e4b Support mb sequences across calls to mb*to*wcs* functions
Bug: 13077905
Change-Id: I5abdc7cc3c27c109b7900c94b112f18a95c35763
2014-05-13 00:24:25 +01:00
Calin Juravle
d4ae59dcf2 Merge "Reserve space in mbstate to allow for proper wchar support" 2014-04-30 10:34:09 +00:00
Elliott Hughes
01ae00f317 Switch to the OpenBSD implementations of the wide scanf functions.
This also gets us the C99 wcstoimax and wcstoumax, and a working fgetwc and
ungetwc, all of which are needed in the implementation.

This also brings several other files closer to upstream.

Change-Id: I23b025a8237a6dbb9aa50d2a96765ea729a85579
2014-04-29 16:28:56 -07:00
Elliott Hughes
3d7a0d9b08 Switch to the OpenBSD wcsto* functions.
This replaces a partial set of non-functional functions with a complete
set of functions, all of which actually work.

This requires us to implement mbsnrtowcs and wcsnrtombs which completes
the set of what we need for libc++.

The mbsnrtowcs is basically a copy & paste of wcsnrtombs, but I'm going
to go straight to looking at using the OpenBSD UTF-8 implementation rather
than keep polishing our home-grown turd.

(This patch also opportunistically switches us over to upstream btowc,
mbrlen, and wctob, since they're all trivially expressed in terms of
other functions.)

Change-Id: I0f81443840de0f1aa73b96f0b51988976793a323
2014-04-29 14:53:11 -07:00
Calin Juravle
eab395e4a8 Reserve space in mbstate to allow for proper wchar support
Bug: 14382788
Change-Id: If023ac9bb65f95135cae7ebe89147e3985a69a96
2014-04-29 20:28:29 +01:00
Elliott Hughes
83c07b5e50 Fix WCHAR_MAX, WCHAR_MIN, WINT_MAX, and WINT_MIN.
GCC tells us everything we need to know. clang does its usual half-assed job.

Change-Id: Id4d664529b10345274602768cd564d3df717e931
2014-04-21 18:09:46 -07:00
Elliott Hughes
40b0579127 Add iswblank for libcxx.
We have similar degenerate implementations for all the other isw* functions,
so it's weird to exclude just one.

Change-Id: I659b97930e68598826c4882bb59f4146870fb6a0
2014-04-15 12:04:05 -07:00
Elliott Hughes
77e944fd46 Implement wctomb(3) for ltrace.
This is an implementation in the style of the rest: char == byte.

We might want to come back and implement UTF-8, but this is enough for ltrace.

Bug: 13747066
Change-Id: Ib2b63609c9014fdef9a8491e067467c4fc5ae3cc
2014-04-07 14:29:28 -07:00