libusbgx: Extract internal header file
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Wed, 29 Oct 2014 14:26:12 +0000 (15:26 +0100)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 22 Dec 2015 20:41:57 +0000 (21:41 +0100)
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
include/usbg/usbg_internal.h [new file with mode: 0644]
src/usbg.c

diff --git a/include/usbg/usbg_internal.h b/include/usbg/usbg_internal.h
new file mode 100644 (file)
index 0000000..4c0f449
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#include <sys/queue.h>
+#include <string.h>
+#include <usbg/usbg.h>
+#include <libconfig.h>
+
+struct usbg_state
+{
+       char *path;
+
+       TAILQ_HEAD(ghead, usbg_gadget) gadgets;
+       TAILQ_HEAD(uhead, usbg_udc) udcs;
+       config_t *last_failed_import;
+};
+
+struct usbg_gadget
+{
+       char *name;
+       char *path;
+
+       TAILQ_ENTRY(usbg_gadget) gnode;
+       TAILQ_HEAD(chead, usbg_config) configs;
+       TAILQ_HEAD(fhead, usbg_function) functions;
+       usbg_state *parent;
+       config_t *last_failed_import;
+       usbg_udc *udc;
+};
+
+struct usbg_config
+{
+       TAILQ_ENTRY(usbg_config) cnode;
+       TAILQ_HEAD(bhead, usbg_binding) bindings;
+       usbg_gadget *parent;
+
+       char *name;
+       char *path;
+       char *label;
+       int id;
+};
+
+struct usbg_function
+{
+       TAILQ_ENTRY(usbg_function) fnode;
+       usbg_gadget *parent;
+
+       char *name;
+       char *path;
+       char *instance;
+       /* Only for internal library usage */
+       char *label;
+       usbg_function_type type;
+};
+
+struct usbg_binding
+{
+       TAILQ_ENTRY(usbg_binding) bnode;
+       usbg_config *parent;
+       usbg_function *target;
+
+       char *name;
+       char *path;
+};
+
+struct usbg_udc
+{
+       TAILQ_ENTRY(usbg_udc) unode;
+       usbg_state *parent;
+       usbg_gadget *gadget;
+
+       char *name;
+};
+
+#define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
+
+#define ARRAY_SIZE_SENTINEL(array, size)                               \
+       static void __attribute__ ((unused)) array##_size_sentinel()                            \
+       {                                                               \
+               char array##_smaller_than_expected[                     \
+                       (int)(ARRAY_SIZE(array) - size)]                \
+                       __attribute__ ((unused));                       \
+                                                                       \
+               char array##_larger_than_expected[                      \
+                       (int)(size - ARRAY_SIZE(array))]                \
+                       __attribute__ ((unused));                       \
+       }
+
+#define ERROR(msg, ...) do {\
+                        fprintf(stderr, "%s()  "msg" \n", \
+                                __func__, ##__VA_ARGS__);\
+                        fflush(stderr);\
+                    } while (0)
+
+#define ERRORNO(msg, ...) do {\
+                        fprintf(stderr, "%s()  %s: "msg" \n", \
+                                __func__, strerror(errno), ##__VA_ARGS__);\
+                        fflush(stderr);\
+                    } while (0)
+
+/* Insert in string order */
+#define INSERT_TAILQ_STRING_ORDER(HeadPtr, HeadType, NameField, ToInsert, NodeField) \
+       do { \
+               if (TAILQ_EMPTY((HeadPtr)) || \
+                       (strcmp((ToInsert)->NameField, TAILQ_FIRST((HeadPtr))->NameField) < 0)) \
+                       TAILQ_INSERT_HEAD((HeadPtr), (ToInsert), NodeField); \
+               else if (strcmp((ToInsert)->NameField, TAILQ_LAST((HeadPtr), HeadType)->NameField) > 0) \
+                       TAILQ_INSERT_TAIL((HeadPtr), (ToInsert), NodeField); \
+               else { \
+                       typeof(ToInsert) _cur; \
+                       TAILQ_FOREACH(_cur, (HeadPtr), NodeField) { \
+                               if (strcmp((ToInsert)->NameField, _cur->NameField) > 0) \
+                                       continue; \
+                               TAILQ_INSERT_BEFORE(_cur, (ToInsert), NodeField); \
+                       } \
+               } \
+       } while (0)
+
+#define STRINGS_DIR "strings"
+#define CONFIGS_DIR "configs"
+#define FUNCTIONS_DIR "functions"
index 978d359..0293f23 100644 (file)
@@ -16,7 +16,7 @@
 
 #include <dirent.h>
 #include <errno.h>
-#include <usbg/usbg.h>
+
 #include <netinet/ether.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <libconfig.h>
 
-#define STRINGS_DIR "strings"
-#define CONFIGS_DIR "configs"
-#define FUNCTIONS_DIR "functions"
+#include "usbg/usbg_internal.h"
 
 /**
  * @file usbg.c
- * @todo Handle buffer overflows
  */
 
-struct usbg_state
-{
-       char *path;
-
-       TAILQ_HEAD(ghead, usbg_gadget) gadgets;
-       TAILQ_HEAD(uhead, usbg_udc) udcs;
-       config_t *last_failed_import;
-};
-
-struct usbg_gadget
-{
-       char *name;
-       char *path;
-
-       TAILQ_ENTRY(usbg_gadget) gnode;
-       TAILQ_HEAD(chead, usbg_config) configs;
-       TAILQ_HEAD(fhead, usbg_function) functions;
-       usbg_state *parent;
-       config_t *last_failed_import;
-       usbg_udc *udc;
-};
-
-struct usbg_config
-{
-       TAILQ_ENTRY(usbg_config) cnode;
-       TAILQ_HEAD(bhead, usbg_binding) bindings;
-       usbg_gadget *parent;
-
-       char *name;
-       char *path;
-       char *label;
-       int id;
-};
-
-struct usbg_function
-{
-       TAILQ_ENTRY(usbg_function) fnode;
-       usbg_gadget *parent;
-
-       char *name;
-       char *path;
-       char *instance;
-       /* Only for internal library usage */
-       char *label;
-       usbg_function_type type;
-};
-
-struct usbg_binding
-{
-       TAILQ_ENTRY(usbg_binding) bnode;
-       usbg_config *parent;
-       usbg_function *target;
-
-       char *name;
-       char *path;
-};
-
-struct usbg_udc
-{
-       TAILQ_ENTRY(usbg_udc) unode;
-       usbg_state *parent;
-       usbg_gadget *gadget;
-
-       char *name;
-};
-#define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
-
-#define ARRAY_SIZE_SENTINEL(array, size)                               \
-       static void __attribute__ ((unused)) array##_size_sentinel()    \
-       {                                                               \
-               char array##_smaller_than_expected[                     \
-                       (int)(ARRAY_SIZE(array) - size)]                \
-                       __attribute__ ((unused));                       \
-                                                                       \
-               char array##_larger_than_expected[                      \
-                       (int)(size - ARRAY_SIZE(array))]                \
-                       __attribute__ ((unused));                       \
-       }
 
 /**
  * @var function_names
@@ -150,36 +69,6 @@ const char *gadget_attr_names[] =
 
 ARRAY_SIZE_SENTINEL(gadget_attr_names, USBG_GADGET_ATTR_MAX);
 
-#define ERROR(msg, ...) do {\
-                        fprintf(stderr, "%s()  "msg" \n", \
-                                __func__, ##__VA_ARGS__);\
-                        fflush(stderr);\
-                    } while (0)
-
-#define ERRORNO(msg, ...) do {\
-                        fprintf(stderr, "%s()  %s: "msg" \n", \
-                                __func__, strerror(errno), ##__VA_ARGS__);\
-                        fflush(stderr);\
-                    } while (0)
-
-/* Insert in string order */
-#define INSERT_TAILQ_STRING_ORDER(HeadPtr, HeadType, NameField, ToInsert, NodeField) \
-       do { \
-               if (TAILQ_EMPTY((HeadPtr)) || \
-                       (strcmp((ToInsert)->NameField, TAILQ_FIRST((HeadPtr))->NameField) < 0)) \
-                       TAILQ_INSERT_HEAD((HeadPtr), (ToInsert), NodeField); \
-               else if (strcmp((ToInsert)->NameField, TAILQ_LAST((HeadPtr), HeadType)->NameField) > 0) \
-                       TAILQ_INSERT_TAIL((HeadPtr), (ToInsert), NodeField); \
-               else { \
-                       typeof(ToInsert) _cur; \
-                       TAILQ_FOREACH(_cur, (HeadPtr), NodeField) { \
-                               if (strcmp((ToInsert)->NameField, _cur->NameField) > 0) \
-                                       continue; \
-                               TAILQ_INSERT_BEFORE(_cur, (ToInsert), NodeField); \
-                       } \
-               } \
-       } while (0)
-
 static int usbg_translate_error(int error)
 {
        int ret;