Use < 0 instead of == -1

This commit is contained in:
FRIGN 2014-11-19 20:59:37 +01:00 committed by sin
parent 9b38355ae8
commit 1436518f9d
21 changed files with 41 additions and 41 deletions

View File

@ -24,7 +24,7 @@ usage(void)
static void static void
chgrp(const char *path) chgrp(const char *path)
{ {
if (chown(path, st.st_uid, gid) == -1) { if (chown(path, st.st_uid, gid) < 0) {
weprintf("chown %s:", path); weprintf("chown %s:", path);
failures++; failures++;
} }
@ -57,7 +57,7 @@ main(int argc, char *argv[])
gid = gr->gr_gid; gid = gr->gr_gid;
while (*++argv) { while (*++argv) {
if (stat(*argv, &st) == -1) { if (stat(*argv, &st) < 0) {
weprintf("stat %s:", *argv); weprintf("stat %s:", *argv);
failures++; failures++;
continue; continue;

View File

@ -65,14 +65,14 @@ chmodr(const char *path)
struct stat st; struct stat st;
mode_t m; mode_t m;
if (stat(path, &st) == -1) { if (stat(path, &st) < 0) {
weprintf("stat %s:", path); weprintf("stat %s:", path);
ret = 1; ret = 1;
return; return;
} }
m = parsemode(modestr, st.st_mode, mask); m = parsemode(modestr, st.st_mode, mask);
if (chmod(path, m) == -1) { if (chmod(path, m) < 0) {
weprintf("chmod %s:", path); weprintf("chmod %s:", path);
ret = 1; ret = 1;
} }

View File

@ -81,7 +81,7 @@ main(int argc, char *argv[])
void void
chownpwgr(const char *path) chownpwgr(const char *path)
{ {
if (chown(path, uid, gid) == -1) { if (chown(path, uid, gid) < 0) {
weprintf("chown %s:", path); weprintf("chown %s:", path);
ret = 1; ret = 1;
} }

View File

@ -28,10 +28,10 @@ main(int argc, char *argv[])
if ((aux = getenv("SHELL"))) if ((aux = getenv("SHELL")))
shell[0] = aux; shell[0] = aux;
if (chroot(argv[0]) == -1) if (chroot(argv[0]) < 0)
eprintf("chroot %s:", argv[0]); eprintf("chroot %s:", argv[0]);
if (chdir("/") == -1) if (chdir("/") < 0)
eprintf("chdir:"); eprintf("chdir:");
if (argc == 1) { if (argc == 1) {

View File

@ -11,7 +11,7 @@ apathmax(char **p, long *size)
{ {
errno = 0; errno = 0;
if ((*size = pathconf("/", _PC_PATH_MAX)) == -1) { if ((*size = pathconf("/", _PC_PATH_MAX)) < 0) {
if (errno == 0) { if (errno == 0) {
*size = BUFSIZ; *size = BUFSIZ;
} else { } else {

View File

@ -66,7 +66,7 @@ cp(const char *s1, const char *s2)
if (!(dp = opendir(s1))) if (!(dp = opendir(s1)))
eprintf("opendir %s:", 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); eprintf("mkdir %s:", s2);
apathmax(&ns1, &size1); apathmax(&ns1, &size1);
@ -144,7 +144,7 @@ preserve:
r = lchown(s2, st.st_uid, st.st_gid); r = lchown(s2, st.st_uid, st.st_gid);
else else
r = chown(s2, st.st_uid, st.st_gid); r = chown(s2, st.st_uid, st.st_gid);
if (r == -1) { if (r < 0) {
weprintf("cp: can't preserve ownership of '%s':", s2); weprintf("cp: can't preserve ownership of '%s':", s2);
cp_status = 1; cp_status = 1;
} }

View File

@ -8,13 +8,13 @@ fnck(const char *a, const char *b, int (*fn)(const char *, const char *))
{ {
struct stat sta, stb; struct stat sta, stb;
if (stat(a, &sta) == 0 if (!stat(a, &sta)
&& stat(b, &stb) == 0 && !stat(b, &stb)
&& sta.st_dev == stb.st_dev && sta.st_dev == stb.st_dev
&& sta.st_ino == stb.st_ino) { && sta.st_ino == stb.st_ino) {
eprintf("%s -> %s: same file\n", a, b); eprintf("%s -> %s: same file\n", a, b);
} }
if (fn(a, b) == -1) if (fn(a, b) < 0)
eprintf("%s -> %s:", a, b); eprintf("%s -> %s:", a, b);
} }

View File

@ -18,7 +18,7 @@ recurse(const char *path, void (*fn)(const char *))
struct stat st; struct stat st;
DIR *dp; DIR *dp;
if (lstat(path, &st) == -1 || S_ISDIR(st.st_mode) == 0) if (lstat(path, &st) < 0 || !S_ISDIR(st.st_mode))
return; return;
if (!(dp = opendir(path))) if (!(dp = opendir(path)))

View File

@ -12,6 +12,6 @@ rm(const char *path)
{ {
if (rm_rflag) if (rm_rflag)
recurse(path, rm); recurse(path, rm);
if (remove(path) == -1 && !rm_fflag) if (remove(path) < 0 && !rm_fflag)
eprintf("remove %s:", path); eprintf("remove %s:", path);
} }

8
ls.c
View File

@ -137,7 +137,7 @@ lsdir(const char *path)
cwd = agetcwd(); cwd = agetcwd();
if (!(dp = opendir(path))) if (!(dp = opendir(path)))
eprintf("opendir %s:", path); eprintf("opendir %s:", path);
if (chdir(path) == -1) if (chdir(path) < 0)
eprintf("chdir %s:", path); eprintf("chdir %s:", path);
if (many) { if (many) {
@ -168,7 +168,7 @@ lsdir(const char *path)
free(ents[rflag ? n-i-1 : i].name); free(ents[rflag ? n-i-1 : i].name);
} }
} }
if (chdir(cwd) == -1) if (chdir(cwd) < 0)
eprintf("chdir %s:", cwd); eprintf("chdir %s:", cwd);
free(ents); free(ents);
free(cwd); free(cwd);
@ -182,7 +182,7 @@ mkent(Entry *ent, char *path, int dostat)
ent->name = path; ent->name = path;
if (!dostat) if (!dostat)
return; return;
if (lstat(path, &st) == -1) if (lstat(path, &st) < 0)
eprintf("lstat %s:", path); eprintf("lstat %s:", path);
ent->mode = st.st_mode; ent->mode = st.st_mode;
ent->nlink = st.st_nlink; ent->nlink = st.st_nlink;
@ -291,7 +291,7 @@ output(Entry *ent)
printf("%10lu ", (unsigned long)ent->size); printf("%10lu ", (unsigned long)ent->size);
printf("%s %s%s", buf, ent->name, indicator(ent->mode)); printf("%s %s%s", buf, ent->name, indicator(ent->mode));
if (S_ISLNK(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); eprintf("readlink %s:", ent->name);
buf[len] = '\0'; buf[len] = '\0';
mkent(&entlnk, buf, Fflag); mkent(&entlnk, buf, Fflag);

View File

@ -41,7 +41,7 @@ main(int argc, char *argv[])
for (; argc > 0; argc--, argv++) { for (; argc > 0; argc--, argv++) {
if (pflag) { if (pflag) {
mkdirp(argv[0]); 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]); eprintf("mkdir %s:", argv[0]);
} }
if (mflag) if (mflag)
@ -60,7 +60,7 @@ mkdirp(char *path)
do { do {
if (*p && (p = strchr(&p[1], '/'))) if (*p && (p = strchr(&p[1], '/')))
*p = '\0'; *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); eprintf("mkdir %s:", path);
if (p) if (p)
*p = '/'; *p = '/';

View File

@ -30,7 +30,7 @@ main(int argc, char *argv[])
usage(); usage();
for (; argc > 0; argc--, argv++) for (; argc > 0; argc--, argv++)
if (mkfifo(argv[0], mode) == -1) if (mkfifo(argv[0], mode) < 0)
eprintf("mkfifo %s:", argv[0]); eprintf("mkfifo %s:", argv[0]);
return 0; return 0;
} }

View File

@ -34,15 +34,15 @@ main(int argc, char *argv[])
if (isatty(STDOUT_FILENO)) { if (isatty(STDOUT_FILENO)) {
if ((fd = open("nohup.out", O_APPEND|O_CREAT, if ((fd = open("nohup.out", O_APPEND|O_CREAT,
S_IRUSR|S_IWUSR)) == -1) { S_IRUSR|S_IWUSR)) < 0) {
enprintf(Error, "open nohup.out:"); enprintf(Error, "open nohup.out:");
} }
if (dup2(fd, STDOUT_FILENO) == -1) if (dup2(fd, STDOUT_FILENO) < 0)
enprintf(Error, "dup2:"); enprintf(Error, "dup2:");
close(fd); close(fd);
} }
if (isatty(STDERR_FILENO)) if (isatty(STDERR_FILENO))
if (dup2(STDOUT_FILENO, STDERR_FILENO) == -1) if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0)
enprintf(Error, "dup2:"); enprintf(Error, "dup2:");
execvp(argv[0], &argv[0]); execvp(argv[0], &argv[0]);

4
pwd.c
View File

@ -41,9 +41,9 @@ getpwd(const char *cwd)
const char *pwd; const char *pwd;
struct stat cst, pst; 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; return cwd;
if (stat(cwd, &cst) == -1) if (stat(cwd, &cst) < 0)
eprintf("stat %s:", cwd); eprintf("stat %s:", cwd);
if (pst.st_dev == cst.st_dev && pst.st_ino == cst.st_ino) if (pst.st_dev == cst.st_dev && pst.st_ino == cst.st_ino)
return pwd; return pwd;

View File

@ -105,7 +105,7 @@ renice(int which, int who, long adj)
} }
adj = MAX(PRIO_MIN, MIN(adj, PRIO_MAX)); 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); weprintf("setpriority %d:", who);
return 0; return 0;
} }

View File

@ -23,7 +23,7 @@ main(int argc, char *argv[])
usage(); usage();
for (; argc > 0; argc--, argv++) for (; argc > 0; argc--, argv++)
if (rmdir(argv[0]) == -1) if (rmdir(argv[0]) < 0)
weprintf("rmdir %s:", argv[0]); weprintf("rmdir %s:", argv[0]);
return 0; return 0;
} }

4
sort.c
View File

@ -208,7 +208,7 @@ parse_keydef(struct keydef *kd, char *s, int flags)
kd->start_char = strtol(rest+1, &rest, 10); kd->start_char = strtol(rest+1, &rest, 10);
if (kd->start_char < 1) if (kd->start_char < 1)
return -1; return -1;
if (parse_flags(&rest, &kd->flags, MOD_STARTB) == -1) if (parse_flags(&rest, &kd->flags, MOD_STARTB) < 0)
return -1; return -1;
if (*rest == ',') { if (*rest == ',') {
kd->end_column = strtol(rest+1, &rest, 10); kd->end_column = strtol(rest+1, &rest, 10);
@ -219,7 +219,7 @@ parse_keydef(struct keydef *kd, char *s, int flags)
if (kd->end_char < 1) if (kd->end_char < 1)
return -1; return -1;
} }
if (parse_flags(&rest, &kd->flags, MOD_ENDB) == -1) if (parse_flags(&rest, &kd->flags, MOD_ENDB) < 0)
return -1; return -1;
} }
if (*rest != '\0') if (*rest != '\0')

View File

@ -131,7 +131,7 @@ nextfile(FILE *f, char *buf, int plen, int slen)
if (f) if (f)
fclose(f); fclose(f);
s = itostr(buf+plen, n++, slen); s = itostr(buf+plen, n++, slen);
if (s == -1) if (s < 0)
return NULL; return NULL;
f = fopen(buf, "w"); f = fopen(buf, "w");

View File

@ -55,7 +55,7 @@ touch(const char *str)
if (stat(str, &st) == 0) { if (stat(str, &st) == 0) {
ut.actime = st.st_atime; ut.actime = st.st_atime;
ut.modtime = t; ut.modtime = t;
if (utime(str, &ut) == -1) if (utime(str, &ut) < 0)
eprintf("utime %s:", str); eprintf("utime %s:", str);
return; return;
} }
@ -64,7 +64,7 @@ touch(const char *str)
else if (cflag) else if (cflag)
return; return;
if ((fd = open(str, O_CREAT|O_EXCL, 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); eprintf("open %s:", str);
close(fd); close(fd);
touch(str); touch(str);

View File

@ -16,7 +16,7 @@ main(int argc, char *argv[])
if (argc != 2) if (argc != 2)
usage(); usage();
if (unlink(argv[1]) == -1) if (unlink(argv[1]) < 0)
eprintf("unlink: '%s':", argv[1]); eprintf("unlink: '%s':", argv[1]);
return 0; return 0;

View File

@ -191,22 +191,22 @@ poparg(void)
int ch; int ch;
argbpos = 0; argbpos = 0;
if (eatspace() == -1) if (eatspace() < 0)
return NULL; return NULL;
while ((ch = inputc()) != EOF) { while ((ch = inputc()) != EOF) {
switch (ch) { switch (ch) {
case ' ': case '\t': case '\n': case ' ': case '\t': case '\n':
goto out; goto out;
case '\'': case '\'':
if (parsequote('\'') == -1) if (parsequote('\'') < 0)
eprintf("unterminated single quote\n"); eprintf("unterminated single quote\n");
break; break;
case '\"': case '\"':
if (parsequote('\"') == -1) if (parsequote('\"') < 0)
eprintf("unterminated double quote\n"); eprintf("unterminated double quote\n");
break; break;
case '\\': case '\\':
if (parseescape() == -1) if (parseescape() < 0)
eprintf("backslash at EOF\n"); eprintf("backslash at EOF\n");
break; break;
default: default: