使用C在Linux中获取用户组的正确方法

Adi*_*GuN 6 c linux usergroups

我想知道unix命令组是否还有其他C库,

$ groups ---- lists all the group id's of the user.

有一个名为getgroups()的方法,但此方法将返回用户组。有没有一种方法可以使用C为特定用户获取组。

Asb*_*arf 5

#include "<grp.h>"
int getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups);
Run Code Online (Sandbox Code Playgroud)

  • 为了完整起见:http://man7.org/linux/man-pages/man3/getgrouplist.3.html 另请注意该错误(有关详细信息,请参阅手册页) (6认同)
  • 也许尝试放一个有用的例子而不是手册页摘录。 (2认同)