From: Andreas Reichel <[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/API.md | 2 +- docs/TODO.md | 4 --- swupdate-adapter/ebgenv.c => env/env_api.c | 42 +++++++++++++++++++++++++++++- env/env_api_fat.c | 42 +----------------------------- {swupdate-adapter => include}/ebgenv.h | 0 include/env_api.h | 2 +- tools/bg_setenv.c | 2 +- tools/tests/test_environment.c | 1 + tools/tests/test_partitions.c | 1 + 10 files changed, 53 insertions(+), 63 deletions(-) rename swupdate-adapter/ebgenv.c => env/env_api.c (76%) rename {swupdate-adapter => include}/ebgenv.h (100%) diff --git a/Makefile.am b/Makefile.am index 2417215..645d845 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,12 +39,12 @@ CLEANFILES = # # 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) \ @@ -53,16 +53,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 @@ -77,11 +69,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) -f bg_setenv$(EXEEXT) \ diff --git a/docs/API.md b/docs/API.md index 3da00b3..1793581 100644 --- a/docs/API.md +++ b/docs/API.md @@ -6,7 +6,7 @@ The library `libebgenv.a` provides an API to access the environment from a user space program. The header file with the interface definitions is -[/swupdate-adapter/ebgenv.h](../swupdate-adapter/ebgenv.h). +[/include/ebgenv.h](../include/ebgenv.h). The interface provides functions to: * enable/disable for output to stdout and stderr 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 76% rename from swupdate-adapter/ebgenv.c rename to env/env_api.c index 9b4e0c4..26d823d 100644 --- a/swupdate-adapter/ebgenv.c +++ b/env/env_api.c @@ -13,9 +13,49 @@ #include "env_api.h" #include "ebgenv.h" +/* 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(ebgenv_t *e, bool v) { - be_verbose(v); + bgenv_be_verbose(v); } int ebg_env_create_new(ebgenv_t *e) diff --git a/env/env_api_fat.c b/env/env_api_fat.c index 8349f6a..38f769f 100644 --- a/env/env_api_fat.c +++ b/env/env_api_fat.c @@ -39,52 +39,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 100% rename from swupdate-adapter/ebgenv.h rename to include/ebgenv.h diff --git a/include/env_api.h b/include/env_api.h index dc53ae4..8fe5454 100644 --- a/include/env_api.h +++ b/include/env_api.h @@ -62,7 +62,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 3df4596..84b580a 100644 --- a/tools/bg_setenv.c +++ b/tools/bg_setenv.c @@ -198,7 +198,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/test_environment.c b/tools/tests/test_environment.c index 61fd417..f4116da 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 62f9cc1..734ec49 100644 --- a/tools/tests/test_partitions.c +++ b/tools/tests/test_partitions.c @@ -18,6 +18,7 @@ #include <cmocka.h> #include "env_api.h" #include "ebgpart.h" +#include "ebgenv.h" #include "test-interface.h" static PedDevice ped_devices[32] = {0}; -- 2.14.1 -- 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/20170926115638.2006-9-andreas.reichel.ext%40siemens.com. For more options, visit https://groups.google.com/d/optout.
