12

I'm about to port a large C++ project (some sort of Library Project, it contains absolutely no GUI) to Android. It's actually a Visual C++ project, but it will be ported to Linux as intermediate step. I know that Android is not a "full" Linux and does not claim to provide all POSIX functions, but I also know there are a lot of "POSIXish functions" on Android by using the NDK.

Now my actual question is:

Which are the biggest/most important functions that are NOT available on Android compared with the full POSIX set? So that I can keep that in mind when doing the porting from Visual C++ to Linux GCC.

I tried to find something on Google, but found nothing really helpful, just here and there some stuff that mentioned that there are some POSIX functions on Android...

Marc.2377
  • 7,807
  • 7
  • 51
  • 95
nurgan
  • 309
  • 1
  • 4
  • 22
  • 2
    perhaps this can help you - http://mobilepearls.com/labs/native-android-api/ and here some more insight -http://stackoverflow.com/questions/10235403/porting-embedded-visual-c-code-to-android and here https://groups.google.com/forum/?fromgroups=#!topic/android-ndk/xZES51OYakY – Sergey Benner Aug 29 '12 at 09:52
  • 1
    http://stackoverflow.com/questions/4610086/pthread-cancel-alternatives-in-android-ndk – Crossle Song Dec 13 '13 at 03:03

4 Answers4

4

Bionic a recode by Google. It is small but optimized for Android.

The only big thing I know of that it lacks is indeed the pthread_cancel() function.

My experience is that if you port it successfully to GNU/Linux, without pthread_cancel() calls, then you should be mostly ok.

BTW, what kind of library are you trying to build? What does it uses? Network, threads...

PS: Even Linux is not fully POSIX.

shkschneider
  • 17,833
  • 13
  • 59
  • 112
4

Bionic Wikipedia page

https://en.wikipedia.org/wiki/Bionic_(software)#Differences_from_POSIX

Also has some interesting info:

Although bionic aims to implement all of C11 and POSIX, there are still (as of Oreo) about 70 POSIX functions missing[8] from libc. There are also POSIX functions such as the endpwent/getpwent/setpwent family that are inapplicable to Android because it lacks a passwd database. As of Oreo, libm is complete.

Some functions deliberately do not conform to the POSIX or C standards for security reasons, such as printf which does not support the %n format string.[9]

Official Bionic in tree documentation quote

https://android.googlesource.com/platform/bionic/+/37ad9597839c70a7ec79578e5072df9c189fc830/docs/status.md

Run ./libc/tools/check-symbols-glibc.py in bionic/ for the current list of POSIX functions implemented by glibc but not by bionic. Currently (2017-10):

aio_cancel
aio_error
aio_fsync
aio_read
aio_return
aio_suspend
aio_write
lio_listio
pthread_cancel
pthread_mutex_consistent
pthread_mutex_getprioceiling
pthread_mutex_setprioceiling
pthread_mutexattr_getprioceiling
pthread_mutexattr_getprotocol
pthread_mutexattr_getrobust
pthread_mutexattr_setprioceiling
pthread_mutexattr_setprotocol
pthread_mutexattr_setrobust
pthread_setcancelstate
pthread_setcanceltype
pthread_testcancel
wordexp
wordfree
libm

Current libm symbols: https://android.googlesource.com/platform/bionic/+/master/libm/libm.map.txt

0 remaining missing POSIX libm functions.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
2

The most obvious feature missing is pthread_cancel().

This blog has some additional details: http://codingrelic.geekhold.com/2008/11/six-million-dollar-libc.html

Good overview of Bionic: https://android-platform.googlegroups.com/attach/0f8eba5ecb95c6f4/OVERVIEW.TXT?gda=HWJaO0UAAAB1RXoVyyH5sRXFfLYnAq48KOFqr-45JqvtfiaR6gxIj4Qe8cBqW3BaWdSUPWi_jHqO3f1cykW9hbJ1ju6H3kglGu1iLHeqhw4ZZRj3RjJ_-A&view=1&part=4

Frohnzie
  • 3,559
  • 1
  • 21
  • 24
2

shared memory is also something you might find differently implemented in android. was hit hard while trying to work with shm_open and shm_unlink on android kernel. Android implements asynchronous shared memory (ashmem).

suppie
  • 1,087
  • 8
  • 10
  • Yes, one has to call ashmem_create_region and share returned file descriptor between processes via binder to mmap it. – olegst Mar 20 '15 at 11:27