@@ -9,6 +9,7 @@
#define __LIBGPIOD_GPIOD_H__
#include <stdbool.h>
+#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
@@ -99,7 +100,7 @@ const char *gpiod_chip_get_path(struct gpiod_chip *chip);
* @param chip GPIO chip object.
* @return Number of GPIO lines.
*/
-unsigned int gpiod_chip_get_num_lines(struct gpiod_chip *chip);
+size_t gpiod_chip_get_num_lines(struct gpiod_chip *chip);
/**
* @brief Get the current snapshot of information about the line at given
@@ -940,7 +941,7 @@ gpiod_line_config_set_output_value_override(struct gpiod_line_config *config,
* the previous argument.
*/
void gpiod_line_config_set_output_values(struct gpiod_line_config *config,
- unsigned int num_values,
+ size_t num_values,
const unsigned int *offsets,
const int *values);
@@ -1016,8 +1017,7 @@ enum {
* @param config Line config object.
* @return Number of individual overridden settings.
*/
-unsigned int
-gpiod_line_config_get_num_overrides(struct gpiod_line_config *config);
+size_t gpiod_line_config_get_num_overrides(struct gpiod_line_config *config);
/**
* @brief Get the list of overridden offsets and the corresponding types of
@@ -1090,7 +1090,7 @@ gpiod_request_config_get_consumer(struct gpiod_request_config *config);
* accepted by the kernel (64 lines) are silently dropped.
*/
void gpiod_request_config_set_offsets(struct gpiod_request_config *config,
- unsigned int num_offsets,
+ size_t num_offsets,
const unsigned int *offsets);
/**
@@ -1098,7 +1098,7 @@ void gpiod_request_config_set_offsets(struct gpiod_request_config *config,
* @param config Request config object.
* @return Number of line offsets in this request config.
*/
-unsigned int
+size_t
gpiod_request_config_get_num_offsets(struct gpiod_request_config *config);
/**
@@ -1119,14 +1119,14 @@ void gpiod_request_config_get_offsets(struct gpiod_request_config *config,
*/
void
gpiod_request_config_set_event_buffer_size(struct gpiod_request_config *config,
- unsigned int event_buffer_size);
+ size_t event_buffer_size);
/**
* @brief Get the edge event buffer size from this request config.
* @param config Request config object.
* @return Current edge event buffer size setting.
*/
-unsigned int
+size_t
gpiod_request_config_get_event_buffer_size(struct gpiod_request_config *config);
/**
@@ -1149,7 +1149,7 @@ void gpiod_line_request_release(struct gpiod_line_request *request);
* @param request Line request object.
* @return Number of requested lines.
*/
-unsigned int gpiod_line_request_get_num_lines(struct gpiod_line_request *request);
+size_t gpiod_line_request_get_num_lines(struct gpiod_line_request *request);
/**
* @brief Get the hardware offsets of lines in this request.
@@ -1179,7 +1179,7 @@ int gpiod_line_request_get_value(struct gpiod_line_request *request,
* @return 0 on success, -1 on failure.
*/
int gpiod_line_request_get_values_subset(struct gpiod_line_request *request,
- unsigned num_lines,
+ size_t num_lines,
const unsigned int *offsets,
int *values);
@@ -1216,7 +1216,7 @@ int gpiod_line_request_set_value(struct gpiod_line_request *request,
* @return 0 on success, -1 on failure.
*/
int gpiod_line_request_set_values_subset(struct gpiod_line_request *request,
- unsigned int num_lines,
+ size_t num_lines,
const unsigned int *offsets,
const int *values);
@@ -1272,7 +1272,7 @@ int gpiod_line_request_edge_event_wait(struct gpiod_line_request *request,
*/
int gpiod_line_request_edge_event_read(struct gpiod_line_request *request,
struct gpiod_edge_event_buffer *buffer,
- unsigned int max_events);
+ size_t max_events);
/**
* @}
@@ -1361,7 +1361,7 @@ unsigned long gpiod_edge_event_get_line_seqno(struct gpiod_edge_event *event);
* capacity is larger than 1024, it will be limited to 1024.
*/
struct gpiod_edge_event_buffer *
-gpiod_edge_event_buffer_new(unsigned int capacity);
+gpiod_edge_event_buffer_new(size_t capacity);
/**
* @brief Get the capacity (the max number of events that can be stored) of
@@ -1369,7 +1369,7 @@ gpiod_edge_event_buffer_new(unsigned int capacity);
* @param buffer Edge event buffer.
* @return The capacity of the buffer.
*/
-unsigned int
+size_t
gpiod_edge_event_buffer_get_capacity(struct gpiod_edge_event_buffer *buffer);
/**
@@ -1395,7 +1395,7 @@ gpiod_edge_event_buffer_get_event(struct gpiod_edge_event_buffer *buffer,
* @param buffer Edge event buffer.
* @return Number of events stored in this buffer.
*/
-unsigned int
+size_t
gpiod_edge_event_buffer_get_num_events(struct gpiod_edge_event_buffer *buffer);
/**
@@ -15,7 +15,7 @@
struct gpiod_chip {
int fd;
- unsigned int num_lines;
+ size_t num_lines;
char name[32];
char label[32];
char *path;
@@ -105,7 +105,7 @@ GPIOD_API const char *gpiod_chip_get_path(struct gpiod_chip *chip)
return chip->path;
}
-GPIOD_API unsigned int gpiod_chip_get_num_lines(struct gpiod_chip *chip)
+GPIOD_API size_t gpiod_chip_get_num_lines(struct gpiod_chip *chip)
{
return chip->num_lines;
}
@@ -21,8 +21,8 @@ struct gpiod_edge_event {
};
struct gpiod_edge_event_buffer {
- unsigned int capacity;
- unsigned int num_events;
+ size_t capacity;
+ size_t num_events;
struct gpiod_edge_event *events;
struct gpio_v2_line_event *event_data;
};
@@ -79,7 +79,7 @@ gpiod_edge_event_get_line_seqno(struct gpiod_edge_event *event)
}
GPIOD_API struct gpiod_edge_event_buffer *
-gpiod_edge_event_buffer_new(unsigned int capacity)
+gpiod_edge_event_buffer_new(size_t capacity)
{
struct gpiod_edge_event_buffer *buf;
@@ -111,7 +111,7 @@ gpiod_edge_event_buffer_new(unsigned int capacity)
return buf;
}
-GPIOD_API unsigned int
+GPIOD_API size_t
gpiod_edge_event_buffer_get_capacity(struct gpiod_edge_event_buffer *buffer)
{
return buffer->capacity;
@@ -140,7 +140,7 @@ gpiod_edge_event_buffer_get_event(struct gpiod_edge_event_buffer *buffer,
return &buffer->events[index];
}
-GPIOD_API unsigned int
+GPIOD_API size_t
gpiod_edge_event_buffer_get_num_events(struct gpiod_edge_event_buffer *buffer)
{
return buffer->num_events;
@@ -148,7 +148,7 @@ gpiod_edge_event_buffer_get_num_events(struct gpiod_edge_event_buffer *buffer)
int gpiod_edge_event_buffer_read_fd(int fd,
struct gpiod_edge_event_buffer *buffer,
- unsigned int max_events)
+ size_t max_events)
{
struct gpio_v2_line_event *curr;
struct gpiod_edge_event *event;
@@ -29,7 +29,7 @@ int gpiod_line_config_to_kernel(struct gpiod_line_config *config,
struct gpiod_line_request *
gpiod_line_request_from_kernel(struct gpio_v2_line_request *reqbuf);
int gpiod_edge_event_buffer_read_fd(int fd, struct gpiod_edge_event_buffer *buffer,
- unsigned int max_events);
+ size_t max_events);
struct gpiod_info_event *
gpiod_info_event_from_kernel(struct gpio_v2_line_info_changed *evbuf);
struct gpiod_info_event *gpiod_info_event_read_fd(int fd);
@@ -671,7 +671,7 @@ gpiod_line_config_set_output_value_override(struct gpiod_line_config *config,
GPIOD_API void
gpiod_line_config_set_output_values(struct gpiod_line_config *config,
- unsigned int num_values,
+ size_t num_values,
const unsigned int *offsets,
const int *values)
{
@@ -746,7 +746,7 @@ static bool base_debounce_period_is_equal(struct base_config *base,
return true;
}
-GPIOD_API unsigned int
+GPIOD_API size_t
gpiod_line_config_get_num_overrides(struct gpiod_line_config *config)
{
struct override_config *override;
@@ -14,7 +14,7 @@
struct gpiod_line_request {
unsigned int offsets[GPIO_V2_LINES_MAX];
- unsigned int num_lines;
+ size_t num_lines;
int fd;
};
@@ -45,7 +45,7 @@ GPIOD_API void gpiod_line_request_release(struct gpiod_line_request *request)
free(request);
}
-GPIOD_API unsigned int
+GPIOD_API size_t
gpiod_line_request_get_num_lines(struct gpiod_line_request *request)
{
return request->num_lines;
@@ -87,7 +87,7 @@ static int offset_to_bit(struct gpiod_line_request *request,
GPIOD_API int
gpiod_line_request_get_values_subset(struct gpiod_line_request *request,
- unsigned num_lines,
+ size_t num_lines,
const unsigned int *offsets, int *values)
{
struct gpio_v2_line_values buf;
@@ -140,7 +140,7 @@ GPIOD_API int gpiod_line_request_set_value(struct gpiod_line_request *request,
GPIOD_API int
gpiod_line_request_set_values_subset(struct gpiod_line_request *request,
- unsigned int num_lines,
+ size_t num_lines,
const unsigned int *offsets,
const int *values)
{
@@ -210,7 +210,7 @@ gpiod_line_request_edge_event_wait(struct gpiod_line_request *request,
GPIOD_API int
gpiod_line_request_edge_event_read(struct gpiod_line_request *request,
struct gpiod_edge_event_buffer *buffer,
- unsigned int max_events)
+ size_t max_events)
{
return gpiod_edge_event_buffer_read_fd(request->fd, buffer, max_events);
}
@@ -13,8 +13,8 @@
struct gpiod_request_config {
char consumer[GPIO_MAX_NAME_SIZE];
unsigned int offsets[GPIO_V2_LINES_MAX];
- unsigned int num_offsets;
- unsigned int event_buffer_size;
+ size_t num_offsets;
+ size_t event_buffer_size;
};
GPIOD_API struct gpiod_request_config *gpiod_request_config_new(void)
@@ -54,7 +54,7 @@ gpiod_request_config_get_consumer(struct gpiod_request_config *config)
GPIOD_API void
gpiod_request_config_set_offsets(struct gpiod_request_config *config,
- unsigned int num_offsets,
+ size_t num_offsets,
const unsigned int *offsets)
{
unsigned int i;
@@ -66,7 +66,7 @@ gpiod_request_config_set_offsets(struct gpiod_request_config *config,
config->offsets[i] = offsets[i];
}
-GPIOD_API unsigned int
+GPIOD_API size_t
gpiod_request_config_get_num_offsets(struct gpiod_request_config *config)
{
return config->num_offsets;
@@ -82,12 +82,12 @@ gpiod_request_config_get_offsets(struct gpiod_request_config *config,
GPIOD_API void
gpiod_request_config_set_event_buffer_size(struct gpiod_request_config *config,
- unsigned int event_buffer_size)
+ size_t event_buffer_size)
{
config->event_buffer_size = event_buffer_size;
}
-GPIOD_API unsigned int
+GPIOD_API size_t
gpiod_request_config_get_event_buffer_size(struct gpiod_request_config *config)
{
return config->event_buffer_size;
@@ -70,7 +70,7 @@ int main(int argc, char **argv)
if (!chip)
die_perror("unable to open %s", entries[i]->d_name);
- printf("%s [%s] (%u lines)\n",
+ printf("%s [%s] (%zu lines)\n",
gpiod_chip_get_name(chip),
gpiod_chip_get_label(chip),
gpiod_chip_get_num_lines(chip));
@@ -44,12 +44,13 @@ int main(int argc, char **argv)
int direction = GPIOD_LINE_DIRECTION_INPUT;
int optc, opti, bias = 0, ret, *values;
struct gpiod_request_config *req_cfg;
- unsigned int *offsets, i, num_lines;
struct gpiod_line_request *request;
struct gpiod_line_config *line_cfg;
+ unsigned int *offsets, i;
struct gpiod_chip *chip;
bool active_low = false;
char *device, *end;
+ size_t num_lines;
for (;;) {
optc = getopt_long(argc, argv, shortopts, longopts, &opti);
@@ -130,7 +130,7 @@ static void list_lines(struct gpiod_chip *chip)
unsigned int i, offset;
int direction;
- printf("%s - %u lines:\n",
+ printf("%s - %zu lines:\n",
gpiod_chip_get_name(chip), gpiod_chip_get_num_lines(chip));
for (offset = 0; offset < gpiod_chip_get_num_lines(chip); offset++) {
@@ -154,15 +154,15 @@ static void handle_signal(int signum UNUSED)
int main(int argc, char **argv)
{
- unsigned int offsets[64], num_lines = 0, offset, events_wanted = 0,
- events_done = 0;
bool watch_rising = false, watch_falling = false, active_low = false;
+ size_t num_lines = 0, events_wanted = 0, events_done = 0;
struct gpiod_edge_event_buffer *event_buffer;
int optc, opti, ret, i, edge, bias = 0;
uint64_t timeout = 10 * 1000000000LLU;
struct gpiod_request_config *req_cfg;
struct gpiod_line_request *request;
struct gpiod_line_config *line_cfg;
+ unsigned int offsets[64], offset;
struct gpiod_edge_event *event;
struct gpiod_chip *chip;
struct mon_ctx ctx;
@@ -192,13 +192,14 @@ int main(int argc, char **argv)
const struct mode_mapping *mode = &modes[MODE_EXIT];
int ret, optc, opti, bias = 0, drive = 0, *values;
struct gpiod_request_config *req_cfg;
- unsigned int *offsets, num_lines, i;
struct gpiod_line_request *request;
struct gpiod_line_config *line_cfg;
struct callback_data cbdata;
+ unsigned int *offsets, i;
struct gpiod_chip *chip;
bool active_low = false;
char *device, *end;
+ size_t num_lines;
memset(&cbdata, 0, sizeof(cbdata));
size_t is the unsigned integer type generally used whenever variables define sizes, ranges and numbers of elements. Use it throughout the C library wherever it makes sense. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> --- include/gpiod.h | 30 +++++++++++++++--------------- lib/chip.c | 4 ++-- lib/edge-event.c | 12 ++++++------ lib/internal.h | 2 +- lib/line-config.c | 4 ++-- lib/line-request.c | 10 +++++----- lib/request-config.c | 12 ++++++------ tools/gpiodetect.c | 2 +- tools/gpioget.c | 3 ++- tools/gpioinfo.c | 2 +- tools/gpiomon.c | 4 ++-- tools/gpioset.c | 3 ++- 12 files changed, 45 insertions(+), 43 deletions(-)