summaryrefslogtreecommitdiff
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-28af87526d348b6f2d98dadfeb01011cd59dc709.tar.gz
rockbox-28af87526d348b6f2d98dadfeb01011cd59dc709.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)
1384int split_string(char *str, const char split_char, char *vector[], const int vector_length) 1384int split_string(char *str, const char split_char, char *vector[], const int vector_length)
1385{ 1385{
1386 int i; 1386 int i;
1387 char *p = str; 1387 char sep[2] = {split_char, '\0'};
1388 1388 char *e, *p = strtok_r(str, sep, &e);
1389 /* skip leading splitters */
1390 while(*p == split_char) p++;
1391 1389
1392 /* *p in the condition takes care of trailing splitters */ 1390 /* *p in the condition takes care of trailing splitters */
1393 for(i = 0; p && *p && i < vector_length; i++) 1391 for(i = 0; i < vector_length; i++)
1394 { 1392 {
1395 vector[i] = p; 1393 vector[i] = p;
1396 if ((p = strchr(p, split_char))) 1394 if (!p)
1397 { 1395 break;
1398 *p++ = '\0'; 1396 p = strtok_r(NULL, sep, &e);
1399 while(*p == split_char) p++; /* skip successive splitters */
1400 }
1401 } 1397 }
1402 1398
1403 return i; 1399 return i;