DIR *dir;
struct gpiod_chip *current;
int state;
+ char *failed_chip;
};
static const char dev_dir[] = "/dev/";
void gpiod_chip_iter_free_noclose(struct gpiod_chip_iter *iter)
{
closedir(iter->dir);
+ if (iter->failed_chip)
+ free(iter->failed_chip);
free(iter);
}
sizeof(cdev_prefix) - 1);
if (status == 0) {
iter->state = CHIP_ITER_INIT;
+ if (iter->failed_chip) {
+ free(iter->failed_chip);
+ iter->failed_chip = NULL;
+ }
chip = gpiod_chip_open_by_name(dentry->d_name);
- if (!chip)
+ if (!chip) {
iter->state = CHIP_ITER_ERR;
+ iter->failed_chip = strdup(dentry->d_name);
+ /* No point in an error check here. */
+ }
iter->current = chip;
return iter->current;
{
return iter->state == CHIP_ITER_ERR;
}
+
+const char *
+gpiod_chip_iter_failed_chip(struct gpiod_chip_iter *iter)
+{
+ return iter->failed_chip;
+}
*/
bool gpiod_chip_iter_iserr(struct gpiod_chip_iter *iter) GPIOD_API;
+/**
+ * @brief Get the name of the gpiochip that we failed to access.
+ * @param iter The gpiochip iterator object.
+ * @return If gpiod_chip_iter_iserr() returned true, this function returns a
+ * pointer to the name of the gpiochip that we failed to access.
+ * If there was no error this function returns NULL.
+ *
+ * NOTE: this function will return NULL if the internal memory allocation
+ * fails.
+ */
+const char *
+gpiod_chip_iter_failed_chip(struct gpiod_chip_iter *iter) GPIOD_API;
+
/**
* @brief GPIO line iterator structure.
*
gpiod_foreach_chip(iter, chip) {
if (gpiod_chip_iter_iserr(iter))
- die_perror("error accessing gpiochip");
+ die_perror("error accessing gpiochip %s",
+ gpiod_chip_iter_failed_chip(iter));
printf("%s [%s] (%u lines)\n",
gpiod_chip_name(chip),