From: Hauke Mehrtens Date: Thu, 15 Oct 2015 11:59:13 +0000 (+0200) Subject: android: c_compat: add __cmsg_nxthd() for Android KitKat 4.4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e25f986586c3e4bf25a98999810d803b4efbba1d;p=contrib%2Fiotivity.git android: c_compat: add __cmsg_nxthd() for Android KitKat 4.4 The function __cmsg_nxthd() is missing in Android 4.4, but the Android NDK header files in the version we are using are referencing it and we use it in our code, this functions was added in version 5.0. To make IoTivity dynamically loadable on Android KitKat 4.4 add this functions as a weak symbol, so it will be used if the c lib does not provide it, like on Android < 5.0 This code was taken from these two resources: https://raw.githubusercontent.com/android/platform_bionic/master/libc/bionic/__cmsg_nxthdr.cpp https://github.com/android/platform_bionic/commit/ff64831b0965c16c95c9f81a148f30a6ef3a6c64 Change-Id: I02ef763cf3f82c73b1e0169230dd8c7e9d6d379b Signed-off-by: Hauke Mehrtens Reviewed-on: https://gerrit.iotivity.org/gerrit/3895 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- diff --git a/build_common/android/compatibility/c_compat.c b/build_common/android/compatibility/c_compat.c index b76c739..1a36575 100644 --- a/build_common/android/compatibility/c_compat.c +++ b/build_common/android/compatibility/c_compat.c @@ -1,4 +1,5 @@ #include +#include /* from stdlib.h */ float strtof(const char *nptr, char **endptr) @@ -45,3 +46,25 @@ void srandom(unsigned int __s) { srand48(__s); } + +/* from __cmsg_nxthdr.cpp */ +/* + * The function __cmsg_nxthd() is missing in Android 4.4, but the Android NDK + * header files in the version we are using are referencing it and we use it in + * our code, this functions was added in version 5.0. To make IoTivity + * dynamically loadable at load time on Android KitKat 4.4 add this functions + * as a weak symbol, so it will be used if the c lib does not provide it, like + * on Android < 5.0 This code was taken from these two resources: + * https://raw.githubusercontent.com/android/platform_bionic/master/libc/bionic/__cmsg_nxthdr.cpp + * https://github.com/android/platform_bionic/commit/ff64831b0965c16c95c9f81a148f30a6ef3a6c64 + */ +struct cmsghdr* __attribute__((weak)) __cmsg_nxthdr(struct msghdr* msg, struct cmsghdr* cmsg) +{ + struct cmsghdr* ptr; + ptr = (struct cmsghdr*)(((unsigned char*) cmsg) + CMSG_ALIGN(cmsg->cmsg_len)); + size_t len = (unsigned long)((char*)(ptr+1) - (char*) msg->msg_control); + if (len > msg->msg_controllen) { + return NULL; + } + return ptr; +}