Make the formatter functions used by the settings return a pointer to avoid usless copying of lang strings, this brought with it a long chain of const correctness and a few random cleanups

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22440 a1c6a512-1295-4272-9138-f99709370657
diff --git a/apps/bookmark.c b/apps/bookmark.c
index 5b92767..cee9abd 100644
--- a/apps/bookmark.c
+++ b/apps/bookmark.c
@@ -86,10 +86,10 @@
                             bool *shuffle,
                             char* file_name);
 static int buffer_bookmarks(struct bookmark_list* bookmarks, int first_line);
-static char* get_bookmark_info(int list_index,
-                               void* data,
-                               char *buffer,
-                               size_t buffer_len);
+static const char* get_bookmark_info(int list_index,
+                                     void* data,
+                                     char *buffer,
+                                     size_t buffer_len);
 static char* select_bookmark(const char* bookmark_file_name, bool show_dont_resume);
 static bool  system_check(void);
 static bool  write_bookmark(bool create_bookmark_file, const char *bookmark);
@@ -515,10 +515,10 @@
     return bookmarks->start + bookmarks->count;
 }
 
-static char* get_bookmark_info(int list_index,
-                               void* data,
-                               char *buffer,
-                               size_t buffer_len)
+static const char* get_bookmark_info(int list_index,
+                                     void* data,
+                                     char *buffer,
+                                     size_t buffer_len)
 {
     struct bookmark_list* bookmarks = (struct bookmark_list*) data;
     int     index = list_index / 2;
diff --git a/apps/cuesheet.c b/apps/cuesheet.c
index deb0769..6f29d68 100644
--- a/apps/cuesheet.c
+++ b/apps/cuesheet.c
@@ -234,10 +234,10 @@
 }
 
 /* callback that gives list item titles for the cuesheet browser */
-static char *list_get_name_cb(int selected_item,
-                              void *data,
-                              char *buffer,
-                              size_t buffer_len)
+static const char* list_get_name_cb(int selected_item,
+                                    void *data,
+                                    char *buffer,
+                                    size_t buffer_len)
 {
     struct cuesheet *cue = (struct cuesheet *)data;
 
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index ea53d44..4ca8b3f 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -141,8 +141,8 @@
     return thread_status_chars[status];
 }
 
-static char* threads_getname(int selected_item, void *data,
-                             char *buffer, size_t buffer_len)
+static const char* threads_getname(int selected_item, void *data,
+                                   char *buffer, size_t buffer_len)
 {
     (void)data;
     struct thread_entry *thread;
@@ -183,6 +183,7 @@
 
     return buffer;
 }
+
 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
 {
     (void)lists;
@@ -783,8 +784,8 @@
 #endif /* !SIMULATOR */
 
 #ifndef SIMULATOR
-static char* dbg_partitions_getname(int selected_item, void *data,
-                                    char *buffer, size_t buffer_len)
+static const char* dbg_partitions_getname(int selected_item, void *data,
+                                          char *buffer, size_t buffer_len)
 {
     (void)data;
     int partition = selected_item/2;
@@ -2796,12 +2797,14 @@
     }
     return btn;
 }
-static char* dbg_menu_getname(int item, void * data,
-                              char *buffer, size_t buffer_len)
+
+static const char* dbg_menu_getname(int item, void * data,
+                                    char *buffer, size_t buffer_len)
 {
     (void)data; (void)buffer; (void)buffer_len;
     return menuitems[item].desc;
 }
+
 bool debug_menu(void)
 {
     struct simplelist_info info;
diff --git a/apps/filetypes.c b/apps/filetypes.c
index 210b949..ffa7161 100644
--- a/apps/filetypes.c
+++ b/apps/filetypes.c
@@ -435,13 +435,13 @@
     return filetypes[items[selected_item]].icon;
 }
 
-static char * openwith_get_name(int selected_item, void * data,
-                                char * buffer, size_t buffer_len)
+static const char* openwith_get_name(int selected_item, void * data,
+                                     char * buffer, size_t buffer_len)
 {
     (void)buffer; (void)buffer_len;
     struct cb_data *info = (struct cb_data *)data;
     int *items = info->items;
-    char *s = strrchr(filetypes[items[selected_item]].plugin, '/');
+    const char *s = strrchr(filetypes[items[selected_item]].plugin, '/');
     if (s)
         return s+1;
     else return filetypes[items[selected_item]].plugin;
diff --git a/apps/gui/bitmap/list.c b/apps/gui/bitmap/list.c
index 8e4cd44..71c74db 100644
--- a/apps/gui/bitmap/list.c
+++ b/apps/gui/bitmap/list.c
@@ -173,7 +173,7 @@
     for (i=start; i<end && i<list->nb_items; i++)
     {
         /* do the text */
-        unsigned char *s;
+        unsigned const char *s;
         char entry_buffer[MAX_PATH];
         unsigned char *entry_name;
         int text_pos = 0;
diff --git a/apps/gui/charcell/list.c b/apps/gui/charcell/list.c
index 8d91c2f..2374156 100644
--- a/apps/gui/charcell/list.c
+++ b/apps/gui/charcell/list.c
@@ -69,7 +69,7 @@
 
     for (i = start; i < end; i++)
     {
-        unsigned char *s;
+        unsigned const char *s;
         char entry_buffer[MAX_PATH];
         unsigned char *entry_name;
         int current_item = gui_list->start_item[display->screen_type] + i;
diff --git a/apps/gui/list.c b/apps/gui/list.c
index 332459c..9b139dd 100644
--- a/apps/gui/list.c
+++ b/apps/gui/list.c
@@ -827,10 +827,10 @@
     va_end(ap);
 }
 
-static char* simplelist_static_getname(int item,
-                                       void * data,
-                                       char *buffer,
-                                       size_t buffer_len)
+static const char* simplelist_static_getname(int item,
+                                             void * data,
+                                             char *buffer,
+                                             size_t buffer_len)
 {
     (void)data; (void)buffer; (void)buffer_len;
     return simplelist_text[item];
@@ -841,7 +841,7 @@
     struct gui_synclist lists;
     int action, old_line_count = simplelist_line_count;
     int oldbars = viewportmanager_set_statusbar(VP_SB_ALLSCREENS);
-    char* (*getname)(int item, void * data, char *buffer, size_t buffer_len);
+    const char* (*getname)(int item, void * data, char *buffer, size_t buffer_len);
     int wrap = LIST_WRAP_UNLESS_HELD;
     if (info->get_name)
         getname = info->get_name;
diff --git a/apps/gui/list.h b/apps/gui/list.h
index 7148e34..8a36acb 100644
--- a/apps/gui/list.h
+++ b/apps/gui/list.h
@@ -64,8 +64,8 @@
  *  - buffer_len : length of the buffer
  * Returns a pointer to a string that contains the text to display
  */
-typedef char * list_get_name(int selected_item, void * data,
-                             char * buffer, size_t buffer_len);
+typedef const char * list_get_name(int selected_item, void * data,
+                                   char * buffer, size_t buffer_len);
 /*
  * Voice callback
  *  - selected_item : an integer that tells the number of the item to speak
diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c
index 01259c4..d806a0a 100644
--- a/apps/gui/option_select.c
+++ b/apps/gui/option_select.c
@@ -69,10 +69,11 @@
 /* these two vars are needed so arbitrary values can be added to the
    TABLE_SETTING settings if the F_ALLOW_ARBITRARY_VALS flag is set */
 static int table_setting_oldval = 0, table_setting_array_position = 0;
-char *option_get_valuestring(const struct settings_list *setting, 
-                             char *buffer, int buf_len,
-                             intptr_t temp_var)
+const char *option_get_valuestring(const struct settings_list *setting, 
+                                   char *buffer, int buf_len,
+                                   intptr_t temp_var)
 {
+    const char* str = buffer;
     if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING)
     {
         bool val = (bool)temp_var;
@@ -93,7 +94,7 @@
         const struct int_setting *int_info = setting->int_setting;
         const struct table_setting *tbl_info = setting->table_setting;
         const char *unit;
-        void (*formatter)(char*, size_t, int, const char*);
+        const char* (*formatter)(char*, size_t, int, const char*);
         if ((setting->flags & F_INT_SETTING) == F_INT_SETTING)
         {
             formatter = int_info->formatter;
@@ -105,7 +106,7 @@
             unit = unit_strings[tbl_info->unit];
         }
         if (formatter)
-            formatter(buffer, buf_len, (int)temp_var, unit);
+            str = formatter(buffer, buf_len, (int)temp_var, unit);
         else
             snprintf(buffer, buf_len, "%d %s", (int)temp_var, unit?unit:"");
     }
@@ -152,7 +153,7 @@
             strlcpy(buffer, val, buf_len);
         }
     }
-    return buffer;
+    return str;
 }
 void option_talk_value(const struct settings_list *setting, int value, bool enqueue)
 {
@@ -363,10 +364,11 @@
     }
     return max- (selection * step);
 }
-static char * value_setting_get_name_cb(int selected_item, 
-                                        void * data,
-                                        char *buffer,
-                                        size_t buffer_len)
+
+static const char * value_setting_get_name_cb(int selected_item, 
+                                              void * data,
+                                              char *buffer,
+                                              size_t buffer_len)
 {
     selected_item = selection_to_val(data, selected_item);
     return option_get_valuestring(data, buffer, buffer_len, selected_item);
diff --git a/apps/gui/option_select.h b/apps/gui/option_select.h
index b1a4a86..a8661fb 100644
--- a/apps/gui/option_select.h
+++ b/apps/gui/option_select.h
@@ -33,7 +33,7 @@
 void option_select_next_val(const struct settings_list *setting,
                             bool previous, bool apply);
 #endif
-char *option_get_valuestring(const struct settings_list *setting, 
+const char *option_get_valuestring(const struct settings_list *setting, 
                              char *buffer, int buf_len,
                              intptr_t temp_var);
 void option_talk_value(const struct settings_list *setting, int value, bool enqueue);
diff --git a/apps/gui/quickscreen.c b/apps/gui/quickscreen.c
index 20d2738..d6d662b 100644
--- a/apps/gui/quickscreen.c
+++ b/apps/gui/quickscreen.c
@@ -147,7 +147,7 @@
                 vps[screen][QUICKSCREEN_BOTTOM].y - vp_icons[screen].y;
 }
 
-static void quickscreen_draw_text(char *s, int item, bool title,
+static void quickscreen_draw_text(const char *s, int item, bool title,
                                   struct screen *display, struct viewport *vp)
 {
     int nb_lines = viewport_get_nb_lines(vp);
@@ -186,7 +186,7 @@
 
     int i;
     char buf[MAX_PATH];
-    unsigned char *title, *value;
+    unsigned const char *title, *value;
     void *setting;
     int temp;
     display->set_viewport(parent);
diff --git a/apps/menu.c b/apps/menu.c
index 348095c..b442d44 100644
--- a/apps/menu.c
+++ b/apps/menu.c
@@ -93,10 +93,10 @@
             return i;
     return 0;
 }
-static char * get_menu_item_name(int selected_item,
-                                 void * data,
-                                 char *buffer,
-                                 size_t buffer_len)
+static const char* get_menu_item_name(int selected_item,
+                                      void * data,
+                                      char *buffer,
+                                      size_t buffer_len)
 {
     const struct menu_item_ex *menu = (const struct menu_item_ex *)data;
     int type = (menu->flags&MENU_TYPE_MASK);
@@ -109,7 +109,7 @@
         if (menu->flags&MENU_DYNAMIC_DESC)
             return menu->menu_get_name_and_icon->list_get_name(selected_item,
                     menu->menu_get_name_and_icon->list_get_name_data, buffer);
-        return (char*)menu->strings[selected_item];
+        return menu->strings[selected_item];
     }
     
     menu = menu->submenus[selected_item];
diff --git a/apps/menus/eq_menu.c b/apps/menus/eq_menu.c
index 6087ebf..0e04ddd 100644
--- a/apps/menus/eq_menu.c
+++ b/apps/menus/eq_menu.c
@@ -51,15 +51,18 @@
  * Utility functions
  */
 
-void eq_q_format(char* buffer, size_t buffer_size, int value, const char* unit)
+const char* eq_q_format(char* buffer, size_t buffer_size, int value, const char* unit)
 {
-    snprintf(buffer, buffer_size, "%d.%d %s", value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit);
+    snprintf(buffer, buffer_size, "%d.%d %s", value / EQ_USER_DIVISOR,
+         value % EQ_USER_DIVISOR, unit);
+    return buffer;
 }
 
-void eq_precut_format(char* buffer, size_t buffer_size, int value, const char* unit)
+const char* eq_precut_format(char* buffer, size_t buffer_size, int value, const char* unit)
 {
     snprintf(buffer, buffer_size, "%s%d.%d %s", value == 0 ? " " : "-",
         value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit);
+    return buffer;
 }
 
 /*
diff --git a/apps/menus/eq_menu.h b/apps/menus/eq_menu.h
index 6be0991..6c8301c 100644
--- a/apps/menus/eq_menu.h
+++ b/apps/menus/eq_menu.h
@@ -43,7 +43,9 @@
 bool eq_menu_graphical(void);
 
 /* utility functions for settings_list.c */
-void eq_q_format(char* buffer, size_t buffer_size, int value, const char* unit);
-void eq_precut_format(char* buffer, size_t buffer_size, int value, const char* unit);
+const char* eq_q_format(char* buffer, size_t buffer_size, int value,
+                        const char* unit);
+const char* eq_precut_format(char* buffer, size_t buffer_size, int value,
+                             const char* unit);
 
 #endif
diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c
index 1e74655..99c73f2 100644
--- a/apps/menus/main_menu.c
+++ b/apps/menus/main_menu.c
@@ -164,8 +164,8 @@
     ID2P(LANG_MEGABYTE)
 };
 
-static char* info_getname(int selected_item, void *data,
-                          char *buffer, size_t buffer_len)
+static const char* info_getname(int selected_item, void *data,
+                                char *buffer, size_t buffer_len)
 {
     struct info_data *info = (struct info_data*)data;
     char s1[32];
@@ -199,27 +199,27 @@
 #if CONFIG_CHARGING == CHARGING_SIMPLE
             /* Only know if plugged */
             if (charger_inserted())
-                return (char *)str(LANG_BATTERY_CHARGE);
+                return str(LANG_BATTERY_CHARGE);
             else
 #elif CONFIG_CHARGING >= CHARGING_MONITOR
 #ifdef ARCHOS_RECORDER
             /* Report the particular algorithm state */
             if (charge_state == CHARGING)
-                return (char *)str(LANG_BATTERY_CHARGE);
+                return str(LANG_BATTERY_CHARGE);
             else if (charge_state == TOPOFF)
-                return (char *)str(LANG_BATTERY_TOPOFF_CHARGE);
+                return str(LANG_BATTERY_TOPOFF_CHARGE);
             else if (charge_state == TRICKLE)
-                return (char *)str(LANG_BATTERY_TRICKLE_CHARGE);
+                return str(LANG_BATTERY_TRICKLE_CHARGE);
             else
 #else /* !ARCHOS_RECORDER */
             /* Go by what power management reports */
             if (charging_state())
-                return (char *)str(LANG_BATTERY_CHARGE);
+                return str(LANG_BATTERY_CHARGE);
             else
 #endif /* ARCHOS_RECORDER */
 #endif /* CONFIG_CHARGING = */
             if (battery_level() >= 0)
-                snprintf(buffer, buffer_len, (char *)str(LANG_BATTERY_TIME),
+                snprintf(buffer, buffer_len, str(LANG_BATTERY_TIME),
                          battery_level(), battery_time() / 60, battery_time() % 60);
             else
                 return "(n/a)";
@@ -399,19 +399,19 @@
 
 
 /* sleep Menu */
-static void sleep_timer_formatter(char* buffer, size_t buffer_size, int value,
-                                  const char* unit)
+static const char* sleep_timer_formatter(char* buffer, size_t buffer_size,
+                                         int value, const char* unit)
 {
-    int minutes, hours;
-
     (void) unit;
+    int minutes, hours;
 
     if (value) {
         hours = value / 60;
         minutes = value - (hours * 60);
         snprintf(buffer, buffer_size, "%d:%02d", hours, minutes);
-   } else {
-        strlcpy(buffer, str(LANG_OFF), buffer_size);
+        return buffer;
+    } else {
+        return str(LANG_OFF);
     }
 }
 
diff --git a/apps/menus/recording_menu.c b/apps/menus/recording_menu.c
index c15a182..7b99b48 100644
--- a/apps/menus/recording_menu.c
+++ b/apps/menus/recording_menu.c
@@ -415,7 +415,7 @@
     return Icon_NOICON;
 }
 
-static char * trigger_get_name(int selected_item, void * data,
+static const char * trigger_get_name(int selected_item, void * data,
                         char * buffer, size_t buffer_len)
 {
     const struct settings_list **settings = 
diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c
index a4950e2..5e8cf02 100644
--- a/apps/playlist_catalog.c
+++ b/apps/playlist_catalog.c
@@ -184,8 +184,8 @@
 }
 
 /* Callback for gui_synclist */
-static char* playlist_callback_name(int selected_item, void* data,
-                                    char* buffer, size_t buffer_len)
+static const char* playlist_callback_name(int selected_item, void* data,
+                                          char* buffer, size_t buffer_len)
 {
     char** playlists = (char**) data;
 
diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c
index 7d3ff4e..a829fc9 100644
--- a/apps/playlist_viewer.c
+++ b/apps/playlist_viewer.c
@@ -559,10 +559,10 @@
     return selected_item;
 }
 
-static char *playlist_callback_name(int selected_item,
-                                    void *data,
-                                    char *buffer,
-                                    size_t buffer_len)
+static const char* playlist_callback_name(int selected_item,
+                                          void *data,
+                                          char *buffer,
+                                          size_t buffer_len)
 {
     struct playlist_viewer * local_viewer = (struct playlist_viewer *)data;
 
@@ -778,15 +778,15 @@
     return ret;
 }
 
-static char *playlist_search_callback_name(int selected_item, void * data,
-                                           char *buffer, size_t buffer_len)
+static const char* playlist_search_callback_name(int selected_item, void * data,
+                                                 char *buffer, size_t buffer_len)
 {
     (void)buffer_len; /* this should probably be used */
     int *found_indicies = (int*)data;
     static struct playlist_track_info track;
     playlist_get_track_info(viewer.playlist, found_indicies[selected_item], &track);
     format_name(buffer, track.filename);
-    return(buffer);
+    return buffer;
 }
 
 bool search_playlist(void)
diff --git a/apps/plugin.h b/apps/plugin.h
index 4cf3192..4981230 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -133,12 +133,12 @@
 #define PLUGIN_MAGIC 0x526F634B /* RocK */
 
 /* increase this every time the api struct changes */
-#define PLUGIN_API_VERSION 170
+#define PLUGIN_API_VERSION 171
 
 /* update this to latest version if a change to the api struct breaks
    backwards compatibility (and please take the opportunity to sort in any
    new function which are "waiting" at the end of the function table) */
-#define PLUGIN_MIN_API_VERSION 170
+#define PLUGIN_MIN_API_VERSION 171
 
 /* plugin return codes */
 enum plugin_status {
@@ -672,7 +672,7 @@
     bool (*set_int)(const unsigned char* string, const char* unit, int voice_unit,
                     const int* variable, void (*function)(int), int step,
                     int min, int max,
-                    void (*formatter)(char*, size_t, int, const char*) );
+                    const char* (*formatter)(char*, size_t, int, const char*) );
     bool (*set_bool)(const char* string, const bool* variable );
 
 #ifdef HAVE_LCD_COLOR
diff --git a/apps/plugins/calendar.c b/apps/plugins/calendar.c
index cfb9290..20b7fa9 100644
--- a/apps/plugins/calendar.c
+++ b/apps/plugins/calendar.c
@@ -669,7 +669,7 @@
     return false;
 }
 
-static char * get_event_text(int selected, void *data,
+static const char* get_event_text(int selected, void *data,
                                   char *buffer, size_t buffer_len)
 {
     struct shown *shown = (struct shown *) data;
diff --git a/apps/plugins/chessbox/chessbox_pgn.c b/apps/plugins/chessbox/chessbox_pgn.c
index cd163a5..512fb0c 100644
--- a/apps/plugins/chessbox/chessbox_pgn.c
+++ b/apps/plugins/chessbox/chessbox_pgn.c
@@ -528,11 +528,10 @@
     }
 }
 
-char * get_game_text(int selected_item, void *data,
-                     char *buffer, size_t buffer_len){
+static const char* get_game_text(int selected_item, void *data,
+                                 char *buffer, size_t buffer_len){
     int i;
     struct pgn_game_node *temp_node = (struct pgn_game_node *)data;
-    char text_buffer[50];
 
     for (i=0;i<selected_item && temp_node != NULL;i++){
         temp_node = temp_node->next_node;
@@ -540,10 +539,9 @@
     if (temp_node == NULL){
         return NULL;
     }
-    rb->snprintf(text_buffer, 50,"%s vs. %s (%s)", temp_node->white_player,
+    rb->snprintf(buffer, buffer_len,"%s vs. %s (%s)", temp_node->white_player,
                          temp_node->black_player, temp_node->game_date);
 
-    rb->strlcpy(buffer, text_buffer, buffer_len);
     return buffer;
 }
 
diff --git a/apps/plugins/disktidy.c b/apps/plugins/disktidy.c
index b7b9aa1..84cc220 100644
--- a/apps/plugins/disktidy.c
+++ b/apps/plugins/disktidy.c
@@ -380,8 +380,8 @@
         return Icon_NOICON;
 }
 
-char * get_name(int selected_item, void * data,
-                     char * buffer, size_t buffer_len)
+static const char* get_name(int selected_item, void * data,
+                            char * buffer, size_t buffer_len)
 {
     (void)data;
     if (tidy_types[selected_item].directory)
diff --git a/apps/plugins/doom/rockdoom.c b/apps/plugins/doom/rockdoom.c
index ca08ec1..1d065cc 100644
--- a/apps/plugins/doom/rockdoom.c
+++ b/apps/plugins/doom/rockdoom.c
@@ -550,14 +550,15 @@
     return (1);
 }
 
-char* choice_get_name(int selected_item, void * data,
-                     char * buffer, size_t buffer_len)
+static const char* choice_get_name(int selected_item, void * data,
+                                   char * buffer, size_t buffer_len)
 {
-    char **names = (char **) data;
+    const char **names = (const char **) data;
     (void) buffer;
     (void) buffer_len;
     return names[selected_item];
 }
+
 int list_action_callback(int action, struct gui_synclist *lists)
 {
     (void) lists;
@@ -565,6 +566,7 @@
         return ACTION_STD_CANCEL;
     return action;
 }
+
 bool menuchoice(char **names, int count, int *selected)
 {
    struct simplelist_info info;
diff --git a/apps/plugins/goban/goban.c b/apps/plugins/goban/goban.c
index 65a03f6..4e20e71 100644
--- a/apps/plugins/goban/goban.c
+++ b/apps/plugins/goban/goban.c
@@ -114,37 +114,39 @@
     autosave_time = 7;
 }
 
-static void
+static const char*
 komi_formatter (char *dest, size_t size, int menu_item, const char *unknown)
 {
     (void) unknown;
     snprint_fixed (dest, size, menu_item);
+    return dest;
 }
 
-static void
+static const char*
 ruleset_formatter (char *dest, size_t size, int menu_item, const char *unknown)
 {
-    (void) unknown;
-    rb->snprintf (dest, size, "%s", ruleset_names[menu_item]);
+    (void)dest, (void)size, (void)unknown;
+    return ruleset_names[menu_item];
 }
 
-static void
+static const char*
 autosave_formatter (char *dest, size_t size, int menu_item, const char *
 unknown)
 {
     (void) unknown;
     if (menu_item == 0)
     {
-        rb->snprintf (dest, size, "Off");
+        return "Off";
     }
     else
     {
         rb->snprintf (dest, size, "%d minute%s", menu_item,
                       menu_item == 1 ? "" : "s");
+        return dest;
     }
 }
 
-static void
+static const char*
 time_formatter (char *dest, size_t size, int menu_item, const char *unknown)
 {
     int time_values[4];         /* days hours minutes seconds */
@@ -183,8 +185,7 @@
 
     if (max_set == -1)
     {
-        rb->snprintf (dest, size, "0");
-        return;
+        return "0";
     }
 
     for (i = min_set; i <= 3; ++i)
@@ -236,6 +237,7 @@
         dest += temp;
         size -= temp;
     }
+    return dest;
 }
 
 enum plugin_status
diff --git a/apps/plugins/goban/types.h b/apps/plugins/goban/types.h
index 216d41b..a7c2b9b 100644
--- a/apps/plugins/goban/types.h
+++ b/apps/plugins/goban/types.h
@@ -218,7 +218,7 @@
 
 
 /* The names of the rulesets, ex. "AGA", "Japanese", etc. */
-extern char *ruleset_names[];
+extern const char *ruleset_names[];
 
 /* IMPORTANT! keep in sync with ruleset_names!!! */
 enum ruleset_t
diff --git a/apps/plugins/goban/util.c b/apps/plugins/goban/util.c
index e996631..0e83173 100644
--- a/apps/plugins/goban/util.c
+++ b/apps/plugins/goban/util.c
@@ -210,7 +210,7 @@
 
 /* These seems to be specified by the SGF specification.  You can do free
    form ones as well, but I haven't implemented that (and don't plan to) */
-char *ruleset_names[] = { "AGA", "Japanese", "Chinese", "NZ", "GOE" };
+const char *ruleset_names[] = { "AGA", "Japanese", "Chinese", "NZ", "GOE" };
 
 
 
diff --git a/apps/plugins/keybox.c b/apps/plugins/keybox.c
index 733c6e9..d926105 100644
--- a/apps/plugins/keybox.c
+++ b/apps/plugins/keybox.c
@@ -122,8 +122,8 @@
                     "Delete entry",
                     "Playback Control");
 
-static char * kb_list_cb(int selected_item, void *data,
-                         char *buffer, size_t buffer_len)
+static const char* kb_list_cb(int selected_item, void *data,
+                              char *buffer, size_t buffer_len)
 {
     (void)data;
     int i;
diff --git a/apps/plugins/mpegplayer/mpeg_settings.c b/apps/plugins/mpegplayer/mpeg_settings.c
index 62293d1..3868d75 100644
--- a/apps/plugins/mpegplayer/mpeg_settings.c
+++ b/apps/plugins/mpegplayer/mpeg_settings.c
@@ -317,7 +317,7 @@
                          void (*function)(int), int step,
                          int min,
                          int max,
-                         void (*formatter)(char*, size_t, int, const char*))
+                         const char* (*formatter)(char*, size_t, int, const char*))
 {
     mpeg_menu_sysevent_clear();
 
@@ -350,15 +350,16 @@
     mpeg_backlight_update_brightness(value);
 }
 
-static void backlight_brightness_formatter(char *buf, size_t length,
-                                           int value, const char *input)
+static const char* backlight_brightness_formatter(char *buf, size_t length,
+                                                  int value, const char *input)
 {
+    (void)input;
+
     if (value < 0)
-        rb->strlcpy(buf, BACKLIGHT_OPTION_DEFAULT, length);
+        return BACKLIGHT_OPTION_DEFAULT;
     else
         rb->snprintf(buf, length, "%d", value + MIN_BRIGHTNESS_SETTING);
-
-    (void)input;
+    return buf;
 }
 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
 
diff --git a/apps/plugins/properties.c b/apps/plugins/properties.c
index c76a25b..7cd29c1 100644
--- a/apps/plugins/properties.c
+++ b/apps/plugins/properties.c
@@ -228,7 +228,8 @@
     return true;
 }
 
-char * get_props(int selected_item, void* data, char *buffer, size_t buffer_len)
+static const char * get_props(int selected_item, void* data,
+                              char *buffer, size_t buffer_len)
 {
     (void)data;
 
@@ -263,8 +264,7 @@
             rb->strlcpy(buffer, its_a_dir ? "" : str_duration, buffer_len);
             break;
         default:
-            rb->strlcpy(buffer, "ERROR", buffer_len);
-            break;
+            return "ERROR";
     }
     return buffer;
 }
diff --git a/apps/plugins/random_folder_advance_config.c b/apps/plugins/random_folder_advance_config.c
index c9ffaed..ba3f0d3 100644
--- a/apps/plugins/random_folder_advance_config.c
+++ b/apps/plugins/random_folder_advance_config.c
@@ -234,7 +234,9 @@
     rb->close(fd);
     rb->splash(HZ, "Done");
 }
-char *list_get_name_cb(int selected_item, void* data, char* buf, size_t buf_len)
+
+static const char* list_get_name_cb(int selected_item, void* data,
+                                    char* buf, size_t buf_len)
 {
     (void)data;
     rb->strlcpy(buf, list->folder[selected_item], buf_len);
diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c
index 455c91b..bd40883 100644
--- a/apps/plugins/rockboy/menu.c
+++ b/apps/plugins/rockboy/menu.c
@@ -270,10 +270,10 @@
 /* 
  * slot_get_name
  */
-static char *slot_get_name(int selected_item, void * data,
-                             char * buffer, size_t buffer_len)
+static const char* slot_get_name(int selected_item, void * data,
+                                 char * buffer, size_t buffer_len)
 {
-    char (*items)[20] = data;
+    const char (*items)[20] = data;
     (void) buffer;
     (void) buffer_len;
     return items[selected_item];
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c
index a4084a2..219f013 100644
--- a/apps/plugins/rockpaint.c
+++ b/apps/plugins/rockpaint.c
@@ -600,8 +600,8 @@
 char bbuf_s[MAX_PATH+1]; /* used by file and font browsers */
 struct tree_context *tree = NULL;
 
-static char * browse_get_name_cb( int selected_item, void *data,
-                                  char *buffer, size_t buffer_len )
+static const char* browse_get_name_cb(int selected_item, void *data,
+                                      char *buffer, size_t buffer_len)
 {
     int *indexes = (int *) data;
     struct entry* dc = tree->dircache;
@@ -609,7 +609,7 @@
     (void) buffer;
     (void) buffer_len;
 
-    return (e->name);
+    return e->name;
 }
 
 static bool browse( char *dst, int dst_size, const char *start )
@@ -633,8 +633,8 @@
     }
     bbuf_s[0] = '\0';
 
-    rb->gui_synclist_init( &browse_list, browse_get_name_cb,
-                            (void*) indexes, false, 1, NULL );
+    rb->gui_synclist_init(&browse_list, browse_get_name_cb,
+                            (void*) indexes, false, 1, NULL);
 
     tree = rb->tree_get_context();
     backup = *tree;
diff --git a/apps/plugins/shortcuts/shortcuts_view.c b/apps/plugins/shortcuts/shortcuts_view.c
index f6a26a5..b964968 100644
--- a/apps/plugins/shortcuts/shortcuts_view.c
+++ b/apps/plugins/shortcuts/shortcuts_view.c
@@ -40,8 +40,8 @@
 enum sc_list_action_type draw_sc_list(struct gui_synclist *gui_sc);
 
 /* Will be passed sc_file* as data */
-char* build_sc_list(int selected_item, void *data,
-                    char *buffer, size_t buffer_len);
+static const char* build_sc_list(int selected_item, void *data,
+                                 char *buffer, size_t buffer_len);
 
 /* Returns true iff we should leave the main loop */
 bool list_sc(void);
@@ -89,8 +89,8 @@
 }
 
 
-char* build_sc_list(int selected_item, void *data,
-                    char *buffer, size_t buffer_len)
+static const char* build_sc_list(int selected_item, void *data,
+                                 char *buffer, size_t buffer_len)
 {
     sc_file_t *file = (sc_file_t*)data;
     
diff --git a/apps/plugins/superdom.c b/apps/plugins/superdom.c
index d6b9621..dc07817 100644
--- a/apps/plugins/superdom.c
+++ b/apps/plugins/superdom.c
@@ -1251,8 +1251,8 @@
     return RET_VAL_OK;
 }
 
-static char * inventory_data(int selected_item, void * data,
-                             char * buffer, size_t buffer_len) {
+static const char* inventory_data(int selected_item, void * data,
+                                  char * buffer, size_t buffer_len) {
     (void)data;
     switch(selected_item) {
         case 0:
diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c
index 473bb68..dc79204 100644
--- a/apps/plugins/text_editor.c
+++ b/apps/plugins/text_editor.c
@@ -121,8 +121,8 @@
     last_char_index = c;
     return 1;
 }
-char *list_get_name_cb(int selected_item, void* data,
-                       char* buf, size_t buf_len)
+static const char* list_get_name_cb(int selected_item, void* data,
+                                    char* buf, size_t buf_len)
 {
     (void)data;
     char *b = &buffer[do_action(ACTION_GET,0,selected_item)];
diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c
index c5729ba..31610a3 100644
--- a/apps/recorder/radio.c
+++ b/apps/recorder/radio.c
@@ -1347,8 +1347,8 @@
             radio_preset_callback, Icon_NOICON, &radio_edit_preset_item, 
             &radio_delete_preset_item);
 /* present a list of preset stations */
-static char * presets_get_name(int selected_item, void *data,
-                               char *buffer, size_t buffer_len)
+static const char* presets_get_name(int selected_item, void *data,
+                                    char *buffer, size_t buffer_len)
 {
     (void)data;
     struct fmstation *p = &presets[selected_item];
diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c
index 2716d93..d461df5 100644
--- a/apps/recorder/recording.c
+++ b/apps/recorder/recording.c
@@ -848,8 +848,8 @@
 
 static int listid_to_enum[ITEM_COUNT];
 
-static char * reclist_get_name(int selected_item, void * data,
-                               char * buffer, size_t buffer_len)
+static const char* reclist_get_name(int selected_item, void * data,
+                                    char * buffer, size_t buffer_len)
 {
     char buf2[32];
 #ifdef HAVE_AGC
diff --git a/apps/screens.c b/apps/screens.c
index 2bdd2dd..ead6735 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -789,20 +789,22 @@
 #endif
     LANG_ID3_PATH,
 };
+
 struct id3view_info {
     struct mp3entry* id3;
     int count;
-    int info_id[sizeof(id3_headers)/sizeof(id3_headers[0])];
+    int info_id[ARRAYLEN(id3_headers)];
 };
-static char * id3_get_info(int selected_item, void* data,
-                           char *buffer, size_t buffer_len)
+
+static const char* id3_get_info(int selected_item, void* data,
+                                char *buffer, size_t buffer_len)
 {
     struct id3view_info *info = (struct id3view_info*)data;
     struct mp3entry* id3 =info->id3;
     int info_no=selected_item/2;
     if(!(selected_item%2))
     {/* header */
-        return( str(id3_headers[info->info_id[info_no]]));
+        return(str(id3_headers[info->info_id[info_no]]));
     }
     else
     {/* data */
@@ -903,7 +905,7 @@
     struct id3view_info info;
     info.count = 0;
     info.id3 = id3;
-    for (i=0; i<sizeof(id3_headers)/sizeof(id3_headers[0]); i++)
+    for (i = 0; i < ARRAYLEN(id3_headers); i++)
     {
         char temp[8];
         info.info_id[i] = i;
@@ -924,8 +926,8 @@
     }
 }
 
-static char* runtime_get_data(int selected_item, void* data,
-                              char* buffer, size_t buffer_len)
+static const char* runtime_get_data(int selected_item, void* data,
+                                    char* buffer, size_t buffer_len)
 {
     (void)data;
     int t;
diff --git a/apps/settings.c b/apps/settings.c
index b764682..98cd6eb 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -1083,7 +1083,7 @@
              int step,
              int min,
              int max,
-             void (*formatter)(char*, size_t, int, const char*) )
+             const char* (*formatter)(char*, size_t, int, const char*) )
 {
     return set_int_ex(string, unit, voice_unit, variable, function,
                       step, min, max, formatter, NULL);
@@ -1097,7 +1097,7 @@
                 int step,
                 int min,
                 int max,
-                void (*formatter)(char*, size_t, int, const char*),
+                const char* (*formatter)(char*, size_t, int, const char*),
                 int32_t (*get_talk_id)(int, int))
 {
     (void)unit;
@@ -1117,17 +1117,18 @@
 
 
 static const struct opt_items *set_option_options;
-static void set_option_formatter(char* buf, size_t size, int item, const char* unit)
+static const char* set_option_formatter(char* buf, size_t size, int item, const char* unit)
 {
-    (void)unit;
-    const unsigned char *text = set_option_options[item].string;
-    strlcpy(buf, P2STR(text), size);
+    (void)buf, (void)unit, (void)size;
+    return P2STR(set_option_options[item].string);
 }
+
 static int32_t set_option_get_talk_id(int value, int unit)
 {
     (void)unit;
     return set_option_options[value].voice_id;
 }
+
 bool set_option(const char* string, const void* variable, enum optiontype type,
                 const struct opt_items* options, 
                 int numoptions, void (*function)(int))
diff --git a/apps/settings.h b/apps/settings.h
index c45e3b3..cbd7b6d 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -271,13 +271,13 @@
 bool set_int(const unsigned char* string, const char* unit, int voice_unit,
              const int* variable,
              void (*function)(int), int step, int min, int max,
-             void (*formatter)(char*, size_t, int, const char*) );
+             const char* (*formatter)(char*, size_t, int, const char*) );
 
 /* use this one if you need to create a lang from the value (i.e with TALK_ID()) */
 bool set_int_ex(const unsigned char* string, const char* unit, int voice_unit,
              const int* variable,
              void (*function)(int), int step, int min, int max,
-             void (*formatter)(char*, size_t, int, const char*),
+             const char* (*formatter)(char*, size_t, int, const char*),
              int32_t (*get_talk_id)(int, int));
 
 void set_file(const char* filename, char* setting, int maxlen);
diff --git a/apps/settings_list.c b/apps/settings_list.c
index a9cfd79..450d0ea 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -269,13 +269,14 @@
 
 #endif /* HAVE_RECORDING */
 
-static void formatter_unit_0_is_off(char *buffer, size_t buffer_size,
+static const char* formatter_unit_0_is_off(char *buffer, size_t buffer_size,
                                     int val, const char *unit)
 {
     if (val == 0)
-        strcpy(buffer, str(LANG_OFF));
+        return str(LANG_OFF);
     else
         snprintf(buffer, buffer_size, "%d %s", val, unit);
+    return buffer;
 }
 
 static int32_t getlang_unit_0_is_off(int value, int unit)
@@ -286,16 +287,17 @@
         return TALK_ID(value,unit);
 }
 
-static void formatter_unit_0_is_skip_track(char *buffer, size_t buffer_size,
+static const char* formatter_unit_0_is_skip_track(char *buffer, size_t buffer_size,
                                            int val, const char *unit)
 {
     (void)unit;
     if (val == 0)
-        strcpy(buffer, str(LANG_SKIP_TRACK));
+        return str(LANG_SKIP_TRACK);
     else if (val % 60 == 0)
         snprintf(buffer, buffer_size, "%d min", val/60);
     else
         snprintf(buffer, buffer_size, "%d s", val);
+    return buffer;
 }
 
 static int32_t getlang_unit_0_is_skip_track(int value, int unit)
@@ -310,15 +312,16 @@
 }
 
 #ifdef HAVE_BACKLIGHT
-static void backlight_formatter(char *buffer, size_t buffer_size,
+static const char* backlight_formatter(char *buffer, size_t buffer_size,
                                 int val, const char *unit)
 {
     if (val == -1)
-        strcpy(buffer, str(LANG_OFF));
+        return str(LANG_OFF);
     else if (val == 0)
-        strcpy(buffer, str(LANG_ON));
+        return str(LANG_ON);
     else
         snprintf(buffer, buffer_size, "%d %s", val, unit);
+    return buffer;
 }
 static int32_t backlight_getlang(int value, int unit)
 {
@@ -332,14 +335,15 @@
 #endif
 
 #ifndef HAVE_WHEEL_ACCELERATION
-static void scanaccel_formatter(char *buffer, size_t buffer_size,
+static const char* scanaccel_formatter(char *buffer, size_t buffer_size,
         int val, const char *unit)
 {
     (void)unit;
     if (val == 0)
-        strcpy(buffer, str(LANG_OFF));
+        return str(LANG_OFF);
     else
         snprintf(buffer, buffer_size, "2x/%ds", val);
+    return buffer;
 }
 #endif
 
@@ -352,13 +356,14 @@
                                   global_settings.crossfeed_hf_cutoff);
 }
 
-static void db_format(char* buffer, size_t buffer_size, int value,
+static const char* db_format(char* buffer, size_t buffer_size, int value,
                       const char* unit)
 {
     int v = abs(value);
 
     snprintf(buffer, buffer_size, "%s%d.%d %s", value < 0 ? "-" : "",
              v / 10, v % 10, unit);
+    return buffer;
 }
 
 static int32_t get_dec_talkid(int value, int unit)
@@ -384,27 +389,25 @@
 #endif
 
 #ifdef HAVE_LCD_CHARCELLS
-static void jumpscroll_format(char* buffer, size_t buffer_size, int value,
+static const char* jumpscroll_format(char* buffer, size_t buffer_size, int value,
                               const char* unit)
 {
     (void)unit;
     switch (value)
     {
         case 0:
-            strcpy(buffer, str(LANG_OFF));
-            break;
+            return str(LANG_OFF);
         case 1:
-            strcpy(buffer, str(LANG_ONE_TIME));
-            break;
+            return str(LANG_ONE_TIME);
         case 2:
         case 3:
         case 4:
             snprintf(buffer, buffer_size, "%d", value);
             break;
         case 5:
-            strcpy(buffer, str(LANG_ALWAYS));
-            break;
+            return str(LANG_ALWAYS);
     }
+    return buffer;
 }
 static int32_t jumpscroll_getlang(int value, int unit)
 {
diff --git a/apps/settings_list.h b/apps/settings_list.h
index 1bc529c..9f1805f 100644
--- a/apps/settings_list.h
+++ b/apps/settings_list.h
@@ -73,7 +73,7 @@
     int min;
     int max;
     int step;
-    void (*formatter)(char*, size_t, int, const char*);
+    const char* (*formatter)(char*, size_t, int, const char*);
     int32_t (*get_talk_id)(int, int);
 };
 #define F_INT_SETTING 0x80
@@ -92,7 +92,7 @@
                                
 struct table_setting {
     void (*option_callback)(int);
-    void (*formatter)(char*, size_t, int, const char*);
+    const char* (*formatter)(char*, size_t, int, const char*);
     int32_t (*get_talk_id)(int, int);
     int unit;
     int count;
diff --git a/apps/tree.c b/apps/tree.c
index 667aea0..228f491 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -106,8 +106,8 @@
 static void ft_play_filename(char *dir, char *file);
 static void say_filetype(int attr);
 
-static char * tree_get_filename(int selected_item, void *data,
-                                char *buffer, size_t buffer_len)
+static const char* tree_get_filename(int selected_item, void *data,
+                                     char *buffer, size_t buffer_len)
 {
     struct tree_context * local_tc=(struct tree_context *)data;
     char *name;