From 05c5815fb970da9c29a4cf8da783e9b147cb3abb Mon Sep 17 00:00:00 2001 From: listout Date: Fri, 29 Jul 2022 19:29:13 +0530 Subject: [PATCH] Use fprintf instead of error hidpp files were using the error function from error.h header file. Unfortunately not every libc comes with this particular header file, so with this patch we won't be requiring to be rely on error function and use fprintf function. Thanks to developer Yaroslav Chvanov for the original suggestion Closes: https://github.com/libratbag/libratbag/issues/1253 Signed-off-by: listout --- tools/hidpp10-dump-page.c | 7 ++++--- tools/hidpp20-dump-page.c | 13 ++++++++----- tools/hidpp20-reset.c | 13 ++++++++----- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/tools/hidpp10-dump-page.c b/tools/hidpp10-dump-page.c index 5d27659a..f059b291 100644 --- a/tools/hidpp10-dump-page.c +++ b/tools/hidpp10-dump-page.c @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -94,8 +93,10 @@ main(int argc, char **argv) path = argv[argc - 1]; fd = open(path, O_RDWR); - if (fd < 0) - error(1, errno, "Failed to open path %s", path); + if (fd < 0) { + fprintf(stderr, "Failed to open path '%s': %s", path, strerror(errno)); + exit(3); + } hidpp_device_init(&base, fd); rc = hidpp10_device_new(&base, HIDPP_WIRED_DEVICE_IDX, HIDPP10_PROFILE_UNKNOWN, 5, &dev); diff --git a/tools/hidpp20-dump-page.c b/tools/hidpp20-dump-page.c index 76ccd3d1..d1ffc7d1 100644 --- a/tools/hidpp20-dump-page.c +++ b/tools/hidpp20-dump-page.c @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -111,13 +110,17 @@ main(int argc, char **argv) path = argv[argc - 1]; fd = open(path, O_RDWR); - if (fd < 0) - error(1, errno, "Failed to open path %s", path); + if (fd < 0) { + fprintf(stderr, "Failed to open path '%s': %s", path, strerror(errno)); + exit(3); + } hidpp_device_init(&base, fd); dev = hidpp20_device_new(&base, 0xff, NULL, 0); - if (!dev) - error(1, 0, "Failed to open %s as a HID++ 2.0 device", path); + if (!dev) { + fprintf(stderr, "Failed to open %s as a HID++ 2.0 device", path); + exit(3); + } hidpp20_onboard_profiles_get_profiles_desc(dev, &info); diff --git a/tools/hidpp20-reset.c b/tools/hidpp20-reset.c index f31f11e3..bb944e83 100644 --- a/tools/hidpp20-reset.c +++ b/tools/hidpp20-reset.c @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -87,13 +86,17 @@ main(int argc, char **argv) path = argv[argc - 1]; fd = open(path, O_RDWR); - if (fd < 0) - error(1, errno, "Failed to open path %s", path); + if (fd < 0) { + fprintf(stderr, "Failed to open path '%s': %s", path, strerror(errno)); + exit(3); + } hidpp_device_init(&base, fd); dev = hidpp20_device_new(&base, 0xff, NULL, 0); - if (!dev) - error(1, 0, "Failed to open %s as a HID++ 2.0 device", path); + if (!dev) { + fprintf(stderr, "Failed to open %s as a HID++ 2.0 device", path); + exit(3); + } hidpp20_onboard_profiles_get_profiles_desc(dev, &info);