-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unified headers: strerror_r not available #324
Comments
Thanks! However, do I understand correctly that the function is only actually there in Android 23+? There's been a call to it in my code for some time in an app built to be compatible with Android 9+, but perhaps it never actually got called - or it would have crashed? |
The GNU version of it, yes. There are actually two You'll get the POSIX one if you are targeting pre-23 or if you don't have This restores the old, pre-unified headers behavior, so your app should keep building as it always has once r14b ships. |
Oh, okay. Thanks for the detailed explanation! |
(Note that if you're only targeting android K or later, you probably don't actually need to use strerror_r. We use a thread local buffer for strerror starting in K) |
Well, I still keep compatibility with Gingerbread, mostly just because, but also since my app is an excellent fit for the Xperia Play. But, @jmgao, to me that feels like a move in the wrong direction. Ugly global-state APIs like strerror or strtok should simply be replaced with properly designed threadsafe APIs where the user manages the buffer, IMHO. Inserting thread local buffers behind the users back will only serve to perpetuate these terrible APIs. Though maybe there are pragmatic reasons I'm not thinking of. Anyway, rant over :) |
Change is merged. |
in general, one advantage TLS has over the _r alternative is that you don't need to know how big a buffer you'll need. if you don't need a copy, no copy is made. if you do, you can size the buffer correctly before copying rather than potentially have to try multiple times or over-allocate. this is particularly problematic with readdir_r which basically should never be used. (see http://elliotth.blogspot.com/2012/10/how-not-to-use-readdirr3.html for much more on this, including examples of how even the man page screwed up trying to use it.) |
Well, readdir_r is particularly poorly designed, and readdir has the advantage that there's a DIR* object to stash the pointer to an allocated string in. strerror doesn't have anything like the DIR* and needs a global thread-local pointer, further bloating the TLS libc state. But I'll concede that if your metric is bugs in user code overall, which is pretty sensible, "non-r" variants have an advantage. |
We had several bugs filed saying "if I set _FILE_OFFSET_BITS=64 when targeting an API < L, various functions are missing". Instead of saying "yes, they are", we quietly just modified the header files to expose the non-64-bit variants. This makes no sense. We can't just say "oh, yeah, we don't have a version of this function that agrees with your calling code about how large off_t is, but here's a version that doesn't: I'm sure it'll be fine". _FILE_OFFSET_BITS=64 on Android LP32 has always been a game of chance, but that game should be "are all the functions my code needs available at compile time?", not "will my code actually work at run time?". Bug: android/ndk#449 Bug: android/ndk#442 Bug: android/ndk#333 Bug: android/ndk#332 Bug: android/ndk#324 Test: builds Change-Id: Ib095251d3e21e77ed50cc3575388107fecec4ecd
This is a partial https://android-review.googlesource.com/c/343952/. We shipped this in r14, but r15 beta 1 is shipping the O oreview headers, which is older than this change. Test: ./validate.py Bug: android/ndk#324 Change-Id: Ib301aba158f014d4fe2bf49aa7f2c1044c582f31 (cherry picked from commit 4e12436cc5af230b083e07ef3bea1d8ef1af1cf0)
We had several bugs filed saying "if I set _FILE_OFFSET_BITS=64 when targeting an API < L, various functions are missing". Instead of saying "yes, they are", we quietly just modified the header files to expose the non-64-bit variants. This makes no sense. We can't just say "oh, yeah, we don't have a version of this function that agrees with your calling code about how large off_t is, but here's a version that doesn't: I'm sure it'll be fine". _FILE_OFFSET_BITS=64 on Android LP32 has always been a game of chance, but that game should be "are all the functions my code needs available at compile time?", not "will my code actually work at run time?". Bug: android/ndk#442 Bug: android/ndk#333 Bug: android/ndk#332 Bug: android/ndk#324 Test: builds Change-Id: Ib095251d3e21e77ed50cc3575388107fecec4ecd
Description
Even though I include <string.h>, with unified headers, strerror_r is not available.
Environment Details
The text was updated successfully, but these errors were encountered: