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
This commit is contained in:
William Wilgus 2022-11-15 23:29:01 -05:00
parent 3ad8c0ad7b
commit 28af87526d

View file

@ -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;