font.c glyph_cache_load() reduce stack
rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]> Mon, 8 Jun 2026 22:31:21 -0400
| Newsgroups | gmane.comp.systems.archos.rockbox.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit dfe965d81e853c630636947fa56fd5c73934c5e9 Author: William Wilgus <[email protected]> Date: Fri Jun 5 00:48:53 2026 -0400 font.c glyph_cache_load() reduce stack open the glyph cache in a separate function so we can get the MAX_PATH alloc off the stack quickly and deal with the fd instead Change-Id: I0e991a1286b29c781e3f03b6a49e100c70809920 diff --git a/firmware/font.c b/firmware/font.c index d4a919c4c0..4d0edb77f8 100644 --- a/firmware/font.c +++ b/firmware/font.c @@ -883,13 +883,14 @@ const unsigned char* font_get_bits(struct font* pf, ucschar_t char_code) return bits; } -static void font_path_to_glyph_path( const char *font_path, char *glyph_path) +extern int open_pathfmt(char *buf, size_t size, int oflag, const char *pathfmt, ...); /*misc.c*/ +static NO_INLINE int font_path_open_glyphcache(const char *font_path, int oflags) { - /* take full file name, cut extension, and add .glyphcache */ - strmemccpy(glyph_path, font_path, MAX_PATH); - int dotidx = strlen(glyph_path) - sizeof(FONT_EXT); - strmemccpy(glyph_path + dotidx, "." GLYPH_CACHE_EXT, MAX_PATH - dotidx); - logf("%s %s", __func__, glyph_path); + char glyph_path[MAX_PATH]; + int dotidx = strlen(font_path) - sizeof(FONT_EXT); + logf("%s %.*s.%s", __func__, dotidx, font_path, GLYPH_CACHE_EXT); + return open_pathfmt(glyph_path, sizeof(glyph_path), oflags, + "%.*s.%s", dotidx, font_path, GLYPH_CACHE_EXT); } /* call with NULL to flush */ @@ -944,9 +945,7 @@ static void glyph_cache_save(int font_id) if(pf && pf->fd >= 0) { - char filename[MAX_PATH]; - font_path_to_glyph_path(pdata->path, filename); - fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666); + fd = font_path_open_glyphcache(pdata->path, O_WRONLY|O_CREAT|O_TRUNC); if (fd >= 0) { uint32_t header = FC_HEADER_VAL; @@ -987,10 +986,7 @@ static NO_INLINE void glyph_cache_load(const char *font_path, struct font *pf) if ( sort_size > MAX_SORT ) sort_size = MAX_SORT; - char filename[MAX_PATH]; - font_path_to_glyph_path(font_path, filename); - - fd = open(filename, O_RDONLY|O_BINARY); + fd = font_path_open_glyphcache(font_path, O_RDONLY|O_BINARY); #ifdef TRY_DEFAULT_GLYPHCACHE /* if font specific file fails, try default */ if (fd < 0) -- rockbox-cvs mailing list [email protected] https://lists.haxx.se/mailman/listinfo/rockbox-cvs