[PATCH 07/13] utils/common: add str_token function

Eliad Peller eliad
Wed Oct 22 01:12:41 PDT 2014


On Wed, Oct 22, 2014 at 9:48 AM, Johannes Berg
<johannes at sipsolutions.net> wrote:
> On Tue, 2014-10-21 at 08:16 -0400, Ilan Peer wrote:
>> From: Eliad Peller <eliad at wizery.com>
>>
>> Add helper function to get next token from a string.
>
>> +/**
>> + * str_token - get next token from 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)
>
> Isn't that equivalent to strtok_r(), and could at least where that's
> available be implemented using it?
>
i don't like the strok_r usage syntax. the simple "while ((token =
str_token(...)))" seems much more comfortable for me.
i guess internally it could be implemented using strtok_r(), but i
don't see much advantage in it, and strtok_r is not defined for C99,
so i preferred implementing it.

Eliad.



More information about the Hostap mailing list