sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 7fc5856e6453fc60d73150cda10196b932adddd5
parent ec8246bbc67678f1e38d279e005b6d0f3e9003d7
Author: FRIGN <dev@frign.de>
Date:   Thu Nov 13 22:16:29 +0100

Tweak NULL-pointer checks

Use !p and p when comparing pointers as opposed to explicit
checks against NULL.  This is generally easier to read.

Diffstat:
cksum.c | 2+-
readlink.c | 2+-
sort.c | 8++++----
split.c | 4++--
uniq.c | 4++--
util/crypt.c | 6+++---
util/getlines.c | 2+-
uudecode.c | 12++++++------
8 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/cksum.c b/cksum.c @@ -114,7 +114,7 @@ cksum(FILE *fp, const char *s) ck = (ck << 8) ^ crctab[(ck >> 24) ^ (i & 0xFF)]; printf("%"PRIu32" %lu", ~ck, (unsigned long)len); - if (s != NULL) + if (s) printf(" %s", s); putchar('\n'); } diff --git a/readlink.c b/readlink.c @@ -43,7 +43,7 @@ main(int argc, char *argv[]) return 1; if (fflag) { - if (realpath(argv[0], buf) == NULL) + if (!realpath(argv[0], buf)) exit(1); } else { if ((n = readlink(argv[0], buf, sizeof(buf) - 1)) < 0) diff --git a/sort.c b/sort.c @@ -238,12 +238,12 @@ skipblank(char *s) static char * nextcol(char *s) { - if (fieldsep == NULL) { + if (!fieldsep) { s = skipblank(s); while(*s && !isblank(*s)) s++; } else { - if (strchr(s, *fieldsep) == NULL) + if (!strchr(s, *fieldsep)) s = strchr(s, '\0'); else s = strchr(s, *fieldsep) + 1; @@ -274,11 +274,11 @@ columns(char *line, const struct keydef *kd) else end = nextcol(end); } else { - if ((end = strchr(line, '\n')) == NULL) + if (!(end = strchr(line, '\n'))) end = strchr(line, '\0'); } - if ((res = strndup(start, end - start)) == NULL) + if (!(res = strndup(start, end - start))) enprintf(2, "strndup:"); return res; } diff --git a/split.c b/split.c @@ -36,11 +36,11 @@ main(int argc, char *argv[]) case 'b': always = 1; tmp = ARGF(); - if (tmp == NULL) + if (!tmp) break; size = strtoull(tmp, &end, 10); - if (*end == '\0') + if (!*end) break; switch (toupper((int)*end)) { case 'K': diff --git a/uniq.c b/uniq.c @@ -62,7 +62,7 @@ main(int argc, char *argv[]) static void uniqline(char *l) { - int linesequel = ((l == NULL) || (prevline == NULL)) + int linesequel = (!l || !prevline) ? l == prevline : !strcmp(l, prevline); @@ -71,7 +71,7 @@ uniqline(char *l) return; } - if (prevline != NULL) { + if (prevline) { if ((prevlinecount == 1 && !dflag) || (prevlinecount != 1 && !uflag)) { printf(countfmt, prevlinecount); diff --git a/util/crypt.c b/util/crypt.c @@ -46,7 +46,7 @@ cryptcheck(char *sumfile, int argc, char *argv[], int r, nonmatch = 0, formatsucks = 0, noread = 0, ret = 0; size_t bufsiz = 0; - if (sumfile == NULL) + if (!sumfile) cfp = stdin; else if (!(cfp = fopen(sumfile, "r"))) eprintf("fopen %s:", sumfile); @@ -81,7 +81,7 @@ cryptcheck(char *sumfile, int argc, char *argv[], } fclose(fp); } - if (sumfile != NULL) + if (sumfile) fclose(cfp); free(line); if (formatsucks > 0) { @@ -111,7 +111,7 @@ cryptmain(int argc, char *argv[], mdprint(md, "<stdin>", sz); } else { for (; argc > 0; argc--) { - if ((fp = fopen(*argv, "r")) == NULL) { + if (!(fp = fopen(*argv, "r"))) { weprintf("fopen %s:", *argv); ret = 1; continue; diff --git a/util/getlines.c b/util/getlines.c @@ -17,7 +17,7 @@ getlines(FILE *fp, struct linebuf *b) if (++b->nlines > b->capacity) { b->capacity += 512; nline = realloc(b->lines, b->capacity * sizeof(*b->lines)); - if (nline == NULL) + if (!nline) eprintf("realloc:"); b->lines = nline; } diff --git a/uudecode.c b/uudecode.c @@ -40,14 +40,14 @@ main(int argc, char *argv[]) if (argc == 0) { parseheader(stdin, "<stdin>", "begin ", &mode, &fname); - if ((nfp = parsefile(fname)) == NULL) + if (!(nfp = parsefile(fname))) eprintf("fopen %s:", fname); uudecode(stdin, nfp); } else { - if ((fp = fopen(argv[0], "r")) == NULL) + if (!(fp = fopen(argv[0], "r"))) eprintf("fopen %s:", argv[0]); parseheader(fp, argv[0], "begin ", &mode, &fname); - if ((nfp = parsefile(fname)) == NULL) + if (!(nfp = parsefile(fname))) eprintf("fopen %s:", fname); uudecode(fp, nfp); } @@ -93,18 +93,18 @@ parseheader(FILE *fp, const char *s, const char *header, mode_t *mode, char **fn char *p, *q; size_t n; - if (fgets(bufs, sizeof(bufs), fp) == NULL) + if (!fgets(bufs, sizeof(bufs), fp)) if (ferror(fp)) eprintf("%s: read error:", s); if (bufs[0] == '\0' || feof(fp)) eprintf("empty or nil header string\n"); - if ((p = strchr(bufs, '\n')) == NULL) + if (!(p = strchr(bufs, '\n'))) eprintf("header string too long or non-newline terminated file\n"); p = bufs; if (strncmp(bufs, header, strlen(header)) != 0) eprintf("malformed header prefix\n"); p += strlen(header); - if ((q = strchr(p, ' ')) == NULL) + if (!(q = strchr(p, ' '))) eprintf("malformed mode string in header\n"); *q++ = '\0'; /* now mode should be null terminated, q points to fname */