From e65e3b7e5c2bf0219e5a686c4aa8bbeec10fb143 Mon Sep 17 00:00:00 2001 From: "Matwey V. Kornilov" Date: Sun, 4 Aug 2019 14:51:10 +0300 Subject: [PATCH] Add initial implementation fwpkg_init() --- include/fwpkg.h | 5 +++-- src/fwpkg.c | 8 ++++++-- src/ov.c | 2 +- test/fwpkg.c | 14 +++++++------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/include/fwpkg.h b/include/fwpkg.h index ad77085..39aa59e 100644 --- a/include/fwpkg.h +++ b/include/fwpkg.h @@ -12,8 +12,9 @@ struct fwpkg { const char* error_str; }; -int fwpkg_from_file(struct fwpkg* fwpkg, const char* filename); -int fwpkg_from_preload(struct fwpkg* fwpkg); +int fwpkg_init(struct fwpkg* fwpkg, const char* filename); +int fwpkg_init_from_file(struct fwpkg* fwpkg, const char* filename); +int fwpkg_init_from_preload(struct fwpkg* fwpkg); void fwpkg_destroy(struct fwpkg* fwpkg); const char* fwpkg_get_error_string(struct fwpkg* fwpkg); diff --git a/src/fwpkg.c b/src/fwpkg.c index 5107d51..996c980 100644 --- a/src/fwpkg.c +++ b/src/fwpkg.c @@ -72,7 +72,11 @@ static int fwpkg_locate_files(struct fwpkg* fwpkg) { return 0; } -int fwpkg_from_file(struct fwpkg* fwpkg, const char* filename) { +int fwpkg_init(struct fwpkg* fwpkg, const char* filename) { + return (filename ? fwpkg_init_from_file(fwpkg, filename) : fwpkg_init_from_preload(fwpkg)); +} + +int fwpkg_init_from_file(struct fwpkg* fwpkg, const char* filename) { zip_error_t ze; int error; @@ -88,7 +92,7 @@ int fwpkg_from_file(struct fwpkg* fwpkg, const char* filename) { return fwpkg_locate_files(fwpkg); } -int fwpkg_from_preload(struct fwpkg* fwpkg) { +int fwpkg_init_from_preload(struct fwpkg* fwpkg) { zip_error_t error; zip_source_t *src = NULL; diff --git a/src/ov.c b/src/ov.c index c855801..61f39f7 100644 --- a/src/ov.c +++ b/src/ov.c @@ -197,7 +197,7 @@ int ov_load_firmware(struct ov_device* ov, const char* filename) { void* tmp = NULL; int ret = 0; - ret = (filename ? fwpkg_from_file(&fwpkg, filename) : fwpkg_from_preload(&fwpkg)); + ret = fwpkg_init(&fwpkg, filename); if (ret < 0) { ov->error_str = fwpkg_get_error_string(&fwpkg); goto fail_fwpkg_from; diff --git a/test/fwpkg.c b/test/fwpkg.c index 3744005..8648589 100644 --- a/test/fwpkg.c +++ b/test/fwpkg.c @@ -6,7 +6,7 @@ START_TEST (test_fwpkg_load1) { struct fwpkg fwpkg; int ret; - ret = fwpkg_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg"); + ret = fwpkg_init_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg"); ck_assert_int_eq(ret, 0); fwpkg_destroy(&fwpkg); } @@ -14,7 +14,7 @@ END_TEST START_TEST (test_fwpkg_load2) { struct fwpkg fwpkg; int ret; - ret = fwpkg_from_preload(&fwpkg); + ret = fwpkg_init_from_preload(&fwpkg); ck_assert_int_eq(ret, 0); fwpkg_destroy(&fwpkg); } @@ -22,7 +22,7 @@ END_TEST START_TEST (test_fwpkg_size1) { struct fwpkg fwpkg; int ret; - ret = fwpkg_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg"); + ret = fwpkg_init_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg"); ck_assert_int_eq(ret, 0); ck_assert_uint_eq(fwpkg_map_size(&fwpkg), 2080); ck_assert_uint_eq(fwpkg_bitstream_size(&fwpkg), 340972); @@ -34,7 +34,7 @@ START_TEST (test_fwpkg_read1) { size_t size; struct fwpkg fwpkg; int ret; - ret = fwpkg_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg"); + ret = fwpkg_init_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg"); ck_assert_int_eq(ret, 0); size = fwpkg_map_size(&fwpkg); buf = malloc(size); @@ -49,7 +49,7 @@ START_TEST (test_fwpkg_read2) { size_t size; struct fwpkg fwpkg; int ret; - ret = fwpkg_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg"); + ret = fwpkg_init_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg"); ck_assert_int_eq(ret, 0); size = fwpkg_bitstream_size(&fwpkg); buf = malloc(size); @@ -64,7 +64,7 @@ START_TEST (test_fwpkg_read3) { size_t size; struct fwpkg fwpkg; int ret; - ret = fwpkg_from_preload(&fwpkg); + ret = fwpkg_init_from_preload(&fwpkg); ck_assert_int_eq(ret, 0); size = fwpkg_map_size(&fwpkg); buf = malloc(size); @@ -79,7 +79,7 @@ START_TEST (test_fwpkg_read4) { size_t size; struct fwpkg fwpkg; int ret; - ret = fwpkg_from_preload(&fwpkg); + ret = fwpkg_init_from_preload(&fwpkg); ck_assert_int_eq(ret, 0); size = fwpkg_bitstream_size(&fwpkg); buf = malloc(size);