summaryrefslogtreecommitdiff
path: root/libbb/bb_pwd.c
diff options
context:
space:
mode:
authorDenis Vlasenko2008-12-03 19:05:55 +0000
committerDenis Vlasenko2008-12-03 19:05:55 +0000
commitd7a805efafd83203e72c334089c3f88204231ac7 (patch)
treed69521a26d050432f89cf5713aa1516f655b136f /libbb/bb_pwd.c
parentac1c96f6737799d1d7f85515237df80e9da71346 (diff)
downloadbusybox-d7a805efafd83203e72c334089c3f88204231ac7.zip
busybox-d7a805efafd83203e72c334089c3f88204231ac7.tar.gz
libbb: introduce and use xgetpwnam. ~ -150 bytes.
Diffstat (limited to 'libbb/bb_pwd.c')
-rw-r--r--libbb/bb_pwd.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/libbb/bb_pwd.c b/libbb/bb_pwd.c
index 5e44edc..5dbc58d 100644
--- a/libbb/bb_pwd.c
+++ b/libbb/bb_pwd.c
@@ -15,7 +15,15 @@
* pointers to static data (getpwuid)
*/
-/* TODO: add xgetpwnam, this construct is used a lot */
+struct passwd* FAST_FUNC xgetpwnam(const char *name)
+{
+ struct passwd *pw = getpwnam(name);
+ if (!pw)
+ bb_error_msg_and_die("unknown user %s", name);
+ return pw;
+}
+
+/* xgetgrnam too? */
struct passwd* FAST_FUNC xgetpwuid(uid_t uid)
{
@@ -73,10 +81,7 @@ long FAST_FUNC xuname2uid(const char *name)
{
struct passwd *myuser;
- myuser = getpwnam(name);
- if (myuser == NULL)
- bb_error_msg_and_die("unknown user %s", name);
-
+ myuser = xgetpwnam(name);
return myuser->pw_uid;
}