X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/9b1663a5574182a66c6de8ad2fce7b3e4cbf277b..HEAD:/progs/catsign.c diff --git a/progs/catsign.c b/progs/catsign.c index 47a951e7..d27016ff 100644 --- a/progs/catsign.c +++ b/progs/catsign.c @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -160,7 +161,7 @@ static size_t textread(msgcanon *m, void *bp) if (n >= MSGBUFTHRESH) goto full; b[n++] = ch; f &= ~F_MIDLINE; - } else if (isspace(ch)) { + } else if (ISSPACE(ch)) { f |= F_MIDLINE; if (n >= MSGBUFSZ) goto full; b[n++] = ch; nsp++; @@ -221,7 +222,7 @@ static void nullwrite(msgcanon *m, const void *bp, size_t n) { ; } static void mcsetup_readfile(msgcanon *m, unsigned f, const char *fn) { m->f = F_DETACH | (f & (F_BINARY | F_PROGRESS)); - if (!fn || strcmp(fn, "-") == 0) { + if (!fn || STRCMP(fn, ==, "-")) { m->fp = stdin; m->f |= F_NOCLOSE; } else if ((m->fp = fopen(fn, (f & F_BINARY) ? "rb" : "r")) == 0) @@ -259,7 +260,7 @@ static void mcsetup_read(msgcanon *m, unsigned f, enc **ee, } } else { m->read = binreaddetach; - if (!dfn || strcmp(dfn, "-") == 0) + if (!dfn || STRCMP(dfn, ==, "-")) m->fp = stdin; else if ((m->fp = fopen(dfn, "rb")) == 0) die(EXIT_FAILURE, "can't open `%s': %s", dfn, strerror(errno)); @@ -287,7 +288,7 @@ static void mcsetup_read(msgcanon *m, unsigned f, enc **ee, } } } else { - if (!dfn || strcmp(dfn, "-") == 0) + if (!dfn || STRCMP(dfn, ==, "-")) m->fp = stdin; else if ((m->fp = fopen(dfn, "r")) == 0) die(EXIT_FAILURE, "can't read file `%s': %s", dfn, strerror(errno)); @@ -394,7 +395,6 @@ static void sigtobuffer(sigmsg *s, buf *b, int hashp) static void dohash(ghash *h, const void *p, size_t n) { -/* trace_block(1, "hashing", p, n); */ GH_HASH(h, p, n); } @@ -436,11 +436,12 @@ static void sig_writeheader(enc *e, sigmsg *s) static void sig_writesig(enc *e, sigmsg *s) { chunk_write(e, s->sig.buf, s->sig.len); } -static void diechoke(const char *m, void *p) +static void NORETURN diechoke(const char *m, void *p) { die(EXIT_FAILURE, "%s%s%s", (const char *)p, p ? ": " : "", m); } static void sig_readheader(enc *e, sigmsg *s, - void (*choke)(const char *, void *), void *p) + void NORETURN (*choke)(const char *, void *), + void *p) { uint16 f; octet bb[MSGBUFSZ]; @@ -532,7 +533,7 @@ static int sign(int argc, char *argv[]) fn = (optind >= argc) ? 0 : argv[optind++]; - if (!of || strcmp(of, "-") == 0) + if (!of || STRCMP(of, ==, "-")) ofp = stdout; else if ((ofp = fopen(of, eo->wmode)) == 0) { die(EXIT_FAILURE, "couldn't open file `%s' for output: %s", @@ -598,14 +599,14 @@ static int vrfbdry(const char *b, void *p) { vrfctx *v = p; - if (strcmp(b, "CATSIGN MESSAGE") == 0) { + if (STRCMP(b, ==, "CATSIGN MESSAGE")) { v->f |= F_BINARY; v->m |= F_BINARY | F_DETACH; return (1); - } else if (strcmp(b, "CATSIGN MESSAGE HEADER") == 0) { + } else if (STRCMP(b, ==, "CATSIGN MESSAGE HEADER")) { v->m |= F_BINARY | F_DETACH; return (1); - } else if (strcmp(b, "CATSIGN SIGNATURE") == 0) { + } else if (STRCMP(b, ==, "CATSIGN SIGNATURE")) { v->f |= F_DETACH; v->m |= F_DETACH; return (1); @@ -613,7 +614,7 @@ static int vrfbdry(const char *b, void *p) return (0); } -static void vrfchoke(const char *m, void *p) +static void NORETURN vrfchoke(const char *m, void *p) { vrfctx *v = p; if (v->verb) printf("FAIL %s: %s\n", v->what, m); @@ -667,7 +668,7 @@ static int verify(int argc, char *argv[]) case 'u': v.f |= F_UTC; break; case 'C': v.f |= F_NOCHECK; break; case 't': - if (strcmp(optarg, "always") == 0) t_fresh = 0; + if (STRCMP(optarg, ==, "always")) t_fresh = 0; else if ((t_fresh = get_date(optarg, 0)) < 0) die(EXIT_FAILURE, "bad freshness time"); break; @@ -684,7 +685,7 @@ static int verify(int argc, char *argv[]) die(EXIT_FAILURE, "encoding `%s' not found", ef); fn = optind < argc ? argv[optind++] : "-"; - if (strcmp(fn, "-") == 0) + if (STRCMP(fn, ==, "-")) fp = stdin; else if ((fp = fopen(fn, eo->rmode)) == 0) { die(EXIT_FAILURE, "couldn't open file `%s': %s", @@ -714,7 +715,7 @@ static int verify(int argc, char *argv[]) (unsigned long)s.keyid); exit(EXIT_FAILURE); } - if (kk && k->id != kk->id) { + if (kk && k != kk) { if (v.verb) { dstr_reset(&d); key_fulltag(k, &d); dstr_reset(&dd); key_fulltag(kk, &dd); @@ -729,7 +730,7 @@ static int verify(int argc, char *argv[]) printf("WARN verification key %s fails check: %s\n", d.buf, err); dstr_reset(&dd); keyhash(k, s.s, &dd); - if (dd.len != s.kh.len || memcmp(dd.buf, s.kh.buf, dd.len) != 0) { + if (dd.len != s.kh.len || MEMCMP(dd.buf, !=, s.kh.buf, dd.len)) { if (v.verb) printf("FAIL key hash mismatch\n"); exit(EXIT_FAILURE); } @@ -745,17 +746,17 @@ static int verify(int argc, char *argv[]) if (!of && (v.f & F_DETACH)) { rfp = ofp = 0; v.f &= ~F_BUFFER; - } else if (!of || strcmp(of, "-") == 0) { + } else if (!of || STRCMP(of, ==, "-")) { v.f |= F_BUFFER; ofp = stdout; - } - if (of && !(v.f & F_BUFFER)) { + } else if (of && !(v.f & F_BUFFER)) { if ((ofp = fopen(of, (v.f & F_BINARY) ? "wb" : "w")) == 0) { die(EXIT_FAILURE, "couldn't open file `%s' for output: %s", of, strerror(errno)); } rfp = ofp; - } else if ((rfp = tmpfile()) == 0) + } + if ((v.f & F_BUFFER) && (rfp = tmpfile()) == 0) die(EXIT_FAILURE, "couldn't create temporary file: %s", strerror(errno)); /* --- Read the message and verify the signature --- */ @@ -892,7 +893,7 @@ static int format(int argc, char *argv[]) die(EXIT_FAILURE, "encoding `%s' not found", oef); fn = optind < argc ? argv[optind++] : "-"; - if (strcmp(fn, "-") == 0) + if (STRCMP(fn, ==, "-")) fp = stdin; else if ((fp = fopen(fn, ieo->rmode)) == 0) { die(EXIT_FAILURE, "couldn't open file `%s': %s", @@ -926,7 +927,7 @@ static int format(int argc, char *argv[]) if (!of) mcsetup_writenull(&mc_out); else { - if (strcmp(of, "-") == 0) + if (STRCMP(of, ==, "-")) ofp = stdout; else if ((ofp = fopen(of, oeo->wmode)) == 0) { die(EXIT_FAILURE, "couldn't open file `%s' for output: %s", @@ -941,7 +942,7 @@ static int format(int argc, char *argv[]) } if (mf) { - if (strcmp(mf, "-") == 0) + if (STRCMP(mf, ==, "-")) mfp = stdout; else if ((mfp = fopen(mf, (f & F_BINARY) ? "wb" : "w")) == 0) { die(EXIT_FAILURE, "couldn't open file `%s' for output: %s", @@ -984,7 +985,7 @@ static int format(int argc, char *argv[]) return (0); } -static void infochoke(const char *m, void *p) +static void NORETURN infochoke(const char *m, void *p) { vrfctx *v = p; printf("BAD %s: %s\n", v->what, m); @@ -1036,7 +1037,7 @@ static int info(int argc, char *argv[]) if (optind >= argc) fp = stdin; - else if (strcmp(argv[optind], "-") == 0) { + else if (STRCMP(argv[optind], ==, "-")) { fp = stdin; optind++; } else if ((fp = fopen(argv[optind], eo->rmode)) == 0) { @@ -1220,7 +1221,6 @@ int main(int argc, char *argv[]) sub_init(); rand_noisesrc(RAND_GLOBAL, &noise_source); rand_seed(RAND_GLOBAL, 160); -/* trace_on(stderr, 1); */ /* --- Parse options --- */