From bc013f8a8300b901a46c3c8a6f667a398d9fb0a4 Mon Sep 17 00:00:00 2001 From: "bernard.xiong" Date: Wed, 24 Mar 2010 07:33:00 +0000 Subject: [PATCH] add strchr and strtok implementation. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@532 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- libc/minilibc/string.c | 57 ++++++++++++++++++++++++++++++++++++++++++ libc/minilibc/string.h | 3 +++ 2 files changed, 60 insertions(+) diff --git a/libc/minilibc/string.c b/libc/minilibc/string.c index 2de4f20790..179cd07b88 100644 --- a/libc/minilibc/string.c +++ b/libc/minilibc/string.c @@ -13,6 +13,7 @@ * 2010-02-15 Gary Lee add strlcpy * 2010-03-17 Bernard add strlcpy implementation to this file. * fix strlcpy declaration + * 2010-03-24 Bernard add strchr and strtok implementation. */ #include @@ -548,4 +549,60 @@ int sscanf(const char * buf, const char * fmt, ...) return i; } +size_t strspn(const char *s, const char *accept) +{ + size_t l=0; + int a=1,i, al=strlen(accept); + + while((a)&&(*s)) + { + for(a=i=0;(!a)&&(i terminate it */ + } + *ptrptr=s; + return tmp; +} + +char *strtok(char *s, const char *delim) +{ + static char *strtok_pos; + return strtok_r(s,delim,&strtok_pos); +} + +char *strchr(const char *s1, int i) +{ + const unsigned char *s = (const unsigned char *)s1; + unsigned char c = (unsigned int)i; + + while (*s && *s != c) + { + s++; + } + + if (*s != c) + { + s = NULL; + } + + return (char *) s; +} + #endif diff --git a/libc/minilibc/string.h b/libc/minilibc/string.h index defffdcaee..19b1cbfc07 100644 --- a/libc/minilibc/string.h +++ b/libc/minilibc/string.h @@ -64,8 +64,11 @@ char *strncpy(char *dest, const char *src, size_t n); size_t strlcpy(char *dst, const char *src, size_t siz); char *strncat(char *dest, const char *src, size_t count); char *strcat(char * dest, const char * src); +char *strchr(const char *s1, int i); char *strrchr(const char *t, int c); char *strdup(const char *s); +char *strtok(char *s, const char *delim); +char*strtok_r(char*s, const char*delim, char**ptrptr); #endif