sigchk

sign and check files using ed25519
git clone git://z3bra.org/sick
Log | Files | Refs | Submodules | README | LICENSE

commit 4b839fbcd1c211ad38bad7122c8d5463357b959f
parent c59850226f23d54bd9ae04d4c729f9c22a81d765
Author: z3bra <willyatmailoodotorg>
Date:   Mon May  2 23:19:21 2016

Revert "Implement ARGLOOP() in arg.h"

This reverts commit c59850226f23d54bd9ae04d4c729f9c22a81d765.
Reading filenames from stdin doesn't add any value over using xargs,
so this code shouldn't be handled internally.

Diffstat:
 arg.h  | 16 ----------------
 sick.c | 22 +++++++++++-----------
 2 files changed, 11 insertions(+), 27 deletions(-)

diff --git a/arg.h b/arg.h @@ -29,20 +29,6 @@ extern char *argv0; argc_ = argv[0][0];\ switch (argc_) -#define ARGLOOP() while((argc>0 && *argv)||(!argc && !feof(stdin))){\ - char *lf_;\ - char argi_[LINE_MAX];\ - memset(argi_, 0, LINE_MAX);\ - if (argc>0) {\ - strncpy(argi_, *(argv++), LINE_MAX);\ - } else {\ - fgets(argi_, LINE_MAX, stdin);\ - }\ - if (strnlen(argi_, LINE_MAX) > 0) {\ - lf_ = strrchr(argi_, '\n');\ - if (lf_){ *lf_ = 0; } - - /* Handles obsolete -NUM syntax */ #define ARGNUM case '0':\ case '1':\ @@ -74,8 +60,6 @@ extern char *argv0; (&argv[0][1]) :\ (argc--, argv++, argv[0]))) -#define ARGI() argi_ - #define LNGARG() &argv[0][0] #endif diff --git a/sick.c b/sick.c @@ -65,7 +65,7 @@ check_magic(const char *file) if (stat(file, &sb) < 0) { perror(file); - return -1; + return NULL; } magic = malloc(strlen(MAGIC)); @@ -77,7 +77,7 @@ check_magic(const char *file) if (read(fd, magic, strlen(MAGIC)) < (unsigned int)strlen(MAGIC)) { perror(file); close(fd); - return -1; + return NULL; } close(fd); @@ -132,7 +132,7 @@ unsign(const char *file) if (stat(file, &sb) < 0) { perror(file); - return -1; + return NULL; } len = sb.st_size - 64 - strlen(MAGIC); @@ -369,33 +369,33 @@ main(int argc, char **argv) usage(argv0); }ARGEND; - ARGLOOP() { switch(action) { case ACTION_CHECK: - if (check(ARGI(), keyring) == 0) { + if (check(*argv, keyring) == 0) { if (!verbose) - puts(ARGI()); + puts(*argv); + } else { + return 1; } break; case ACTION_GENKEY: keygen(key ? key : DEFAULT_ALIAS); break; case ACTION_UNSIGN: - unsign(ARGI()); + unsign(*argv); break; case ACTION_SIGN: /* TODO: only check the pubkey matchng the private */ - if (check_magic(ARGI()) != 0) { - sign(ARGI(), key ? key : DEFAULT_ALIAS ".key"); + if (check_magic(*argv) != 0) { + sign(*argv, key ? key : DEFAULT_ALIAS ".key"); } else { - fprintf(stderr, "%s: Already signed\n", ARGI()); + fprintf(stderr, "%s: Already signed\n", *argv); return -1; } break; default: usage(argv0); } - }ARGEND; return 0; }