string: add strtok
This commit is contained in:
parent
aeb2781baf
commit
5ab34eb11b
2 changed files with 24 additions and 1 deletions
|
|
@ -4,12 +4,14 @@
|
||||||
|
|
||||||
#ifndef __ASM__
|
#ifndef __ASM__
|
||||||
|
|
||||||
#include <kernel/common.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
void *memcpy(void *dest, const void *src, size_t num);
|
void *memcpy(void *dest, const void *src, size_t num);
|
||||||
int memcmp(const void *aa, const void *bb, size_t num);
|
int memcmp(const void *aa, const void *bb, size_t num);
|
||||||
void *memset(void *str, int c, size_t n);
|
void *memset(void *str, int c, size_t n);
|
||||||
char *strcpy(char *dest, const char *src);
|
char *strcpy(char *dest, const char *src);
|
||||||
|
char *strtok(char *str, const char *delim);
|
||||||
char **strsplit(const char *str, char delim, int *num);
|
char **strsplit(const char *str, char delim, int *num);
|
||||||
size_t strlen(const char *c);
|
size_t strlen(const char *c);
|
||||||
int atoi(const char *a);
|
int atoi(const char *a);
|
||||||
|
|
|
||||||
21
lib/string.c
21
lib/string.c
|
|
@ -86,6 +86,27 @@ char *strchr(const char *s, int c)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *strtok(char *str, const char *delim)
|
||||||
|
{
|
||||||
|
static char *last = NULL;
|
||||||
|
if (str)
|
||||||
|
last = str;
|
||||||
|
|
||||||
|
if (!last)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
char *ret = last;
|
||||||
|
while (*last) {
|
||||||
|
if (strchr(delim, *last)) {
|
||||||
|
*last = 0;
|
||||||
|
last++;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
last++;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
char **strsplit(const char *s, char delim, int *n)
|
char **strsplit(const char *s, char delim, int *n)
|
||||||
{
|
{
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue