From: Bartosz Golaszewski Date: Fri, 19 Jan 2018 10:18:51 +0000 (+0100) Subject: all: fix various coding style issues X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=7222ec048ecfcb094924c7c1743bd6111e014a31;p=qemu-gpiodev%2Flibgpiod.git all: fix various coding style issues Make the entire code base more consistent with the linux kernel coding style. Signed-off-by: Bartosz Golaszewski --- diff --git a/include/gpiod.h b/include/gpiod.h index 151214b..62963db 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -316,7 +316,7 @@ int gpiod_simple_find_line(const char *name, char *chipname, * @param path Path to the gpiochip device file. * @return GPIO chip handle or NULL if an error occurred. */ -struct gpiod_chip * gpiod_chip_open(const char *path) GPIOD_API; +struct gpiod_chip *gpiod_chip_open(const char *path) GPIOD_API; /** * @brief Open a gpiochip by name. @@ -325,7 +325,7 @@ struct gpiod_chip * gpiod_chip_open(const char *path) GPIOD_API; * * This routine appends name to '/dev/' to create the path. */ -struct gpiod_chip * gpiod_chip_open_by_name(const char *name) GPIOD_API; +struct gpiod_chip *gpiod_chip_open_by_name(const char *name) GPIOD_API; /** * @brief Open a gpiochip by number. @@ -334,7 +334,7 @@ struct gpiod_chip * gpiod_chip_open_by_name(const char *name) GPIOD_API; * * This routine appends num to '/dev/gpiochip' to create the path. */ -struct gpiod_chip * gpiod_chip_open_by_number(unsigned int num) GPIOD_API; +struct gpiod_chip *gpiod_chip_open_by_number(unsigned int num) GPIOD_API; /** * @brief Open a gpiochip by label. @@ -344,7 +344,7 @@ struct gpiod_chip * gpiod_chip_open_by_number(unsigned int num) GPIOD_API; * @note If the chip cannot be found but no other error occurred, errno is set * to ENOENT. */ -struct gpiod_chip * gpiod_chip_open_by_label(const char *label) GPIOD_API; +struct gpiod_chip *gpiod_chip_open_by_label(const char *label) GPIOD_API; /** * @brief Open a gpiochip based on the best guess what the path is. @@ -355,7 +355,7 @@ struct gpiod_chip * gpiod_chip_open_by_label(const char *label) GPIOD_API; * GPIO chip, its name, label or number as a string. Then it tries to open it * using one of the gpiod_chip_open** variants. */ -struct gpiod_chip * gpiod_chip_open_lookup(const char *descr) GPIOD_API; +struct gpiod_chip *gpiod_chip_open_lookup(const char *descr) GPIOD_API; /** * @brief Close a GPIO chip handle and release all allocated resources. @@ -368,14 +368,14 @@ void gpiod_chip_close(struct gpiod_chip *chip) GPIOD_API; * @param chip The GPIO chip object. * @return Pointer to a human-readable string containing the chip name. */ -const char * gpiod_chip_name(struct gpiod_chip *chip) GPIOD_API; +const char *gpiod_chip_name(struct gpiod_chip *chip) GPIOD_API; /** * @brief Get the GPIO chip label as represented in the kernel. * @param chip The GPIO chip object. * @return Pointer to a human-readable string containing the chip label. */ -const char * gpiod_chip_label(struct gpiod_chip *chip) GPIOD_API; +const char *gpiod_chip_label(struct gpiod_chip *chip) GPIOD_API; /** * @brief Get the number of GPIO lines exposed by this chip. @@ -559,7 +559,7 @@ unsigned int gpiod_line_offset(struct gpiod_line *line) GPIOD_API; * routine returns a pointer to a null-terminated string or NULL if * the line is unnamed. */ -const char * gpiod_line_name(struct gpiod_line *line) GPIOD_API; +const char *gpiod_line_name(struct gpiod_line *line) GPIOD_API; /** * @brief Read the GPIO line consumer name. @@ -568,7 +568,7 @@ const char * gpiod_line_name(struct gpiod_line *line) GPIOD_API; * kernel. This routine returns a pointer to a null-terminated string * or NULL if the line is not used. */ -const char * gpiod_line_consumer(struct gpiod_line *line) GPIOD_API; +const char *gpiod_line_consumer(struct gpiod_line *line) GPIOD_API; /** * @brief Read the GPIO line direction setting. @@ -1122,7 +1122,7 @@ gpiod_line_get(const char *device, unsigned int offset) GPIOD_API; * this line to avoid memory leaks. If the line could not be found, this * functions sets errno to ENOENT. */ -struct gpiod_line * gpiod_line_find(const char *name) GPIOD_API; +struct gpiod_line *gpiod_line_find(const char *name) GPIOD_API; /** * @brief Close a GPIO chip owning this line and release all resources. @@ -1137,7 +1137,7 @@ void gpiod_line_close_chip(struct gpiod_line *line) GPIOD_API; * @param line The GPIO line object. * @return Pointer to the GPIO chip handle controlling this line. */ -struct gpiod_chip * gpiod_line_get_chip(struct gpiod_line *line) GPIOD_API; +struct gpiod_chip *gpiod_line_get_chip(struct gpiod_line *line) GPIOD_API; /** * @} @@ -1159,7 +1159,7 @@ struct gpiod_chip * gpiod_line_get_chip(struct gpiod_line *line) GPIOD_API; * files, opens them and stores their the handles until ::gpiod_chip_iter_free * or ::gpiod_chip_iter_free_noclose is called. */ -struct gpiod_chip_iter * gpiod_chip_iter_new(void) GPIOD_API; +struct gpiod_chip_iter *gpiod_chip_iter_new(void) GPIOD_API; /** * @brief Release all resources allocated for the gpiochip iterator and close @@ -1278,7 +1278,7 @@ gpiod_line_iter_next(struct gpiod_line_iter *iter) GPIOD_API; * @brief Get the version of the library as a human-readable string. * @return Human-readable string containing the library version. */ -const char * gpiod_version_string(void) GPIOD_API; +const char *gpiod_version_string(void) GPIOD_API; /** * @} diff --git a/src/lib/core.c b/src/lib/core.c index 087de62..d540890 100644 --- a/src/lib/core.c +++ b/src/lib/core.c @@ -58,7 +58,7 @@ struct gpiod_chip { char label[32]; }; -struct gpiod_chip * gpiod_chip_open(const char *path) +struct gpiod_chip *gpiod_chip_open(const char *path) { struct gpiochip_info info; struct gpiod_chip *chip; @@ -129,12 +129,12 @@ void gpiod_chip_close(struct gpiod_chip *chip) free(chip); } -const char * gpiod_chip_name(struct gpiod_chip *chip) +const char *gpiod_chip_name(struct gpiod_chip *chip) { return chip->name; } -const char * gpiod_chip_label(struct gpiod_chip *chip) +const char *gpiod_chip_label(struct gpiod_chip *chip) { return chip->label; } @@ -194,7 +194,7 @@ static void line_maybe_update(struct gpiod_line *line) line->up_to_date = false; } -struct gpiod_chip * gpiod_line_get_chip(struct gpiod_line *line) +struct gpiod_chip *gpiod_line_get_chip(struct gpiod_line *line) { return line->chip; } @@ -204,12 +204,12 @@ unsigned int gpiod_line_offset(struct gpiod_line *line) return line->offset; } -const char * gpiod_line_name(struct gpiod_line *line) +const char *gpiod_line_name(struct gpiod_line *line) { return line->name[0] == '\0' ? NULL : line->name; } -const char * gpiod_line_consumer(struct gpiod_line *line) +const char *gpiod_line_consumer(struct gpiod_line *line) { return line->consumer[0] == '\0' ? NULL : line->consumer; } @@ -488,11 +488,10 @@ int gpiod_line_request_bulk(struct gpiod_line_bulk *bulk, if (!line_bulk_same_chip(bulk) || !line_bulk_all_free(bulk)) return -1; - if (line_request_is_direction(config->request_type)) { + if (line_request_is_direction(config->request_type)) return line_request_values(bulk, config, default_vals); - } else if (line_request_is_events(config->request_type)) { + else if (line_request_is_events(config->request_type)) return line_request_events(bulk, config); - } errno = EINVAL; return -1; diff --git a/src/lib/helpers.c b/src/lib/helpers.c index a7f1387..94643fa 100644 --- a/src/lib/helpers.c +++ b/src/lib/helpers.c @@ -24,12 +24,13 @@ static bool isuint(const char *str) { - for (; *str && isdigit(*str); str++); + for (; *str && isdigit(*str); str++) + ; return *str == '\0'; } -struct gpiod_chip * gpiod_chip_open_by_name(const char *name) +struct gpiod_chip *gpiod_chip_open_by_name(const char *name) { struct gpiod_chip *chip; char *path; @@ -45,7 +46,7 @@ struct gpiod_chip * gpiod_chip_open_by_name(const char *name) return chip; } -struct gpiod_chip * gpiod_chip_open_by_number(unsigned int num) +struct gpiod_chip *gpiod_chip_open_by_number(unsigned int num) { struct gpiod_chip *chip; char *path; @@ -61,7 +62,7 @@ struct gpiod_chip * gpiod_chip_open_by_number(unsigned int num) return chip; } -struct gpiod_chip * gpiod_chip_open_by_label(const char *label) +struct gpiod_chip *gpiod_chip_open_by_label(const char *label) { struct gpiod_chip_iter *iter; struct gpiod_chip *chip; @@ -83,7 +84,7 @@ struct gpiod_chip * gpiod_chip_open_by_label(const char *label) return NULL; } -struct gpiod_chip * gpiod_chip_open_lookup(const char *descr) +struct gpiod_chip *gpiod_chip_open_lookup(const char *descr) { struct gpiod_chip *chip; @@ -335,7 +336,7 @@ int gpiod_line_request_bulk_both_edges_events_flags( GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES); } -struct gpiod_line * gpiod_line_get(const char *device, unsigned int offset) +struct gpiod_line *gpiod_line_get(const char *device, unsigned int offset) { struct gpiod_chip *chip; struct gpiod_line *line; @@ -353,7 +354,7 @@ struct gpiod_line * gpiod_line_get(const char *device, unsigned int offset) return line; } -struct gpiod_line * gpiod_line_find(const char *name) +struct gpiod_line *gpiod_line_find(const char *name) { struct gpiod_chip_iter *iter; struct gpiod_chip *chip; diff --git a/src/lib/iter.c b/src/lib/iter.c index 2a80dca..3bb2210 100644 --- a/src/lib/iter.c +++ b/src/lib/iter.c @@ -42,7 +42,7 @@ static void free_dirs(struct dirent ***dirs, unsigned int num_dirs) free(*dirs); } -struct gpiod_chip_iter * gpiod_chip_iter_new(void) +struct gpiod_chip_iter *gpiod_chip_iter_new(void) { struct gpiod_chip_iter *iter; struct dirent **dirs; @@ -117,7 +117,7 @@ void gpiod_chip_iter_free_noclose(struct gpiod_chip_iter *iter) free(iter); } -struct gpiod_chip * gpiod_chip_iter_next(struct gpiod_chip_iter *iter) +struct gpiod_chip *gpiod_chip_iter_next(struct gpiod_chip_iter *iter) { if (iter->offset > 0) { gpiod_chip_close(iter->chips[iter->offset - 1]); @@ -127,13 +127,13 @@ struct gpiod_chip * gpiod_chip_iter_next(struct gpiod_chip_iter *iter) return gpiod_chip_iter_next_noclose(iter); } -struct gpiod_chip * gpiod_chip_iter_next_noclose(struct gpiod_chip_iter *iter) +struct gpiod_chip *gpiod_chip_iter_next_noclose(struct gpiod_chip_iter *iter) { return iter->offset < (iter->num_chips) ? iter->chips[iter->offset++] : NULL; } -struct gpiod_line_iter * gpiod_line_iter_new(struct gpiod_chip *chip) +struct gpiod_line_iter *gpiod_line_iter_new(struct gpiod_chip *chip) { struct gpiod_line_iter *iter; unsigned int i; @@ -169,7 +169,7 @@ void gpiod_line_iter_free(struct gpiod_line_iter *iter) free(iter); } -struct gpiod_line * gpiod_line_iter_next(struct gpiod_line_iter *iter) +struct gpiod_line *gpiod_line_iter_next(struct gpiod_line_iter *iter) { return iter->offset < (iter->num_lines) ? iter->lines[iter->offset++] : NULL; diff --git a/src/lib/misc.c b/src/lib/misc.c index fe79c04..732d744 100644 --- a/src/lib/misc.c +++ b/src/lib/misc.c @@ -13,7 +13,7 @@ #include -const char * gpiod_version_string(void) +const char *gpiod_version_string(void) { return GPIOD_VERSION_STR; } diff --git a/src/tools/gpioinfo.c b/src/tools/gpioinfo.c index dcaa95b..68ae91f 100644 --- a/src/tools/gpioinfo.c +++ b/src/tools/gpioinfo.c @@ -18,9 +18,11 @@ #include #include +typedef bool (*is_set_func)(struct gpiod_line *); + struct flag { const char *name; - bool (*is_set)(struct gpiod_line *); + is_set_func is_set; }; static const struct flag flags[] = { diff --git a/src/tools/gpioset.c b/src/tools/gpioset.c index 18c8fd7..f1ce074 100644 --- a/src/tools/gpioset.c +++ b/src/tools/gpioset.c @@ -164,7 +164,7 @@ static const struct mode_mapping modes[] = { }, }; -static const struct mode_mapping * parse_mode(const char *mode) +static const struct mode_mapping *parse_mode(const char *mode) { unsigned int i; diff --git a/tests/gpiod-test.c b/tests/gpiod-test.c index 31474fa..9e1b129 100644 --- a/tests/gpiod-test.c +++ b/tests/gpiod-test.c @@ -100,7 +100,7 @@ enum { CYELLOW, }; -static const char *term_colors[] = { +static const char *const term_colors[] = { "\033[0m", "\033[32m", "\033[31m", @@ -214,7 +214,7 @@ static TEST_PRINTF(1, 2) NORETURN void die_perr(const char *fmt, ...) exit(EXIT_FAILURE); } -static MALLOC void * xmalloc(size_t size) +static MALLOC void *xmalloc(size_t size) { void *ptr; @@ -225,7 +225,7 @@ static MALLOC void * xmalloc(size_t size) return ptr; } -static MALLOC void * xzalloc(size_t size) +static MALLOC void *xzalloc(size_t size) { void *ptr; @@ -235,7 +235,7 @@ static MALLOC void * xzalloc(size_t size) return ptr; } -static MALLOC void * xcalloc(size_t nmemb, size_t size) +static MALLOC void *xcalloc(size_t nmemb, size_t size) { void *ptr; @@ -246,7 +246,7 @@ static MALLOC void * xcalloc(size_t nmemb, size_t size) return ptr; } -static MALLOC char * xstrdup(const char *str) +static MALLOC char *xstrdup(const char *str) { char *ret; @@ -257,7 +257,7 @@ static MALLOC char * xstrdup(const char *str) return ret; } -static TEST_PRINTF(2, 3) char * xappend(char *str, const char *fmt, ...) +static TEST_PRINTF(2, 3) char *xappend(char *str, const char *fmt, ...) { char *new, *ret; va_list va; @@ -356,7 +356,7 @@ static void event_unlock(void) pthread_mutex_unlock(&globals.test_ctx.event.lock); } -static void * event_worker(void *data TEST_UNUSED) +static void *event_worker(void *data TEST_UNUSED) { struct event_thread *ev = &globals.test_ctx.event; struct timeval tv_now, tv_add, tv_res; @@ -451,7 +451,7 @@ static void gpiotool_proc_dup_fds(int in_fd, int out_fd, int err_fd) } } -static char * gpiotool_proc_get_path(const char *tool) +static char *gpiotool_proc_get_path(const char *tool) { char *path, *progpath, *progdir; @@ -471,7 +471,8 @@ static NORETURN void gpiotool_proc_exec(const char *path, va_list va) va_list va2; va_copy(va2, va); - for (num_args = 2; va_arg(va2, char *) != NULL; num_args++); + for (num_args = 2; va_arg(va2, char *) != NULL; num_args++) + ; va_end(va2); argv = xcalloc(num_args, sizeof(char *)); @@ -663,14 +664,14 @@ void test_tool_wait(void) proc->running = false; } -const char * test_tool_stdout(void) +const char *test_tool_stdout(void) { struct gpiotool_proc *proc = &globals.test_ctx.tool_proc; return proc->stdout; } -const char * test_tool_stderr(void) +const char *test_tool_stderr(void) { struct gpiotool_proc *proc = &globals.test_ctx.tool_proc; @@ -1056,14 +1057,14 @@ void test_free_chip_iter_noclose(struct gpiod_chip_iter **iter) gpiod_chip_iter_free_noclose(*iter); } -const char * test_chip_path(unsigned int index) +const char *test_chip_path(unsigned int index) { check_chip_index(index); return globals.test_ctx.chips[index]->path; } -const char * test_chip_name(unsigned int index) +const char *test_chip_name(unsigned int index) { check_chip_index(index); diff --git a/tests/gpiod-test.h b/tests/gpiod-test.h index 5b8a83b..3ff4259 100644 --- a/tests/gpiod-test.h +++ b/tests/gpiod-test.h @@ -93,8 +93,8 @@ enum { * or number by index corresponding with the order in which the mockup chips * were requested in the TEST_DEFINE() macro. */ -const char * test_chip_path(unsigned int index); -const char * test_chip_name(unsigned int index); +const char *test_chip_path(unsigned int index); +const char *test_chip_name(unsigned int index); unsigned int test_chip_num(unsigned int index); enum { @@ -108,8 +108,8 @@ void test_set_event(unsigned int chip_index, unsigned int line_offset, void test_tool_run(char *tool, ...); void test_tool_wait(void); -const char * test_tool_stdout(void); -const char * test_tool_stderr(void); +const char *test_tool_stdout(void); +const char *test_tool_stderr(void); bool test_tool_exited(void); int test_tool_exit_status(void); void test_tool_signal(int signum);