From bce3718defb0732a4940f300d88eb4997426309b Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Tue, 24 Oct 2017 14:25:02 +0200 Subject: [PATCH] helpers: set errno in gpiod_chip_open_by_label() If a GPIO chip with given label cannot be found but no other error occurred, set errno to ENOENT before returning a NULL pointer. Update the relevant test case. Signed-off-by: Bartosz Golaszewski --- src/lib/helpers.c | 4 ++++ tests/tests-chip.c | 1 + 2 files changed, 5 insertions(+) diff --git a/src/lib/helpers.c b/src/lib/helpers.c index 4de9143..fc85b58 100644 --- a/src/lib/helpers.c +++ b/src/lib/helpers.c @@ -19,6 +19,7 @@ #include #include #include +#include static bool isuint(const char *str) { @@ -78,8 +79,11 @@ struct gpiod_chip * gpiod_chip_open_by_label(const char *label) } } + errno = ENOENT; + out: gpiod_chip_iter_free(iter); + return NULL; } diff --git a/tests/tests-chip.c b/tests/tests-chip.c index 0f8d417..e7527ec 100644 --- a/tests/tests-chip.c +++ b/tests/tests-chip.c @@ -119,6 +119,7 @@ static void chip_open_by_label_bad(void) chip = gpiod_chip_open_by_label("nonexistent_gpio_chip"); TEST_ASSERT_NULL(chip); + TEST_ASSERT_ERRNO_IS(ENOENT); } TEST_DEFINE(chip_open_by_label_bad, "gpiod_chip_open_by_label() - bad", -- 2.30.2