]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add str_token() function
authorEliad Peller <eliad@wizery.com>
Wed, 22 Oct 2014 12:03:58 +0000 (08:03 -0400)
committerJouni Malinen <j@w1.fi>
Sun, 16 Nov 2014 19:11:23 +0000 (21:11 +0200)
Add helper function to get the next token from a string.

Signed-off-by: Eliad Peller <eliadx.peller@intel.com>
src/utils/common.c
src/utils/common.h

index 9902004917966c1b03d08d818476ce79d041e1fc..26c401c7097e3c5c839f969a23b9a71990fb49af 100644 (file)
@@ -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;
+}
index 6efe8090183dd43762788d677c104b70974fdb7e..284e7e5cf1fa84e12ae9179e90c46afa36efa46a 100644 (file)
@@ -537,13 +537,14 @@ void int_array_add_unique(int **res, int a);
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
-
 void str_clear_free(char *str);
 void bin_clear_free(void *bin, size_t len);
 
 int random_mac_addr(u8 *addr);
 int random_mac_addr_keep_oui(u8 *addr);
 
+char * str_token(char *str, const char *delim, char **context);
+
 
 /*
  * gcc 4.4 ends up generating strict-aliasing warnings about some very common