kee

Offline IOU signer with QR as transport
git clone https://holbrook.no/src/kee
Info | Log | Files | Refs | README | LICENSE

commit 6b42cd0876cf42c91c89270818dfa0f89518ba4a
parent b0fe20f21ce44e624c7156a81066f02d6395d6c2
Author: lash <dev@holbrook.no>
Date:   Thu, 13 Jun 2024 22:07:18 +0100

Add output from cli command

Diffstat:
Msrc/cmd/cli.c | 22++++++++++++++++++++++
Msrc/cmd/cli.h | 2++
Msrc/cmd/sign.c | 3+++
3 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/src/cmd/cli.c b/src/cmd/cli.c @@ -1,5 +1,6 @@ #include <string.h> #include <stdlib.h> +#include <unistd.h> #include "gpg.h" #include "err.h" @@ -52,6 +53,27 @@ int cli_init(struct kee_cli_t *cli, const char *passphrase) { } int cli_exit(struct kee_cli_t *cli, int err) { + int f; + int c; + int r; + + if (cli->result != NULL) { + if (err != ERR_OK) { + f = STDERR_FILENO; + } else { + f = STDOUT_FILENO; + } + c = cli->result_len; + while (c > 0) { + r = write(f, cli->result, c); + if (r == 0) { + debug_logerr(LLOG_CRITICAL, ERR_FAIL, "cli result output fail"); + err = ERR_FAIL; + break; + } + c -= r; + } + } cli_free(cli); return err; } diff --git a/src/cmd/cli.h b/src/cmd/cli.h @@ -10,6 +10,8 @@ struct kee_cli_t { struct kee_settings settings; struct gpg_store gpg; char *passphrase; + char *result; + size_t result_len; }; int cli_init(struct kee_cli_t *cli, const char *passphrase); diff --git a/src/cmd/sign.c b/src/cmd/sign.c @@ -127,5 +127,8 @@ int main(int argc, char **argv) { return cli_exit(&cli, ERR_FAIL); } + cli.result = b; + cli.result_len = (size_t)c; + return cli_exit(&cli, 0); }