[hackers] [sbase] Use < 0 instead of == -1 || FRIGN

From: <git_AT_suckless.org>
Date: Wed, 19 Nov 2014 21:09:33 +0100

commit 1436518f9dad063bbfb8dc5595b9c744d025557c
Author: FRIGN <dev_AT_frign.de>
Date: Wed Nov 19 20:59:37 2014 +0100

    Use < 0 instead of == -1

diff --git a/chgrp.c b/chgrp.c
index 0a3c38d..b052bba 100644
--- a/chgrp.c
+++ b/chgrp.c
_AT_@ -24,7 +24,7 @@ usage(void)
 static void
 chgrp(const char *path)
 {
- if (chown(path, st.st_uid, gid) == -1) {
+ if (chown(path, st.st_uid, gid) < 0) {
                 weprintf("chown %s:", path);
                 failures++;
         }
_AT_@ -57,7 +57,7 @@ main(int argc, char *argv[])
         gid = gr->gr_gid;
 
         while (*++argv) {
- if (stat(*argv, &st) == -1) {
+ if (stat(*argv, &st) < 0) {
                         weprintf("stat %s:", *argv);
                         failures++;
                         continue;
diff --git a/chmod.c b/chmod.c
index 4b2bc32..9f3ab9e 100644
--- a/chmod.c
+++ b/chmod.c
_AT_@ -65,14 +65,14 @@ chmodr(const char *path)
         struct stat st;
         mode_t m;
 
- if (stat(path, &st) == -1) {
+ if (stat(path, &st) < 0) {
                 weprintf("stat %s:", path);
                 ret = 1;
                 return;
         }
 
         m = parsemode(modestr, st.st_mode, mask);
- if (chmod(path, m) == -1) {
+ if (chmod(path, m) < 0) {
                 weprintf("chmod %s:", path);
                 ret = 1;
         }
diff --git a/chown.c b/chown.c
index 066bd63..5b6178b 100644
--- a/chown.c
+++ b/chown.c
_AT_@ -81,7 +81,7 @@ main(int argc, char *argv[])
 void
 chownpwgr(const char *path)
 {
- if (chown(path, uid, gid) == -1) {
+ if (chown(path, uid, gid) < 0) {
                 weprintf("chown %s:", path);
                 ret = 1;
         }
diff --git a/chroot.c b/chroot.c
index db42616..f62af90 100644
--- a/chroot.c
+++ b/chroot.c
_AT_@ -28,10 +28,10 @@ main(int argc, char *argv[])
         if ((aux = getenv("SHELL")))
                 shell[0] = aux;
 
- if (chroot(argv[0]) == -1)
+ if (chroot(argv[0]) < 0)
                 eprintf("chroot %s:", argv[0]);
 
- if (chdir("/") == -1)
+ if (chdir("/") < 0)
                 eprintf("chdir:");
 
         if (argc == 1) {
diff --git a/libutil/apathmax.c b/libutil/apathmax.c
index c570329..d2412b8 100644
--- a/libutil/apathmax.c
+++ b/libutil/apathmax.c
_AT_@ -11,7 +11,7 @@ apathmax(char **p, long *size)
 {
         errno = 0;
 
- if ((*size = pathconf("/", _PC_PATH_MAX)) == -1) {
+ if ((*size = pathconf("/", _PC_PATH_MAX)) < 0) {
                 if (errno == 0) {
                         *size = BUFSIZ;
                 } else {
diff --git a/libutil/cp.c b/libutil/cp.c
index 3d89233..f274475 100644
--- a/libutil/cp.c
+++ b/libutil/cp.c
_AT_@ -66,7 +66,7 @@ cp(const char *s1, const char *s2)
                 if (!(dp = opendir(s1)))
                         eprintf("opendir %s:", s1);
 
- if (mkdir(s2, st.st_mode) == -1 && errno != EEXIST)
+ if (mkdir(s2, st.st_mode) < 0 && errno != EEXIST)
                         eprintf("mkdir %s:", s2);
 
                 apathmax(&ns1, &size1);
_AT_@ -144,7 +144,7 @@ preserve:
                         r = lchown(s2, st.st_uid, st.st_gid);
                 else
                         r = chown(s2, st.st_uid, st.st_gid);
- if (r == -1) {
+ if (r < 0) {
                         weprintf("cp: can't preserve ownership of '%s':", s2);
                         cp_status = 1;
                 }
diff --git a/libutil/fnck.c b/libutil/fnck.c
index 8053267..3085ab7 100644
--- a/libutil/fnck.c
+++ b/libutil/fnck.c
_AT_@ -8,13 +8,13 @@ fnck(const char *a, const char *b, int (*fn)(const char *, const char *))
 {
         struct stat sta, stb;
 
- if (stat(a, &sta) == 0
- && stat(b, &stb) == 0
- && sta.st_dev == stb.st_dev
- && sta.st_ino == stb.st_ino) {
+ if (!stat(a, &sta)
+ && !stat(b, &stb)
+ && sta.st_dev == stb.st_dev
+ && sta.st_ino == stb.st_ino) {
                 eprintf("%s -> %s: same file\n", a, b);
         }
 
- if (fn(a, b) == -1)
+ if (fn(a, b) < 0)
                 eprintf("%s -> %s:", a, b);
 }
diff --git a/libutil/recurse.c b/libutil/recurse.c
index 318987d..f9044e9 100644
--- a/libutil/recurse.c
+++ b/libutil/recurse.c
_AT_@ -18,7 +18,7 @@ recurse(const char *path, void (*fn)(const char *))
         struct stat st;
         DIR *dp;
 
- if (lstat(path, &st) == -1 || S_ISDIR(st.st_mode) == 0)
+ if (lstat(path, &st) < 0 || !S_ISDIR(st.st_mode))
                 return;
 
         if (!(dp = opendir(path)))
diff --git a/libutil/rm.c b/libutil/rm.c
index a89b11c..7261b6f 100644
--- a/libutil/rm.c
+++ b/libutil/rm.c
_AT_@ -12,6 +12,6 @@ rm(const char *path)
 {
         if (rm_rflag)
                 recurse(path, rm);
- if (remove(path) == -1 && !rm_fflag)
+ if (remove(path) < 0 && !rm_fflag)
                 eprintf("remove %s:", path);
 }
diff --git a/ls.c b/ls.c
index 97af5f9..b48391b 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -137,7 +137,7 @@ lsdir(const char *path)
         cwd = agetcwd();
         if (!(dp = opendir(path)))
                 eprintf("opendir %s:", path);
- if (chdir(path) == -1)
+ if (chdir(path) < 0)
                 eprintf("chdir %s:", path);
 
         if (many) {
_AT_@ -168,7 +168,7 @@ lsdir(const char *path)
                         free(ents[rflag ? n-i-1 : i].name);
                 }
         }
- if (chdir(cwd) == -1)
+ if (chdir(cwd) < 0)
                 eprintf("chdir %s:", cwd);
         free(ents);
         free(cwd);
_AT_@ -182,7 +182,7 @@ mkent(Entry *ent, char *path, int dostat)
         ent->name = path;
         if (!dostat)
                 return;
- if (lstat(path, &st) == -1)
+ if (lstat(path, &st) < 0)
                 eprintf("lstat %s:", path);
         ent->mode = st.st_mode;
         ent->nlink = st.st_nlink;
_AT_@ -291,7 +291,7 @@ output(Entry *ent)
                 printf("%10lu ", (unsigned long)ent->size);
         printf("%s %s%s", buf, ent->name, indicator(ent->mode));
         if (S_ISLNK(ent->mode)) {
- if ((len = readlink(ent->name, buf, sizeof buf)) == -1)
+ if ((len = readlink(ent->name, buf, sizeof buf)) < 0)
                         eprintf("readlink %s:", ent->name);
                 buf[len] = '\0';
                 mkent(&entlnk, buf, Fflag);
diff --git a/mkdir.c b/mkdir.c
index ef31462..536180c 100644
--- a/mkdir.c
+++ b/mkdir.c
_AT_@ -41,7 +41,7 @@ main(int argc, char *argv[])
         for (; argc > 0; argc--, argv++) {
                 if (pflag) {
                         mkdirp(argv[0]);
- } else if (mkdir(argv[0], S_IRWXU|S_IRWXG|S_IRWXO) == -1) {
+ } else if (mkdir(argv[0], S_IRWXU|S_IRWXG|S_IRWXO) < 0) {
                         eprintf("mkdir %s:", argv[0]);
                 }
                 if (mflag)
_AT_@ -60,7 +60,7 @@ mkdirp(char *path)
         do {
                 if (*p && (p = strchr(&p[1], '/')))
                         *p = '\0';
- if (mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO) == -1 && errno != EEXIST)
+ if (mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO) < 0 && errno != EEXIST)
                         eprintf("mkdir %s:", path);
                 if (p)
                         *p = '/';
diff --git a/mkfifo.c b/mkfifo.c
index 30f61a5..8c78441 100644
--- a/mkfifo.c
+++ b/mkfifo.c
_AT_@ -30,7 +30,7 @@ main(int argc, char *argv[])
                 usage();
 
         for (; argc > 0; argc--, argv++)
- if (mkfifo(argv[0], mode) == -1)
+ if (mkfifo(argv[0], mode) < 0)
                         eprintf("mkfifo %s:", argv[0]);
         return 0;
 }
diff --git a/nohup.c b/nohup.c
index 967ad38..48b30a4 100644
--- a/nohup.c
+++ b/nohup.c
_AT_@ -34,15 +34,15 @@ main(int argc, char *argv[])
 
         if (isatty(STDOUT_FILENO)) {
                 if ((fd = open("nohup.out", O_APPEND|O_CREAT,
- S_IRUSR|S_IWUSR)) == -1) {
+ S_IRUSR|S_IWUSR)) < 0) {
                         enprintf(Error, "open nohup.out:");
                 }
- if (dup2(fd, STDOUT_FILENO) == -1)
+ if (dup2(fd, STDOUT_FILENO) < 0)
                         enprintf(Error, "dup2:");
                 close(fd);
         }
         if (isatty(STDERR_FILENO))
- if (dup2(STDOUT_FILENO, STDERR_FILENO) == -1)
+ if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0)
                         enprintf(Error, "dup2:");
 
         execvp(argv[0], &argv[0]);
diff --git a/pwd.c b/pwd.c
index 16b541c..18f0eac 100644
--- a/pwd.c
+++ b/pwd.c
_AT_@ -41,9 +41,9 @@ getpwd(const char *cwd)
         const char *pwd;
         struct stat cst, pst;
 
- if (!(pwd = getenv("PWD")) || pwd[0] != '/' || stat(pwd, &pst) == -1)
+ if (!(pwd = getenv("PWD")) || pwd[0] != '/' || stat(pwd, &pst) < 0)
                 return cwd;
- if (stat(cwd, &cst) == -1)
+ if (stat(cwd, &cst) < 0)
                 eprintf("stat %s:", cwd);
         if (pst.st_dev == cst.st_dev && pst.st_ino == cst.st_ino)
                 return pwd;
diff --git a/renice.c b/renice.c
index 5d7e10e..1d301c6 100644
--- a/renice.c
+++ b/renice.c
_AT_@ -105,7 +105,7 @@ renice(int which, int who, long adj)
         }
 
         adj = MAX(PRIO_MIN, MIN(adj, PRIO_MAX));
- if (setpriority(which, who, (int)adj) == -1) {
+ if (setpriority(which, who, (int)adj) < 0) {
                 weprintf("setpriority %d:", who);
                 return 0;
         }
diff --git a/rmdir.c b/rmdir.c
index b58f22c..4338c0b 100644
--- a/rmdir.c
+++ b/rmdir.c
_AT_@ -23,7 +23,7 @@ main(int argc, char *argv[])
                 usage();
 
         for (; argc > 0; argc--, argv++)
- if (rmdir(argv[0]) == -1)
+ if (rmdir(argv[0]) < 0)
                         weprintf("rmdir %s:", argv[0]);
         return 0;
 }
diff --git a/sort.c b/sort.c
index ebe0d82..2a89870 100644
--- a/sort.c
+++ b/sort.c
_AT_@ -208,7 +208,7 @@ parse_keydef(struct keydef *kd, char *s, int flags)
                 kd->start_char = strtol(rest+1, &rest, 10);
         if (kd->start_char < 1)
                 return -1;
- if (parse_flags(&rest, &kd->flags, MOD_STARTB) == -1)
+ if (parse_flags(&rest, &kd->flags, MOD_STARTB) < 0)
                 return -1;
         if (*rest == ',') {
                 kd->end_column = strtol(rest+1, &rest, 10);
_AT_@ -219,7 +219,7 @@ parse_keydef(struct keydef *kd, char *s, int flags)
                         if (kd->end_char < 1)
                                 return -1;
                 }
- if (parse_flags(&rest, &kd->flags, MOD_ENDB) == -1)
+ if (parse_flags(&rest, &kd->flags, MOD_ENDB) < 0)
                         return -1;
         }
         if (*rest != '\0')
diff --git a/split.c b/split.c
index 6bced97..1ad7384 100644
--- a/split.c
+++ b/split.c
_AT_@ -131,7 +131,7 @@ nextfile(FILE *f, char *buf, int plen, int slen)
         if (f)
                 fclose(f);
         s = itostr(buf+plen, n++, slen);
- if (s == -1)
+ if (s < 0)
                 return NULL;
 
         f = fopen(buf, "w");
diff --git a/touch.c b/touch.c
index 90fa7db..5a3bd8d 100644
--- a/touch.c
+++ b/touch.c
_AT_@ -55,7 +55,7 @@ touch(const char *str)
         if (stat(str, &st) == 0) {
                 ut.actime = st.st_atime;
                 ut.modtime = t;
- if (utime(str, &ut) == -1)
+ if (utime(str, &ut) < 0)
                         eprintf("utime %s:", str);
                 return;
         }
_AT_@ -64,7 +64,7 @@ touch(const char *str)
         else if (cflag)
                 return;
         if ((fd = open(str, O_CREAT|O_EXCL,
- S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) == -1)
+ S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0)
                 eprintf("open %s:", str);
         close(fd);
         touch(str);
diff --git a/unlink.c b/unlink.c
index 12e88ad..777ec54 100644
--- a/unlink.c
+++ b/unlink.c
_AT_@ -16,7 +16,7 @@ main(int argc, char *argv[])
         if (argc != 2)
                 usage();
 
- if (unlink(argv[1]) == -1)
+ if (unlink(argv[1]) < 0)
                 eprintf("unlink: '%s':", argv[1]);
 
         return 0;
diff --git a/xargs.c b/xargs.c
index d972a34..e253299 100644
--- a/xargs.c
+++ b/xargs.c
_AT_@ -191,22 +191,22 @@ poparg(void)
         int ch;
 
         argbpos = 0;
- if (eatspace() == -1)
+ if (eatspace() < 0)
                 return NULL;
         while ((ch = inputc()) != EOF) {
                 switch (ch) {
                 case ' ': case '\t': case '\n':
                         goto out;
                 case '\'':
- if (parsequote('\'') == -1)
+ if (parsequote('\'') < 0)
                                 eprintf("unterminated single quote\n");
                         break;
                 case '\"':
- if (parsequote('\"') == -1)
+ if (parsequote('\"') < 0)
                                 eprintf("unterminated double quote\n");
                         break;
                 case '\\':
- if (parseescape() == -1)
+ if (parseescape() < 0)
                                 eprintf("backslash at EOF\n");
                         break;
                 default:
Received on Wed Nov 19 2014 - 21:09:33 CET

This archive was generated by hypermail 2.3.0 : Wed Nov 19 2014 - 21:12:22 CET