AP_ROMFS: added directory listing interface

This commit is contained in:
Andrew Tridgell 2020-03-07 11:53:39 +11:00
parent 6360c67858
commit 98542d0c0b
2 changed files with 25 additions and 0 deletions

View File

@ -113,3 +113,21 @@ void AP_ROMFS::free(const uint8_t *data)
::free(const_cast<uint8_t *>(data));
#endif
}
/*
directory listing interface. Start with ofs=0. Returns pathnames
that match dirname prefix. Ends with nullptr return when no more
files found
*/
const char *AP_ROMFS::dir_list(const char *dirname, uint16_t &ofs)
{
const size_t dlen = strlen(dirname);
for ( ; ofs < ARRAY_SIZE(files); ofs++) {
if (strncmp(dirname, files[ofs].filename, dlen) == 0 &&
files[ofs].filename[dlen] == '/') {
// found one
return files[ofs++].filename;
}
}
return nullptr;
}

View File

@ -16,6 +16,13 @@ public:
// free returned data
static void free(const uint8_t *data);
/*
directory listing interface. Start with ofs=0. Returns pathnames
that match dirname prefix. Ends with nullptr return when no more
files found
*/
static const char *dir_list(const char *dirname, uint16_t &ofs);
private:
// find an embedded file
static const uint8_t *find_file(const char *name, uint32_t &size);