Add str_token() function
Add helper function to get the next token from a string. Signed-off-by: Eliad Peller <eliadx.peller@intel.com>
This commit is contained in:
parent
d1f880013a
commit
1b640fd27c
2 changed files with 34 additions and 1 deletions
|
@ -866,3 +866,35 @@ int random_mac_addr_keep_oui(u8 *addr)
|
|||
addr[0] |= 0x02; /* locally administered */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* str_token - Get next token from a string
|
||||
* @buf: String to tokenize. Note that the string might be modified.
|
||||
* @delim: String of delimiters
|
||||
* @context: Pointer to save our context. Should be initialized with
|
||||
* NULL on the first call, and passed for any further call.
|
||||
* Returns: The next token, NULL if there are no more valid tokens.
|
||||
*/
|
||||
char * str_token(char *str, const char *delim, char **context)
|
||||
{
|
||||
char *end, *pos = str;
|
||||
|
||||
if (*context)
|
||||
pos = *context;
|
||||
|
||||
while (*pos && os_strchr(delim, *pos))
|
||||
pos++;
|
||||
if (!*pos)
|
||||
return NULL;
|
||||
|
||||
end = pos + 1;
|
||||
while (*end && !os_strchr(delim, *end))
|
||||
end++;
|
||||
|
||||
if (*end)
|
||||
*end++ = '\0';
|
||||
|
||||
*context = end;
|
||||
return pos;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue