AP_ROMFS: added find_size()

This commit is contained in:
Andrew Tridgell 2024-03-19 06:08:54 +11:00 committed by Peter Barker
parent 7912fcd511
commit aa7ae2327d
2 changed files with 18 additions and 1 deletions

View File

@ -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;
}

View File

@ -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