summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-11-15 23:29:01 -0500
committerWilliam Wilgus <wilgus.william@gmail.com>2022-11-15 23:33:39 -0500
commit28af87526d348b6f2d98dadfeb01011cd59dc709 (patch)
treed4298c4aafc7f4313edbb896b56ff147d7e97919
parent3ad8c0ad7ba9413d4179dc0bb698de0d1cdf28f3 (diff)
downloadrockbox-28af87526d.tar.gz
rockbox-28af87526d.zip
misc.c split_string replace with strtok_r
there isn't much difference from this function to strtok_r now places a NULL in the last vector space permitting as well Change-Id: Ibaaa1ad01b5054c41a6410788a2333b8d11a7cf7
-rw-r--r--apps/misc.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/apps/misc.c b/apps/misc.c
index 338ef9be19..fcdbb28fce 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -1384,20 +1384,16 @@ void format_time(char* buf, int buf_size, long t)
int split_string(char *str, const char split_char, char *vector[], const int vector_length)
{
int i;
- char *p = str;
-
- /* skip leading splitters */
- while(*p == split_char) p++;
+ char sep[2] = {split_char, '\0'};
+ char *e, *p = strtok_r(str, sep, &e);
/* *p in the condition takes care of trailing splitters */
- for(i = 0; p && *p && i < vector_length; i++)
+ for(i = 0; i < vector_length; i++)
{
vector[i] = p;
- if ((p = strchr(p, split_char)))
- {
- *p++ = '\0';
- while(*p == split_char) p++; /* skip successive splitters */
- }
+ if (!p)
+ break;
+ p = strtok_r(NULL, sep, &e);
}
return i;