Android SDK没有SUN_LEN宏

时间:2012-09-27 17:58:14

标签: android android-ndk

今天我遇到了麻烦 - android的ndk没有SUN_LEN宏(sys / un.h || linux / un.h),我不想修补android的头文件,有什么更好的办法?

2 个答案:

答案 0 :(得分:4)

不要修补标题,在自己的文件中定义它。

#ifndef SUN_LEN //In case they fix it down the road
#define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) + strlen((ptr)->sun_path))
#endif

答案 1 :(得分:0)

SUN_LEN宏是非便携式(也不是POSIX标准的一部分)扩展 使用sizeof(struct sockaddr_un)代替是完全安全的。