如何在 Android NDK 中实现 getgrnam_r()? (仿生中不存在)

How to implement getgrnam_r() in Android NDK? (Does not exist in bionic)

如何在 Android NDK 编译期间实现此功能 getgrnam_r

int getgrnam_r(const char *name, struct group *grp,
                 char *buf, size_t buflen, struct group **result);

很好的问题,几乎 5 年前实际上已经为此创建了一个问题(请阅读此处):https://code.google.com/p/android/issues/detail?id=9242

来自Google:

Bionic doesn’t want to implement all features of a traditional C library, we only add features to it as we need them, and we try to keep things as simple and small as possible. Our goal is not to support scaling to thousands of concurrent threads on multi-processors machines; we’re running this on cellphones, damnit !!

来源:https://android.googlesource.com/platform/bionic/+/donut-release/libc/README

这里有关于 Android 的 OS 和 libc(2011 年)的更多注释:http://cgi.cs.indiana.edu/~nhusted/dokuwiki/lib/exe/fetch.php?media=wiki:android_project_documentation.pdf

您会注意到 getgrnam_rlibc 中遗漏的 500 多个函数的一部分。

综上所述,有一个名为 android-busybox 的存储库实现了非常接近的东西:

/* Search for an entry with a matching group name.  */
struct group* FAST_FUNC getgrnam(const char *__name);

来源:https://github.com/sherpya/android-busybox/blob/master/include/grp_.h#L49

经过长时间的搜索:

实施 №1:非常感谢帮助我的 BusyBox 人 (Vladimir N. Oleynik):https://gist.github.com/FreakMurderer/d0d770cdb85e5b80a552#file-g-c

实施 №2(另一个(我真的不知道什么更好 - 风险自负)):https://github.com/chombourger/android-udev/blob/c78aaf59cdc4378346eb084e9cdc02ca46bc389a/android/missing.c