From c23f56559fb7faad6e426c131bc26764420580fe Mon Sep 17 00:00:00 2001 From: Magnus Holmgren Date: Tue, 23 Jan 2007 19:54:09 +0000 Subject: [PATCH] Reduce stack usage in settings_write_config (by about 460 bytes). Should allow for a smaller ATA thread stack. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12095 a1c6a512-1295-4272-9138-f99709370657 --- apps/settings.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/apps/settings.c b/apps/settings.c index c7794e1015..1a7d159666 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -262,7 +262,7 @@ bool settings_write_config(char* filename) { int i; int fd; - char value[MAX_PATH]; + char value[MAX_FILENAME * 3]; /* More than enough for all current values */ fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY); if (fd < 0) return false; @@ -287,27 +287,38 @@ bool settings_write_config(char* filename) } else #endif - if (settings[i].cfg_vals == NULL) + if (settings[i].cfg_vals == NULL) { snprintf(value,MAX_PATH,"%d",*(int*)settings[i].setting); } else { - char *s,*end; - char vals[MAX_PATH]; + const char *s; + const char *end; int val = 0; - strncpy(vals,settings[i].cfg_vals,MAX_PATH); - s = strtok_r(vals,",",&end); - while (s) + + end = s = settings[i].cfg_vals; + + do { + while (*end != 0 && *end != ',') + { + end++; + } + if (val == *(int*)settings[i].setting) { - strncpy(value,s,MAX_PATH); + strncpy(value, s, end - s); + value[end - s] = 0; break; } - val++; - s = strtok_r(NULL,",",&end); + else + { + s = end + 1; + val++; + } } + while (*end++); } break; case F_T_BOOL: