ap

An audio player suited to my tastes
Log | Files | Refs | README | LICENSE

commit ef1837bac8326e899ab2f9d0d9066874f92955a7
parent e5bf82213147abc9abbac758611fd7ed52d71bf7
Author: Jacob R. Edwards <n/a>
Date:   Thu, 13 Oct 2022 18:32:22 -0700

Fix how the client library stores the status message

Previously 'ok' was stored as it was and errors had the 'error: '
prefix removed. This would make it impossible to see the difference
between the 'ok' and 'error: ok' status messages. Now status messages
are left untouched and a function, apc_error, is provided to get
the error message from an error status.

Diffstat:
Mapc/apc.c | 2+-
Mlib/ap/client.c | 12++++++++----
Mlib/ap/client.h | 1+
3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/apc/apc.c b/apc/apc.c @@ -72,7 +72,7 @@ printresponse(struct apc *apc) if (apc->status == NULL) return 1; if (strcmp(apc->status, "ok") != 0) - return fprintf(stderr, "error: %s\n", apc->status) < 0; + return fprintf(stderr, "%s\n", apc->status) < 0; return 0; } diff --git a/lib/ap/client.c b/lib/ap/client.c @@ -96,10 +96,6 @@ apc_read(struct apc *apc) return NULL; if (strcmp(buf, "ok") == 0 || strncmp(buf, "error: ", 7) == 0) { - if (*buf == 'e') { - memmove(buf, buf + 7, len - 7); - buf[len - 7] = 0; - } free(apc->status); apc->status = buf; return NULL; @@ -107,3 +103,11 @@ apc_read(struct apc *apc) return buf; } + +char * +apc_error(struct apc *apc) +{ + if (apc->status && apc->status[0] == 'e') + return apc->status + 7; + return NULL; +} diff --git a/lib/ap/client.h b/lib/ap/client.h @@ -12,3 +12,4 @@ int apc_bufword(struct apc *, char *); int apc_write(struct apc *); int apc_recv(struct apc *); char *apc_read(struct apc *); +char *apc_error(struct apc *);