diff --git a/libraries/AP_ROMFS/AP_ROMFS.cpp b/libraries/AP_ROMFS/AP_ROMFS.cpp index cc131f4de3..3a8542e199 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 33a7c219fb..57efa9f5b8 100644 --- a/libraries/AP_ROMFS/AP_ROMFS.h +++ b/libraries/AP_ROMFS/AP_ROMFS.h @@ -16,6 +16,9 @@ public: // 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