From e97b54586b4cb4db780417877c09be594a096415 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 19 Mar 2024 06:08:54 +1100 Subject: [PATCH] AP_ROMFS: added find_size() --- libraries/AP_ROMFS/AP_ROMFS.cpp | 16 +++++++++++++++- libraries/AP_ROMFS/AP_ROMFS.h | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libraries/AP_ROMFS/AP_ROMFS.cpp b/libraries/AP_ROMFS/AP_ROMFS.cpp index cc131f4de329d0..3a8542e199093b 100644 --- a/libraries/AP_ROMFS/AP_ROMFS.cpp +++ b/libraries/AP_ROMFS/AP_ROMFS.cpp @@ -53,7 +53,7 @@ const AP_ROMFS::embedded_file *AP_ROMFS::find_file(const char *name) const uint8_t *AP_ROMFS::find_decompress(const char *name, uint32_t &size) { const struct embedded_file *f = find_file(name); - if (!f) { + if (f == nullptr) { return nullptr; } @@ -146,3 +146,17 @@ const char *AP_ROMFS::dir_list(const char *dirname, uint16_t &ofs) } return nullptr; } + +/* + find a compressed file and return its size +*/ +bool AP_ROMFS::find_size(const char *name, uint32_t &size) +{ + const struct embedded_file *f = find_file(name); + if (f == nullptr) { + return false; + } + size = f->decompressed_size; + return true; +} + diff --git a/libraries/AP_ROMFS/AP_ROMFS.h b/libraries/AP_ROMFS/AP_ROMFS.h index 33a7c219fb7f03..57efa9f5b8c96d 100644 --- a/libraries/AP_ROMFS/AP_ROMFS.h +++ b/libraries/AP_ROMFS/AP_ROMFS.h @@ -16,6 +16,9 @@ class AP_ROMFS { // free returned data static void free(const uint8_t *data); + // get the size of a file without decompressing + static bool find_size(const char *name, uint32_t &size); + /* directory listing interface. Start with ofs=0. Returns pathnames that match dirname prefix. Ends with nullptr return when no more