Only check errno if getpw*() fails

This commit is contained in:
sin 2014-07-09 14:48:59 +01:00
parent 7872986dd2
commit 8e8d8ff242

View File

@ -47,19 +47,23 @@ main(int argc, char *argv[])
if(owner && *owner) { if(owner && *owner) {
errno = 0; errno = 0;
pw = getpwnam(owner); pw = getpwnam(owner);
if (!pw) {
if(errno != 0) if(errno != 0)
eprintf("getpwnam %s:", owner); eprintf("getpwnam %s:", owner);
else if(!pw) else
eprintf("getpwnam %s: no such user\n", owner); eprintf("getpwnam %s: no such user\n", owner);
} }
}
if(group && *group) { if(group && *group) {
errno = 0; errno = 0;
gr = getgrnam(group); gr = getgrnam(group);
if (!gr) {
if(errno != 0) if(errno != 0)
eprintf("getgrnam %s:", group); eprintf("getgrnam %s:", group);
else if(!gr) else
eprintf("getgrnam %s: no such group\n", group); eprintf("getgrnam %s: no such group\n", group);
} }
}
for(; argc > 0; argc--, argv++) for(; argc > 0; argc--, argv++)
chownpwgr(argv[0]); chownpwgr(argv[0]);