Skip to content

Commit

Permalink
AP_ROMFS: added find_size()
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Mar 19, 2024
1 parent 7912fcd commit e97b545
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 15 additions & 1 deletion libraries/AP_ROMFS/AP_ROMFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

3 changes: 3 additions & 0 deletions libraries/AP_ROMFS/AP_ROMFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e97b545

Please sign in to comment.