toaruos/kernel/misc/tokenize.c

27 lines
658 B
C
Raw Normal View History

2021-05-31 04:47:02 +03:00
/**
* @file kernel/misc/tokenize.c
* @brief Wrapper around strtok_r, used to turn strings into arrays.
*
* @copyright
* This file is part of ToaruOS and is released under the terms
* of the NCSA / University of Illinois License - see LICENSE.md
* Copyright (C) 2015-2021 K. Lange
2018-03-16 15:56:19 +03:00
*/
2021-05-31 04:47:02 +03:00
#include <kernel/string.h>
2018-03-19 05:38:11 +03:00
#include <kernel/tokenize.h>
2018-03-16 15:56:19 +03:00
2021-05-31 04:47:02 +03:00
int tokenize(char * str, const char * sep, char **buf) {
2018-03-16 15:56:19 +03:00
char * pch_i;
char * save_i;
int argc = 0;
pch_i = strtok_r(str,sep,&save_i);
if (!pch_i) { return 0; }
while (pch_i != NULL) {
buf[argc] = (char *)pch_i;
++argc;
pch_i = strtok_r(NULL,sep,&save_i);
}
buf[argc] = NULL;
return argc;
}