core: don't expose designated initializers in the library header
authorBartosz Golaszewski <bartekgola@gmail.com>
Wed, 1 Mar 2017 16:51:26 +0000 (17:51 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Wed, 1 Mar 2017 16:51:26 +0000 (17:51 +0100)
We don't know who might want to include gpiod.h, so let's try to avoid
any C99 extensions in the header.

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

index 01c03e5f10cd1d99b63aaa18e5ff91659d247c72..4adf4c231f0b6812234fa74d501cd3fecf5a7ac5 100644 (file)
@@ -317,7 +317,7 @@ struct gpiod_line_bulk {
  *
  * This macro simply sets the internally held number of lines to 0.
  */
-#define GPIOD_LINE_BULK_INITIALIZER    { .num_lines = 0, }
+#define GPIOD_LINE_BULK_INITIALIZER    { { NULL }, 0 }
 
 /**
  * @brief Initialize a GPIO bulk object.
@@ -465,19 +465,9 @@ int gpiod_line_request(struct gpiod_line *line,
  * @param active_low Active state of the line (true if low).
  * @return 0 if the line was properly reserved, -1 on failure.
  */
-static inline int gpiod_line_request_input(struct gpiod_line *line,
-                                          const char *consumer,
-                                          bool active_low)
-{
-       struct gpiod_line_request_config config = {
-               .consumer = consumer,
-               .direction = GPIOD_DIRECTION_INPUT,
-               .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW
-                                          : GPIOD_ACTIVE_STATE_HIGH,
-       };
-
-       return gpiod_line_request(line, &config, 0);
-}
+int gpiod_line_request_input(struct gpiod_line *line,
+                            const char *consumer,
+                            bool active_low) GPIOD_API;
 
 /**
  * @brief Reserve a single line, set the direction to output.
@@ -487,19 +477,8 @@ static inline int gpiod_line_request_input(struct gpiod_line *line,
  * @param default_val Default line value.
  * @return 0 if the line was properly reserved, -1 on failure.
  */
-static inline int gpiod_line_request_output(struct gpiod_line *line,
-                                           const char *consumer,
-                                           bool active_low, int default_val)
-{
-       struct gpiod_line_request_config config = {
-               .consumer = consumer,
-               .direction = GPIOD_DIRECTION_OUTPUT,
-               .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW
-                                          : GPIOD_ACTIVE_STATE_HIGH,
-       };
-
-       return gpiod_line_request(line, &config, default_val);
-}
+int gpiod_line_request_output(struct gpiod_line *line, const char *consumer,
+                             bool active_low, int default_val) GPIOD_API;
 
 /**
  * @brief Reserve a set of GPIO lines.
@@ -525,19 +504,9 @@ int gpiod_line_request_bulk(struct gpiod_line_bulk *bulk,
  * @param active_low Active state of the lines (true if low).
  * @return 0 if the lines were properly reserved, -1 on failure.
  */
-static inline int gpiod_line_request_bulk_input(struct gpiod_line_bulk *bulk,
-                                               const char *consumer,
-                                               bool active_low)
-{
-       struct gpiod_line_request_config config = {
-               .consumer = consumer,
-               .direction = GPIOD_DIRECTION_INPUT,
-               .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW
-                                          : GPIOD_ACTIVE_STATE_HIGH,
-       };
-
-       return gpiod_line_request_bulk(bulk, &config, 0);
-}
+int gpiod_line_request_bulk_input(struct gpiod_line_bulk *bulk,
+                                 const char *consumer,
+                                 bool active_low) GPIOD_API;
 
 /**
  * @brief Reserve a set of GPIO lines, set the direction to output.
@@ -547,20 +516,9 @@ static inline int gpiod_line_request_bulk_input(struct gpiod_line_bulk *bulk,
  * @param default_vals Default line values.
  * @return 0 if the lines were properly reserved, -1 on failure.
  */
-static inline int gpiod_line_request_bulk_output(struct gpiod_line_bulk *bulk,
-                                                const char *consumer,
-                                                bool active_low,
-                                                const int *default_vals)
-{
-       struct gpiod_line_request_config config = {
-               .consumer = consumer,
-               .direction = GPIOD_DIRECTION_OUTPUT,
-               .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW
-                                          : GPIOD_ACTIVE_STATE_HIGH,
-       };
-
-       return gpiod_line_request_bulk(bulk, &config, default_vals);
-}
+int gpiod_line_request_bulk_output(struct gpiod_line_bulk *bulk,
+                                  const char *consumer, bool active_low,
+                                  const int *default_vals) GPIOD_API;
 
 /**
  * @brief Release a previously reserved line.
@@ -708,20 +666,9 @@ int gpiod_line_event_request(struct gpiod_line *line,
                             struct gpiod_line_evreq_config *config) GPIOD_API;
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
-static inline int _gpiod_line_event_request_type(struct gpiod_line *line,
-                                                const char *consumer,
-                                                bool active_low,
-                                                int type)
-{
-       struct gpiod_line_evreq_config config = {
-               .consumer = consumer,
-               .event_type = type,
-               .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW
-                                          : GPIOD_ACTIVE_STATE_HIGH,
-       };
-
-       return gpiod_line_event_request(line, &config);
-}
+int _gpiod_line_event_request_type(struct gpiod_line *line,
+                                  const char *consumer, bool active_low,
+                                  int type) GPIOD_API;
 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
 /**
@@ -1080,12 +1027,7 @@ struct gpiod_line_iter {
  * @brief Static initializer for line iterators.
  * @param chip The gpiochip object whose lines we want to iterate over.
  */
-#define GPIOD_LINE_ITER_INITIALIZER(chip)                              \
-       {                                                               \
-               .offset = 0,                                            \
-               .chip = (chip),                                         \
-               .state = GPIOD_LINE_ITER_INIT,                          \
-       }
+#define GPIOD_LINE_ITER_INITIALIZER(chip) { 0, (chip), GPIOD_LINE_ITER_INIT }
 
 /**
  * @brief Initialize a GPIO line iterator.
index 2d313bc167480956f3e962a4a11e0ce299904586..d7f1547debe712bb4a6ff6e13e279e231159735c 100644 (file)
@@ -499,6 +499,32 @@ int gpiod_line_request(struct gpiod_line *line,
        return gpiod_line_request_bulk(&bulk, config, &default_val);
 }
 
+int gpiod_line_request_input(struct gpiod_line *line,
+                            const char *consumer, bool active_low)
+{
+       struct gpiod_line_request_config config = {
+               .consumer = consumer,
+               .direction = GPIOD_DIRECTION_INPUT,
+               .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW
+                                          : GPIOD_ACTIVE_STATE_HIGH,
+       };
+
+       return gpiod_line_request(line, &config, 0);
+}
+
+int gpiod_line_request_output(struct gpiod_line *line, const char *consumer,
+                             bool active_low, int default_val)
+{
+       struct gpiod_line_request_config config = {
+               .consumer = consumer,
+               .direction = GPIOD_DIRECTION_OUTPUT,
+               .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW
+                                          : GPIOD_ACTIVE_STATE_HIGH,
+       };
+
+       return gpiod_line_request(line, &config, default_val);
+}
+
 static bool verify_line_bulk(struct gpiod_line_bulk *bulk)
 {
        struct gpiod_line *line;
@@ -586,6 +612,33 @@ int gpiod_line_request_bulk(struct gpiod_line_bulk *bulk,
        return 0;
 }
 
+int gpiod_line_request_bulk_input(struct gpiod_line_bulk *bulk,
+                                 const char *consumer, bool active_low)
+{
+       struct gpiod_line_request_config config = {
+               .consumer = consumer,
+               .direction = GPIOD_DIRECTION_INPUT,
+               .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW
+                                          : GPIOD_ACTIVE_STATE_HIGH,
+       };
+
+       return gpiod_line_request_bulk(bulk, &config, 0);
+}
+
+int gpiod_line_request_bulk_output(struct gpiod_line_bulk *bulk,
+                                  const char *consumer, bool active_low,
+                                  const int *default_vals)
+{
+       struct gpiod_line_request_config config = {
+               .consumer = consumer,
+               .direction = GPIOD_DIRECTION_OUTPUT,
+               .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW
+                                          : GPIOD_ACTIVE_STATE_HIGH,
+       };
+
+       return gpiod_line_request_bulk(bulk, &config, default_vals);
+}
+
 void gpiod_line_release(struct gpiod_line *line)
 {
        struct gpiod_line_bulk bulk;
@@ -785,6 +838,20 @@ int gpiod_line_event_request(struct gpiod_line *line,
        return 0;
 }
 
+int _gpiod_line_event_request_type(struct gpiod_line *line,
+                                  const char *consumer, bool active_low,
+                                  int type)
+{
+       struct gpiod_line_evreq_config config = {
+               .consumer = consumer,
+               .event_type = type,
+               .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW
+                                          : GPIOD_ACTIVE_STATE_HIGH,
+       };
+
+       return gpiod_line_event_request(line, &config);
+}
+
 void gpiod_line_event_release(struct gpiod_line *line)
 {
        close(line_get_event_fd(line));