From: Andreas Reichel <[email protected]>

From: Reichel Andreas <[email protected]>

There is no need for two different static libraries, hence these
two are combined to one `libebgenv.a`.

Signed-off-by: Andreas Reichel <[email protected]>
---
 Makefile.am                                | 20 ++++----------
 docs/TODO.md                               |  4 ---
 swupdate-adapter/ebgenv.c => env/env_api.c | 44 ++++++++++++++++++++++++++++--
 env/env_api_fat.c                          | 42 +---------------------------
 {swupdate-adapter => include}/ebgenv.h     |  2 +-
 include/env_api.h                          |  2 +-
 tools/bg_setenv.c                          |  2 +-
 tools/tests/Makefile                       |  7 +----
 tools/tests/test_environment.c             |  1 +
 tools/tests/test_partitions.c              |  1 +
 10 files changed, 55 insertions(+), 70 deletions(-)
 rename swupdate-adapter/ebgenv.c => env/env_api.c (75%)
 rename {swupdate-adapter => include}/ebgenv.h (97%)

diff --git a/Makefile.am b/Makefile.am
index 6c9197f..e4340ba 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -40,12 +40,12 @@ BUILD_TESTS = @build_tests@
 #
 # Static libraries
 #
-lib_LIBRARIES = libebgenv.a libenv_api.a
+lib_LIBRARIES = libebgenv.a
 
 libebgenv_a_SOURCES = \
        env/@[email protected] \
-       tools/ebgpart.c \
-       swupdate-adapter/ebgenv.c
+       env/env_api.c \
+       tools/ebgpart.c
 
 libebgenv_a_CPPFLAGS = \
        $(AM_CPPFLAGS) \
@@ -54,16 +54,8 @@ libebgenv_a_CPPFLAGS = \
 libebgenv_a_CFLAGS = \
        $(AM_CFLAGS)
 
-libenv_api_a_SOURCES = \
-       tools/ebgpart.c \
-       env/@[email protected]
-
-libenv_api_a_CFLAGS = \
-       $(AM_CFLAGS)
-
 pkginclude_HEADERS = \
-       swupdate-adapter/ebgenv.h \
-       include/env_api.h
+       include/ebgenv.h
 
 #
 # bg_setenv binary
@@ -78,11 +70,11 @@ bg_setenv_CFLAGS = \
        $(AM_CFLAGS)
 
 bg_setenv_LDADD = \
-       -lenv_api \
+       -lebgenv \
        -lz
 
 bg_setenv_DEPENDENCIES = \
-       libenv_api.a
+       libebgenv.a
 
 install-exec-hook:
        $(LN_S) bg_setenv$(EXEEXT) \
diff --git a/docs/TODO.md b/docs/TODO.md
index e5f4b3e..29b7fe0 100644
--- a/docs/TODO.md
+++ b/docs/TODO.md
@@ -14,10 +14,6 @@
          key-value pairs.
 
 * API refactoring
-       * Currently, there are two APIs, a lower API 'bg_utils.c', and an
-         adapter-API 'ebgenv.c'. After refactoring the state variable, the API
-         will be simplified as well.  It is possible, that only one API is
-         needed then.
        * Function / Datatype / Variable names remind of Parted and should be
          renamed if code developes independent of libparted.
 
diff --git a/swupdate-adapter/ebgenv.c b/env/env_api.c
similarity index 75%
rename from swupdate-adapter/ebgenv.c
rename to env/env_api.c
index 2c3d52c..1f073cf 100644
--- a/swupdate-adapter/ebgenv.c
+++ b/env/env_api.c
@@ -11,16 +11,56 @@
  */
 
 #include "env_api.h"
-#include "ebgdefs.h"
 #include "ebgenv.h"
+#include "ebgdefs.h"
 
 static BGENV *env_current = NULL;
 
 static bool ebg_new_env_created = false;
 
+/* UEFI uses 16-bit wide unicode strings.
+ * However, wchar_t support functions are fixed to 32-bit wide
+ * characters in glibc. This code is compiled with
+ *  -fshort-wchar
+ * which enables 16-bit wide wchar_t support. However,
+ * glibc functions do not work with 16-bit wchar_t input, except
+ * it was specifically compiled for that, which is unusual.
+ * Thus, the needed conversion by truncation function is
+ * reimplemented here.
+ */
+char *str16to8(char *buffer, wchar_t *src)
+{
+       if (!src || !buffer) {
+               return NULL;
+       }
+       char *tmp = buffer;
+       while (*src) {
+               *buffer = (char)*src;
+               src++;
+               buffer++;
+       }
+       *buffer = 0;
+       return tmp;
+}
+
+wchar_t *str8to16(wchar_t *buffer, char *src)
+{
+       if (!src || !buffer) {
+               return NULL;
+       }
+       wchar_t *tmp = buffer;
+       while (*src) {
+               *buffer = (wchar_t)*src;
+               src++;
+               buffer++;
+       }
+       *buffer = 0;
+       return tmp;
+}
+
 void ebg_beverbose(bool v)
 {
-       be_verbose(v);
+       bgenv_be_verbose(v);
 }
 
 int ebg_env_create_new(void)
diff --git a/env/env_api_fat.c b/env/env_api_fat.c
index ec97b14..5e997d7 100644
--- a/env/env_api_fat.c
+++ b/env/env_api_fat.c
@@ -38,52 +38,12 @@ static EBGENVKEY bgenv_str2enum(char *key)
        return EBGENV_UNKNOWN;
 }
 
-void be_verbose(bool v)
+void bgenv_be_verbose(bool v)
 {
        verbosity = v;
        ebgpart_beverbose(v);
 }
 
-/* UEFI uses 16-bit wide unicode strings.
- * However, wchar_t support functions are fixed to 32-bit wide
- * characters in glibc. This code is compiled with
- *  -fshort-wchar
- * which enables 16-bit wide wchar_t support. However,
- * glibc functions do not work with 16-bit wchar_t input, except
- * it was specifically compiled for that, which is unusual.
- * Thus, the needed conversion by truncation function is
- * reimplemented here.
- */
-char *str16to8(char *buffer, wchar_t *src)
-{
-       if (!src || !buffer) {
-               return NULL;
-       }
-       char *tmp = buffer;
-       while (*src) {
-               *buffer = (char)*src;
-               src++;
-               buffer++;
-       }
-       *buffer = 0;
-       return tmp;
-}
-
-wchar_t *str8to16(wchar_t *buffer, char *src)
-{
-       if (!src || !buffer) {
-               return NULL;
-       }
-       wchar_t *tmp = buffer;
-       while (*src) {
-               *buffer = (wchar_t)*src;
-               src++;
-               buffer++;
-       }
-       *buffer = 0;
-       return tmp;
-}
-
 static char *get_mountpoint(char *devpath)
 {
        struct mntent *part = NULL;
diff --git a/swupdate-adapter/ebgenv.h b/include/ebgenv.h
similarity index 97%
rename from swupdate-adapter/ebgenv.h
rename to include/ebgenv.h
index db20dda..0bcd363 100644
--- a/swupdate-adapter/ebgenv.h
+++ b/include/ebgenv.h
@@ -39,7 +39,7 @@ int ebg_env_open_current(void);
  *  @buffer pointer to buffer containing requested value
  *  @return 0 on success, errno on failure
  */
-int ebg_env_get(char *key, char* buffer);
+int ebg_env_get(char *key, char *buffer);
 
 /** @brief Store new content into variable
  *  @param key name of the environment variable to set
diff --git a/include/env_api.h b/include/env_api.h
index b9bc15d..540a6f1 100644
--- a/include/env_api.h
+++ b/include/env_api.h
@@ -67,7 +67,7 @@ typedef struct {
        BG_ENVDATA *data;
 } BGENV;
 
-extern void be_verbose(bool v);
+extern void bgenv_be_verbose(bool v);
 
 extern char *str16to8(char *buffer, wchar_t *src);
 extern wchar_t *str8to16(wchar_t *buffer, char *src);
diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
index 7efd759..761cb14 100644
--- a/tools/bg_setenv.c
+++ b/tools/bg_setenv.c
@@ -162,7 +162,7 @@ static error_t parse_opt(int key, char *arg, struct 
argp_state *state)
                /* Set verbosity in this program */
                verbosity = true;
                /* Set verbosity in the library */
-               be_verbose(true);
+               bgenv_be_verbose(true);
                break;
        case ARGP_KEY_ARG:
                /* too many arguments - program terminates with call to
diff --git a/tools/tests/Makefile b/tools/tests/Makefile
index 5c4b334..65e8692 100644
--- a/tools/tests/Makefile
+++ b/tools/tests/Makefile
@@ -24,7 +24,6 @@ CFLAGS = \
        -I$(PROJECTDIR)/.. \
        -I$(PROJECTDIR)/../.. \
        -I$(PROJECTDIR)/../../include \
-       -I$(PROJECTDIR)/../../swupdate-adapter \
        -std=gnu99 \
        -g
 
@@ -40,7 +39,6 @@ CFLAGS += \
        -fshort-wchar
 
 LIBS = -L../.. \
-          -L../../swupdate-adapter \
           -lcmocka \
           -lebgenv \
           -lz
@@ -56,7 +54,7 @@ ENV_API ?= env_api_fat
 #
 OBJS_test_partitions = test_partitions.O $(ENV_API).O ebgpart.O
 OBJS_test_environment = test_environment.O $(ENV_API).O ebgpart.O
-OBJS_test_api = test_api.O $(ENV_API).O ebgenv.O
+OBJS_test_api = test_api.O $(ENV_API).O
 
 MOCKOBJS_test_partitions = $(ENV_API) ebgpart
 MOCKOBJS_test_environment = $(ENV_API)
@@ -104,8 +102,5 @@ $(foreach test,$(TEST_TARGETS),$(eval $(call 
TEST_TARGET_TEMPLATE,$(test))))
 %.O: ../../env/%.c
        $(CC) $(CFLAGS) $(DEFINES) -c $< -o $(@:O=o)
 
-%.O: ../../swupdate-adapter/%.c
-       $(CC) $(CFLAGS) $(DEFINES) -c $< -o $(@:O=o)
-
 clean:
        @rm -rf *.o $(TEST_TARGETS:.target=)
diff --git a/tools/tests/test_environment.c b/tools/tests/test_environment.c
index 7402121..a15606c 100644
--- a/tools/tests/test_environment.c
+++ b/tools/tests/test_environment.c
@@ -18,6 +18,7 @@
 #include <cmocka.h>
 #include <string.h>
 #include "env_api.h"
+#include "ebgenv.h"
 #include "test-interface.h"
 
 /* Mock functions from libparted */
diff --git a/tools/tests/test_partitions.c b/tools/tests/test_partitions.c
index f49b35d..24b79d0 100644
--- a/tools/tests/test_partitions.c
+++ b/tools/tests/test_partitions.c
@@ -17,6 +17,7 @@
 #include <setjmp.h>
 #include <cmocka.h>
 #include "env_api.h"
+#include "ebgenv.h"
 #include "test-interface.h"
 
 static PedDevice ped_devices[32] = {0};
-- 
2.13.3

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/20170822161551.12662-10-andreas.reichel.ext%40siemens.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to