Mercurial > hg > toybox
diff lib/xwrap.c @ 1130:6df194c6de88 draft
Add xgetpwnam() to lib/xwrap.c.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 28 Nov 2013 21:06:15 -0600 |
parents | c644f85444d0 |
children | faf7117c4489 |
line wrap: on
line diff
--- a/lib/xwrap.c Thu Nov 28 20:18:04 2013 -0600 +++ b/lib/xwrap.c Thu Nov 28 21:06:15 2013 -0600 @@ -402,17 +402,24 @@ struct passwd *xgetpwuid(uid_t uid) { struct passwd *pwd = getpwuid(uid); - if (!pwd) error_exit(NULL); + if (!pwd) error_exit("bad uid %ld", (long)uid); return pwd; } struct group *xgetgrgid(gid_t gid) { struct group *group = getgrgid(gid); - if (!group) error_exit(NULL); + if (!group) error_exit("bad gid %ld", (long)gid); return group; } +struct passwd *xgetpwnam(char *name) +{ + struct passwd *up = getpwnam(name); + if (!up) error_exit("bad user '%s'", name); + return up; +} + // This can return null (meaning file not found). It just won't return null // for memory allocation reasons. char *xreadlink(char *name)