Only check errno if getpw*() fails

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

20
chown.c
View File

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