1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <string.h> #include <grp.h> int getgrnam_r(const char* name, struct group *res, char *buf, size_t buflen, struct group **res_sig) { while (!getgrent_r(res,buf,buflen,res_sig)) if (!strcmp(name,res->gr_name)) goto ok; *res_sig=0; ok: endgrent(); return *res_sig?0:-1; }