diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2009-08-25 21:06:35 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2009-08-25 21:09:22 +0200 |
commit | 4851d131d62936c531dc4044ce19a4c4a66ba0a1 (patch) | |
tree | ab050be1cbe6bfd4e2ad0dee2b2b435f3523ceb8 /libudev/libudev-util-private.c | |
parent | d25b7205db0b6a33f043c60c8466c848af5847df (diff) |
assign errno for getgrnam_r()/getpwnam_r()
On Mon, Aug 24, 2009 at 19:50, Lennart Poettering<lennart@poettering.net> wrote:
> One little comment here: on POSIX getrnam_r() doesn't touch
> errno. Instead it returns the error value as return value.
Diffstat (limited to 'libudev/libudev-util-private.c')
-rw-r--r-- | libudev/libudev-util-private.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/libudev/libudev-util-private.c b/libudev/libudev-util-private.c index 3641b3630f..84dee559c4 100644 --- a/libudev/libudev-util-private.c +++ b/libudev/libudev-util-private.c @@ -135,8 +135,7 @@ uid_t util_lookup_user(struct udev *udev, const char *user) if (endptr[0] == '\0') return uid; - errno = 0; - getpwnam_r(user, &pwbuf, buf, buflen, &pw); + errno = getpwnam_r(user, &pwbuf, buf, buflen, &pw); if (pw != NULL) return pw->pw_uid; if (errno == 0 || errno == ENOENT || errno == ESRCH) @@ -149,7 +148,7 @@ uid_t util_lookup_user(struct udev *udev, const char *user) gid_t util_lookup_group(struct udev *udev, const char *group) { char *endptr; - int buflen; + int buflen = sysconf(_SC_GETGR_R_SIZE_MAX); char *buf; struct group grbuf; struct group *gr; @@ -160,28 +159,23 @@ gid_t util_lookup_group(struct udev *udev, const char *group) gid = strtoul(group, &endptr, 10); if (endptr[0] == '\0') return gid; - - buflen = sysconf(_SC_GETGR_R_SIZE_MAX); - if (buflen < 0) - buflen = 1000; buf = NULL; gid = 0; for (;;) { buf = realloc(buf, buflen); if (!buf) break; - errno = 0; - getgrnam_r(group, &grbuf, buf, buflen, &gr); - if (gr != NULL) + errno = getgrnam_r(group, &grbuf, buf, buflen, &gr); + if (gr != NULL) { gid = gr->gr_gid; - else if (errno == ERANGE) { + } else if (errno == ERANGE) { buflen *= 2; continue; - } - else if (errno == 0 || errno == ENOENT || errno == ESRCH) + } else if (errno == 0 || errno == ENOENT || errno == ESRCH) { err(udev, "specified group '%s' unknown\n", group); - else + } else { err(udev, "error resolving group '%s': %m\n", group); + } break; } free(buf); |