commit d90ced20471237c69970249b9a40a2fa4d0d1d4b
parent de221bc6f582625f395fe44e3c3e3bfdb1b71bfa
Author: Connor Lane Smith <cls@lubutu.com>
Date: Sat, 4 Jun 2011 12:20:41 +0100
consistent error check
Diffstat:
13 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/chmod.c b/chmod.c
@@ -53,7 +53,7 @@ main(int argc, char *argv[])
void
chmodr(const char *path)
{
- if(chmod(path, mode) != 0)
+ if(chmod(path, mode) == -1)
eprintf("chmod %s:", path);
if(rflag)
recurse(path, chmodr);
diff --git a/chown.c b/chown.c
@@ -37,7 +37,7 @@ main(int argc, char *argv[])
if(owner && *owner) {
errno = 0;
pw = getpwnam(owner);
- if(errno != 0)
+ if(errno == -1)
eprintf("getpwnam %s:", owner);
else if(!pw)
eprintf("getpwnam %s: no such user\n", owner);
@@ -45,7 +45,7 @@ main(int argc, char *argv[])
if(group && *group) {
errno = 0;
gr = getgrnam(group);
- if(errno != 0)
+ if(errno == -1)
eprintf("getgrnam %s:", group);
else if(!gr)
eprintf("getgrnam %s: no such group\n", group);
@@ -58,7 +58,7 @@ main(int argc, char *argv[])
void
chownpwgr(const char *path)
{
- if(chown(path, pw ? pw->pw_uid : -1, gr ? gr->gr_gid : -1) != 0)
+ if(chown(path, pw ? pw->pw_uid : -1, gr ? gr->gr_gid : -1) == -1)
eprintf("chown %s:", path);
if(rflag)
recurse(path, chownpwgr);
diff --git a/ln.c b/ln.c
@@ -34,7 +34,7 @@ main(int argc, char *argv[])
int
ln(const char *s1, const char *s2)
{
- if(fflag && remove(s2) != 0 && errno != ENOENT)
+ if(fflag && remove(s2) == -1 && errno != ENOENT)
eprintf("remove %s:", s2);
return (sflag ? symlink : link)(s1, s2);
}
diff --git a/ls.c b/ls.c
@@ -99,7 +99,7 @@ lsdir(const char *path)
cwd = agetcwd();
if(!(dp = opendir(path)))
eprintf("opendir %s:", path);
- if(chdir(path) != 0)
+ if(chdir(path) == -1)
eprintf("chdir %s:", path);
while((d = readdir(dp))) {
@@ -125,7 +125,7 @@ lsdir(const char *path)
output(&ents[i]);
free(ents[i].name);
}
- if(chdir(cwd) != 0)
+ if(chdir(cwd) == -1)
eprintf("chdir %s:", cwd);
free(ents);
free(cwd);
@@ -136,7 +136,7 @@ mkent(Entry *ent, char *path)
{
struct stat st;
- if(lstat(path, &st) != 0)
+ if(lstat(path, &st) == -1)
eprintf("lstat %s:", path);
ent->name = path;
ent->mode = st.st_mode;
diff --git a/mkdir.c b/mkdir.c
@@ -27,7 +27,7 @@ main(int argc, char *argv[])
for(; optind < argc; optind++)
if(pflag)
mkdirp(argv[optind]);
- else if(mkdir(argv[optind], S_IRWXU|S_IRWXG|S_IRWXO) != 0)
+ else if(mkdir(argv[optind], S_IRWXU|S_IRWXG|S_IRWXO) == -1)
eprintf("mkdir %s:", argv[optind]);
return EXIT_SUCCESS;
}
@@ -40,7 +40,7 @@ mkdirp(char *path)
do {
if((p = strchr(&p[1], '/')))
*p = '\0';
- if(mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO) != 0 && errno != EEXIST)
+ if(mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO) == -1 && errno != EEXIST)
eprintf("mkdir %s:", path);
if(p)
*p = '/';
diff --git a/mkfifo.c b/mkfifo.c
@@ -11,7 +11,7 @@ main(int argc, char *argv[])
while(getopt(argc, argv, "") != -1)
exit(EXIT_FAILURE);
for(; optind < argc; optind++)
- if(mkfifo(argv[optind], S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) != 0)
+ if(mkfifo(argv[optind], S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) == -1)
eprintf("mkfifo %s:", argv[optind]);
return EXIT_SUCCESS;
}
diff --git a/pwd.c b/pwd.c
@@ -33,9 +33,9 @@ getpwd(const char *cwd)
const char *pwd;
struct stat cst, pst;
- if(!(pwd = getenv("PWD")) || pwd[0] != '/' || stat(pwd, &pst) != 0)
+ if(!(pwd = getenv("PWD")) || pwd[0] != '/' || stat(pwd, &pst) == -1)
return cwd;
- if(stat(cwd, &cst) != 0)
+ if(stat(cwd, &cst) == -1)
eprintf("stat %s:", cwd);
if(pst.st_dev == cst.st_dev && pst.st_ino == cst.st_ino)
return pwd;
diff --git a/rm.c b/rm.c
@@ -36,6 +36,6 @@ rm(const char *path)
{
if(rflag)
recurse(path, rm);
- if(remove(path) != 0 && !fflag)
+ if(remove(path) == -1 && !fflag)
eprintf("remove %s:", path);
}
diff --git a/sort.c b/sort.c
@@ -44,7 +44,7 @@ main(int argc, char *argv[])
qsort(lines, nlines, sizeof *lines, (int (*)(const void *, const void *))linecmp);
for(i = 0; i < nlines; i++)
- if(!uflag || i == 0 || strcmp(lines[i], lines[i-1]) != 0)
+ if(!uflag || i == 0 || strcmp(lines[i], lines[i-1]) == -1)
fputs(lines[i], stdout);
return EXIT_SUCCESS;
}
diff --git a/touch.c b/touch.c
@@ -45,7 +45,7 @@ touch(const char *str)
struct stat st;
struct utimbuf ut;
- if(stat(str, &st) != 0) {
+ if(stat(str, &st) == -1) {
if(errno != ENOENT)
eprintf("stat %s:", str);
if(cflag)
@@ -56,6 +56,6 @@ touch(const char *str)
}
ut.actime = st.st_atime;
ut.modtime = t;
- if(utime(str, &ut) != 0)
+ if(utime(str, &ut) == -1)
eprintf("utime %s:", str);
}
diff --git a/uname.c b/uname.c
@@ -40,7 +40,7 @@ main(int argc, char *argv[])
default:
exit(EXIT_FAILURE);
}
- if(uname(&u) != 0)
+ if(uname(&u) == -1)
eprintf("uname:");
if(sflag || !(nflag || rflag || vflag || mflag))
diff --git a/util/enmasse.c b/util/enmasse.c
@@ -16,7 +16,7 @@ enmasse(int argc, char **argv, int (*fn)(const char *, const char *))
struct stat st;
if(argc == 2 && !(stat(argv[1], &st) == 0 && S_ISDIR(st.st_mode))) {
- if(fn(argv[0], argv[1]) != 0)
+ if(fn(argv[0], argv[1]) == -1)
eprintf("%s:", argv[1]);
return;
}
@@ -31,7 +31,7 @@ enmasse(int argc, char **argv, int (*fn)(const char *, const char *))
eprintf("malloc:");
for(i = 0; i < argc; i++) {
snprintf(buf, size, "%s/%s", dir, basename(argv[i]));
- if(fn(argv[i], buf) != 0)
+ if(fn(argv[i], buf) == -1)
eprintf("%s:", buf);
}
free(buf);
diff --git a/util/recurse.c b/util/recurse.c
@@ -20,14 +20,14 @@ recurse(const char *path, void (*fn)(const char *))
eprintf("opendir %s:", path);
}
cwd = agetcwd();
- if(chdir(path) != 0)
+ if(chdir(path) == -1)
eprintf("chdir %s:", path);
while((d = readdir(dp)))
if(strcmp(d->d_name, ".") && strcmp(d->d_name, ".."))
fn(d->d_name);
closedir(dp);
- if(chdir(cwd) != 0)
+ if(chdir(cwd) == -1)
eprintf("chdir %s:", cwd);
free(cwd);
}