all: fix various coding style issues
authorBartosz Golaszewski <bartekgola@gmail.com>
Fri, 19 Jan 2018 10:18:51 +0000 (11:18 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Fri, 19 Jan 2018 10:40:37 +0000 (11:40 +0100)
Make the entire code base more consistent with the linux kernel
coding style.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
include/gpiod.h
src/lib/core.c
src/lib/helpers.c
src/lib/iter.c
src/lib/misc.c
src/tools/gpioinfo.c
src/tools/gpioset.c
tests/gpiod-test.c
tests/gpiod-test.h

index 151214b7303176a078803b1e199b23ad50fb4b0f..62963dbb77f9321de01563a4abab121b931f191e 100644 (file)
@@ -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;
 
 /**
  * @}
index 087de62513fa4cc861828c8ec23178394881a6d4..d540890bfe664e2efb1124e8f1a75fa3572ea40f 100644 (file)
@@ -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;
index a7f1387b844d86a0e37a8f9df9d05e099374dcae..94643faa374c686d7d7b789d3346bec42ef9e390 100644 (file)
 
 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;
index 2a80dca11ec6753d9c4be21bfe942d1818508694..3bb22103f7c7a54f4e72c73d0d6aa71c88ab930a 100644 (file)
@@ -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;
index fe79c04b9a99e751bbe0c369a46bc9eef436bcd9..732d744e54d86c2252ba38901c44dd74c0e4d872 100644 (file)
@@ -13,7 +13,7 @@
 
 #include <gpiod.h>
 
-const char * gpiod_version_string(void)
+const char *gpiod_version_string(void)
 {
        return GPIOD_VERSION_STR;
 }
index dcaa95ba8ea1200b7fb32df4dc63f2cb796d8453..68ae91f28353b771dc0cd5ee8009ebcf1ad2a9ff 100644 (file)
 #include <getopt.h>
 #include <errno.h>
 
+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[] = {
index 18c8fd79b2b29b5ce1a9fd46e732fdab267c52aa..f1ce07477183a08c8641764959485bf40b325eab 100644 (file)
@@ -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;
 
index 31474fa978346d26e758eded7360bc04890d2469..9e1b12946c52ad991bbd298a36ab51a316677405 100644 (file)
@@ -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);
 
index 5b8a83be1ba7e4e9a3f0fa613b1b60730d5678d8..3ff42599ee152199ba7c1895c8e3d24499ca87c1 100644 (file)
@@ -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);