* Functions and data structures dealing with GPIO chips.
*/
+/**
+ * @brief Check if the file pointed to by path is a GPIO chip character device.
+ * @param path Path to check.
+ * @return True if the file exists and is a GPIO chip character device or a
+ * symbolic link to it.
+ */
+bool gpiod_is_gpiochip_device(const char *path) GPIOD_API;
+
/**
* @brief Open a gpiochip by path.
* @param path Path to the gpiochip device file.
(index) < (bulk)->num_lines; \
(index)++, (line) = (bulk)->lines[(index)])
-static bool is_gpiochip_cdev(const char *path)
+bool gpiod_is_gpiochip_device(const char *path)
{
char *name, *realname, *sysfsp, sysfsdev[16], devstr[16];
struct stat statbuf;
* We were able to open the file but is it really a gpiochip character
* device?
*/
- if (!is_gpiochip_cdev(path))
+ if (!gpiod_is_gpiochip_device(path))
goto err_close_fd;
chip = malloc(sizeof(*chip));
#define GPIOD_TEST_GROUP "chip"
+GPIOD_TEST_CASE(is_gpiochip_good, 0, { 8 })
+{
+ g_assert_true(gpiod_is_gpiochip_device(gpiod_test_chip_path(0)));
+}
+
+GPIOD_TEST_CASE(is_gpiochip_bad, 0, { 8 })
+{
+ g_assert_false(gpiod_is_gpiochip_device("/dev/null"));
+}
+
+GPIOD_TEST_CASE(is_gpiochip_nonexistent, 0, { 8 })
+{
+ g_assert_false(gpiod_is_gpiochip_device("/dev/nonexistent_gpiochip"));
+}
+
GPIOD_TEST_CASE(open_good, 0, { 8 })
{
g_autoptr(gpiod_chip_struct) chip = NULL;