From: Bartosz Golaszewski Date: Mon, 23 Oct 2017 10:47:55 +0000 (+0200) Subject: core: implement gpiod_line_bulk_foreach_line_off() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=5ba624dd6901c08cf2140b0487debafbb72079a1;p=qemu-gpiodev%2Flibgpiod.git core: implement gpiod_line_bulk_foreach_line_off() 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 --- diff --git a/include/gpiod.h b/include/gpiod.h index 0f2839d..fa4c7b9 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -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)]) + /** * @} *