aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
Diffstat (limited to 'toys')
-rw-r--r--toys/other/makedevs.c25
-rw-r--r--toys/posix/find.c4
2 files changed, 5 insertions, 24 deletions
diff --git a/toys/other/makedevs.c b/toys/other/makedevs.c
index f6e7ece9..0d20a57d 100644
--- a/toys/other/makedevs.c
+++ b/toys/other/makedevs.c
@@ -41,7 +41,7 @@ GLOBALS(
void makedevs_main()
{
- int value, fd = 0, line_no, i;
+ int fd = 0, line_no, i;
char *line = NULL;
// Open file and chdir, verbosely
@@ -78,27 +78,8 @@ void makedevs_main()
continue;
} else mode |= (mode_t[]){S_IFIFO, S_IFCHR, S_IFBLK, 0, 0}[i];
- if (*user) {
- struct passwd *usr;
-
- if (!(usr = getpwnam(user)) && isdigit(*user)) {
- sscanf(user, "%u", &value);
- usr = xgetpwuid(value);
- }
- if (!usr) error_exit("bad user '%s'", user);
- uid = usr->pw_uid;
- } else uid = getuid();
-
- if (*group) {
- struct group *grp;
-
- if (!(grp = getgrnam(group)) && isdigit(*group)) {
- sscanf (group, "%u", &value);
- grp = getgrgid(value);
- }
- if (!grp) error_exit("bad group '%s'", group);
- gid = grp->gr_gid;
- } else gid = getgid();
+ uid = *user ? xgetpwnamid(user)->pw_uid : getuid();
+ gid = *group ? xgetgrnamid(group)->gr_gid : getgid();
while (*node == '/') node++; // using relative path
diff --git a/toys/posix/find.c b/toys/posix/find.c
index 6c45a212..3607874a 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -371,8 +371,8 @@ static int do_find(struct dirtree *new)
udl = xmalloc(sizeof(*udl));
dlist_add_nomalloc(&TT.argdata, (void *)udl);
- if (*s == 'u') udl->u.uid = xgetpwnam(ss[1])->pw_uid;
- else if (*s == 'g') udl->u.gid = xgetgrnam(ss[1])->gr_gid;
+ if (*s == 'u') udl->u.uid = xgetpwnamid(ss[1])->pw_uid;
+ else if (*s == 'g') udl->u.gid = xgetgrnamid(ss[1])->gr_gid;
else {
struct stat st;