changeset 1129:c644f85444d0

Move xgetpwuid() and xgetgrgid() into xwrap.c
author Rob Landley <rob@landley.net>
date Thu, 28 Nov 2013 20:18:04 -0600
parents 9eaec92e3713
children 6df194c6de88
files lib/lib.h lib/xwrap.c toys/posix/id.c
diffstat 3 files changed, 16 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/lib/lib.h	Tue Nov 26 19:35:22 2013 -0600
+++ b/lib/lib.h	Thu Nov 28 20:18:04 2013 -0600
@@ -111,6 +111,8 @@
 void xchdir(char *path);
 void xmkpath(char *path, int mode);
 void xsetuid(uid_t uid);
+struct passwd *xgetpwuid(uid_t uid);
+struct group *xgetgrgid(gid_t gid);
 char *xreadlink(char *name);
 long xparsetime(char *arg, long units, long *fraction);
 void xpidfile(char *name);
--- a/lib/xwrap.c	Tue Nov 26 19:35:22 2013 -0600
+++ b/lib/xwrap.c	Thu Nov 28 20:18:04 2013 -0600
@@ -399,6 +399,20 @@
   if (setuid(uid)) perror_exit("xsetuid");
 }
 
+struct passwd *xgetpwuid(uid_t uid)
+{
+  struct passwd *pwd = getpwuid(uid);
+  if (!pwd) error_exit(NULL);
+  return pwd;
+}
+
+struct group *xgetgrgid(gid_t gid)
+{
+  struct group *group = getgrgid(gid);
+  if (!group) error_exit(NULL);
+  return group;
+}
+
 // This can return null (meaning file not found).  It just won't return null
 // for memory allocation reasons.
 char *xreadlink(char *name)
--- a/toys/posix/id.c	Tue Nov 26 19:35:22 2013 -0600
+++ b/toys/posix/id.c	Thu Nov 28 20:18:04 2013 -0600
@@ -52,20 +52,6 @@
   printf("%s%u(%s)", header, u, s);
 }
 
-struct passwd *xgetpwuid(uid_t uid)
-{
-  struct passwd *pwd = getpwuid(uid);
-  if (!pwd) error_exit(NULL);
-  return pwd;
-}
-
-struct group *xgetgrgid(gid_t gid)
-{
-  struct group *group = getgrgid(gid);
-  if (!group) error_exit(NULL);
-  return group;
-}
-
 void do_id(char *username)
 {
   int flags, i, ngroups, cmd_groups = toys.which->name[0] == 'g';