From 16b4ad693b6b03b5a4a7408c2c105729f995dcff Mon Sep 17 00:00:00 2001 From: nirenjan Date: Mon, 18 May 2020 14:38:49 -0700 Subject: [PATCH] Fix error reporting in x52cli Prior to this change, x52cli assumed that the return code from the handler was a standard error code, but negated. This is an incorrect assumption as the libx52 API returns a `libx52_error_code` enum, which is a positive integer. This change fixes the printing of the error message to call `libx52_strerror`, which translates it correctly. It also adds error printing to any failure of `libx52_init`, as well as explicitly specifying `LIBX52_SUCCESS` instead of `0`. Addresses #19. --- utils/cli/x52_cli.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/cli/x52_cli.c b/utils/cli/x52_cli.c index 0f798fd..09542e4 100644 --- a/utils/cli/x52_cli.c +++ b/utils/cli/x52_cli.c @@ -378,13 +378,13 @@ int main(int argc, char **argv) rc = libx52_init(&x52); if (rc != LIBX52_SUCCESS) { - fprintf(stderr, "Unable to find X52 joystick!\n"); + fprintf(stderr, "Error initializing X52 joystick: %s\n", libx52_strerror(rc)); return 1; } rc = (*(cmd->handler))(x52, args); - if (rc != 0) { - fprintf(stderr, "Error: %s\n", strerror(-rc)); + if (rc != LIBX52_SUCCESS) { + fprintf(stderr, "Error: %s\n", libx52_strerror(rc)); } libx52_update(x52);