aboutsummaryrefslogtreecommitdiff
path: root/lib/xwrap.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-11-28 21:06:15 -0600
committerRob Landley <rob@landley.net>2013-11-28 21:06:15 -0600
commit5ec4ab3113dcc813b6040d7ded38e297df99dc0e (patch)
treeafad4e181b9b8ab64496ed7d001c444c245ae429 /lib/xwrap.c
parent9e44a5841f0ab9bc03cefb5631c80f3e4e5a60fe (diff)
downloadtoybox-5ec4ab3113dcc813b6040d7ded38e297df99dc0e.tar.gz
Add xgetpwnam() to lib/xwrap.c.
Diffstat (limited to 'lib/xwrap.c')
-rw-r--r--lib/xwrap.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 71ea9209..c0c8a44b 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -402,17 +402,24 @@ void xsetuid(uid_t uid)
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)