- errno = 0;
- getgrnam_r(group, &grbuf, buf, buflen, &gr);
- if (gr != NULL)
- return gr->gr_gid;
- if (errno == 0 || errno == ENOENT || errno == ESRCH)
- err(udev, "specified group '%s' unknown\n", group);
- else
- err(udev, "error resolving group '%s': %m\n", group);
- return 0;
+ newbuf = realloc(buf, buflen);
+ if (!newbuf)
+ break;
+ buf = newbuf;
+ errno = getgrnam_r(group, &grbuf, buf, buflen, &gr);
+ if (gr != NULL) {
+ gid = gr->gr_gid;
+ } else if (errno == ERANGE) {
+ buflen *= 2;
+ continue;
+ } else if (errno == 0 || errno == ENOENT || errno == ESRCH) {
+ err(udev, "specified group '%s' unknown\n", group);
+ } else {
+ err(udev, "error resolving group '%s': %m\n", group);
+ }
+ break;
+ }
+ free(buf);
+ return gid;