From: Bartosz Golaszewski Date: Tue, 24 Oct 2017 12:25:02 +0000 (+0200) Subject: helpers: set errno in gpiod_chip_open_by_label() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=bce3718defb0732a4940f300d88eb4997426309b;p=qemu-gpiodev%2Flibgpiod.git 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 --- 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",