diff options
author | William Wilgus <wilgus.william@gmail.com> | 2021-10-20 16:05:21 -0400 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2021-10-20 16:05:21 -0400 |
commit | 9878226e4dec1ee7bb1434249214d6d8161b439f (patch) | |
tree | 6946582892b0e4f62c8072a546e95fb2a6a19977 | |
parent | e1553d860dc42a819fe71913d5a68a77fbf64a6e (diff) | |
download | rockbox-9878226e4dec1ee7bb1434249214d6d8161b439f.tar.gz rockbox-9878226e4dec1ee7bb1434249214d6d8161b439f.zip |
filetree.c move static and stack allocated buffers around
it makes more sense to make the main buffer static and make the
second (infrequently needed) buffer as stack allocated
Change-Id: Ide7c1a7a312124e47a23ed0ab75a90d7b8be982e
-rw-r--r-- | apps/filetree.c | 21 | ||||
-rw-r--r-- | apps/filetypes.c | 9 | ||||
-rw-r--r-- | apps/filetypes.h | 2 |
3 files changed, 17 insertions, 15 deletions
diff --git a/apps/filetree.c b/apps/filetree.c index 5c6443cc34..66e4a68398 100644 --- a/apps/filetree.c +++ b/apps/filetree.c | |||
@@ -435,7 +435,8 @@ static void ft_load_font(char *file) | |||
435 | int ft_enter(struct tree_context* c) | 435 | int ft_enter(struct tree_context* c) |
436 | { | 436 | { |
437 | int rc = GO_TO_PREVIOUS; | 437 | int rc = GO_TO_PREVIOUS; |
438 | char buf[MAX_PATH]; | 438 | static char buf[MAX_PATH]; |
439 | |||
439 | struct entry* file = tree_get_entry_at(c, c->selected_item); | 440 | struct entry* file = tree_get_entry_at(c, c->selected_item); |
440 | if (!file) | 441 | if (!file) |
441 | { | 442 | { |
@@ -634,17 +635,18 @@ int ft_enter(struct tree_context* c) | |||
634 | case FILE_ATTR_LUA: | 635 | case FILE_ATTR_LUA: |
635 | case FILE_ATTR_OPX: | 636 | case FILE_ATTR_OPX: |
636 | { | 637 | { |
637 | char *plugin = buf, *argument = NULL, lua_path[MAX_PATH]; | 638 | char *plugin = buf, *argument = NULL; |
639 | char plugin_path[MAX_PATH]; | ||
638 | int ret; | 640 | int ret; |
639 | 641 | ||
640 | if ((file_attr & FILE_ATTR_MASK) == FILE_ATTR_LUA) { | 642 | if ((file_attr & FILE_ATTR_MASK) == FILE_ATTR_LUA) { |
641 | snprintf(lua_path, sizeof(lua_path)-1, "%s/lua.rock", VIEWERS_DIR); /* Use a #define here ? */ | 643 | snprintf(plugin_path, sizeof(plugin_path)-1, "%s/lua.rock", VIEWERS_DIR); /* Use a #define here ? */ |
642 | plugin = lua_path; | 644 | plugin = plugin_path; |
643 | argument = buf; | 645 | argument = buf; |
644 | } | 646 | } |
645 | else if ((file_attr & FILE_ATTR_MASK) == FILE_ATTR_OPX) { | 647 | else if ((file_attr & FILE_ATTR_MASK) == FILE_ATTR_OPX) { |
646 | snprintf(lua_path, sizeof(lua_path)-1, "%s/open_plugins.rock", VIEWERS_DIR); /* Use a #define here ? */ | 648 | snprintf(plugin_path, sizeof(plugin_path)-1, "%s/open_plugins.rock", VIEWERS_DIR); /* Use a #define here ? */ |
647 | plugin = lua_path; | 649 | plugin = plugin_path; |
648 | argument = buf; | 650 | argument = buf; |
649 | } | 651 | } |
650 | 652 | ||
@@ -685,7 +687,8 @@ int ft_enter(struct tree_context* c) | |||
685 | default: | 687 | default: |
686 | { | 688 | { |
687 | const char* plugin; | 689 | const char* plugin; |
688 | 690 | char plugin_path[MAX_PATH]; | |
691 | const char *argument = buf; | ||
689 | if (global_settings.party_mode && audio_status()) { | 692 | if (global_settings.party_mode && audio_status()) { |
690 | splash(HZ, ID2P(LANG_PARTY_MODE)); | 693 | splash(HZ, ID2P(LANG_PARTY_MODE)); |
691 | break; | 694 | break; |
@@ -698,10 +701,10 @@ int ft_enter(struct tree_context* c) | |||
698 | return rc; | 701 | return rc; |
699 | } | 702 | } |
700 | 703 | ||
701 | plugin = filetype_get_plugin(file); | 704 | plugin = filetype_get_plugin(file, plugin_path, sizeof(plugin_path)); |
702 | if (plugin) | 705 | if (plugin) |
703 | { | 706 | { |
704 | switch (plugin_load(plugin,buf)) | 707 | switch (plugin_load(plugin, argument)) |
705 | { | 708 | { |
706 | case PLUGIN_USB_CONNECTED: | 709 | case PLUGIN_USB_CONNECTED: |
707 | rc = GO_TO_FILEBROWSER; | 710 | rc = GO_TO_FILEBROWSER; |
diff --git a/apps/filetypes.c b/apps/filetypes.c index 530ab18683..3724f57a9b 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c | |||
@@ -531,17 +531,16 @@ int filetype_get_icon(int attr) | |||
531 | return filetypes[index].icon; | 531 | return filetypes[index].icon; |
532 | } | 532 | } |
533 | 533 | ||
534 | char* filetype_get_plugin(const struct entry* file) | 534 | char* filetype_get_plugin(const struct entry* file, char *buffer, size_t buffer_len) |
535 | { | 535 | { |
536 | static char plugin_name[MAX_PATH]; | ||
537 | int index = find_attr(file->attr); | 536 | int index = find_attr(file->attr); |
538 | if (index < 0) | 537 | if (index < 0 || !buffer) |
539 | return NULL; | 538 | return NULL; |
540 | if (filetypes[index].plugin == NULL) | 539 | if (filetypes[index].plugin == NULL) |
541 | return NULL; | 540 | return NULL; |
542 | snprintf(plugin_name, MAX_PATH, "%s/%s.%s", | 541 | snprintf(buffer, buffer_len, "%s/%s.%s", |
543 | PLUGIN_DIR, filetypes[index].plugin, ROCK_EXTENSION); | 542 | PLUGIN_DIR, filetypes[index].plugin, ROCK_EXTENSION); |
544 | return plugin_name; | 543 | return buffer; |
545 | } | 544 | } |
546 | 545 | ||
547 | bool filetype_supported(int attr) | 546 | bool filetype_supported(int attr) |
diff --git a/apps/filetypes.h b/apps/filetypes.h index 23f259b3ca..efe9f3f5df 100644 --- a/apps/filetypes.h +++ b/apps/filetypes.h | |||
@@ -73,7 +73,7 @@ int filetype_get_color(const char* name, int attr); | |||
73 | #endif | 73 | #endif |
74 | int filetype_get_icon(int attr); | 74 | int filetype_get_icon(int attr); |
75 | /* return the plugin filename associated with the file */ | 75 | /* return the plugin filename associated with the file */ |
76 | char* filetype_get_plugin(const struct entry* file); | 76 | char* filetype_get_plugin(const struct entry* file, char *buffer, size_t buffer_len); |
77 | 77 | ||
78 | /* returns true if the attr is supported */ | 78 | /* returns true if the attr is supported */ |
79 | bool filetype_supported(int attr); | 79 | bool filetype_supported(int attr); |