# HG changeset patch # User Rob Landley # Date 1385691484 21600 # Node ID c644f85444d0edcdd78eb347e62da1428b5550dc # Parent 9eaec92e3713407030d7972a39056af9e205a2e2 Move xgetpwuid() and xgetgrgid() into xwrap.c diff -r 9eaec92e3713 -r c644f85444d0 lib/lib.h --- 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); diff -r 9eaec92e3713 -r c644f85444d0 lib/xwrap.c --- 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) diff -r 9eaec92e3713 -r c644f85444d0 toys/posix/id.c --- 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';