core: implement gpiod_line_bulk_foreach_line_off()
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 23 Oct 2017 10:47:55 +0000 (12:47 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Mon, 23 Oct 2017 10:55:10 +0000 (12:55 +0200)
Implement a variant of gpiod_line_bulk_foreach_line() which allows to
store the loop state in an integer counter variable.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
include/gpiod.h

index 0f2839d6c475192d951745211288e6f9d3844520..fa4c7b94db27aebcf4ec6061b1a3ea43700a5b60 100644 (file)
@@ -468,6 +468,23 @@ gpiod_line_bulk_num_lines(struct gpiod_line_bulk *bulk)
             (lineptr) <= (bulk)->lines + ((bulk)->num_lines - 1);      \
             (lineptr)++, (line) = *(lineptr))
 
+/**
+ * @brief Iterate over all line handles held by a line bulk object.
+ * @param bulk Line bulk object.
+ * @param line GPIO line handle. On each iteration, the subsequent line handle
+ *             is assigned to this pointer.
+ * @param offset An integer variable used to store the loop state.
+ *
+ * This is a variant of ::gpiod_line_bulk_foreach_line which uses an integer
+ * variable (either signed or unsigned) to store the loop state. This offset
+ * variable is guaranteed to correspond with the offset of the current line in
+ * the bulk->lines array.
+ */
+#define gpiod_line_bulk_foreach_line_off(bulk, line, offset)           \
+       for ((offset) = 0, (line) = (bulk)->lines[0];                   \
+            (offset) < (bulk)->num_lines;                              \
+            (offset)++, (line) = (bulk)->lines[(offset)])
+
 /**
  * @}
  *