helpers: set errno in gpiod_chip_open_by_label()
authorBartosz Golaszewski <bartekgola@gmail.com>
Tue, 24 Oct 2017 12:25:02 +0000 (14:25 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Tue, 24 Oct 2017 12:25:02 +0000 (14:25 +0200)
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 <bartekgola@gmail.com>
src/lib/helpers.c
tests/tests-chip.c

index 4de9143e19d97da30e9a7e5a55718a1a5c165840..fc85b5851c7c57b346dc35cbd3d3ff90f1830e73 100644 (file)
@@ -19,6 +19,7 @@
 #include <string.h>
 #include <errno.h>
 #include <ctype.h>
+#include <errno.h>
 
 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;
 }
 
index 0f8d4178c03cb4e33258b958a33db1b697a28f27..e7527ecb3d6cce94d8cb8f7aa3159a6f628aa8bb 100644 (file)
@@ -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",