summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorgary.li.wenchao.4 <[email protected]>2010-03-14 12:00:55 +0000
committergary.li.wenchao.4 <[email protected]>2010-03-14 12:00:55 +0000
commite02d3fe86ec7a80e771ba57416a002d65c8d662a (patch)
tree63f589791066ee7f3be0362aae023872530bdc6d /libc
parentd45d23a96a977b87941dd2090a06b45be0ef1750 (diff)
improve function of strcat and strncat
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@483 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'libc')
-rw-r--r--libc/minilibc/string.c50
-rw-r--r--libc/minilibc/string.h6
2 files changed, 26 insertions, 30 deletions
diff --git a/libc/minilibc/string.c b/libc/minilibc/string.c
index 0b1d893f2a..3eac377c7a 100644
--- a/libc/minilibc/string.c
+++ b/libc/minilibc/string.c
@@ -60,38 +60,34 @@ int strncmp(const char * cs,const char * ct,rt_ubase_t count)
return __res;
}
-char* strcat(register char* s,register const char* t)
+char *strcat(char * dest, const char * src)
{
- char *dest = s;
-
- s += strlen(s);
- for (;;)
- {
- if (!(*s = *t)) break;
- ++s;
- ++t;
- }
-
- return dest;
+ char *tmp = dest;
+
+ while (*dest)
+ dest++;
+ while ((*dest++ = *src++) != '\0')
+ ;
+
+ return tmp;
}
-char *strncat(char *s, const char *t, size_t n)
+char *strncat(char *dest, const char *src, size_t count)
{
- char *dest = s;
- register char *max;
-
- s += rt_strlen(s);
- if ((max=s+n)==s)
- goto fini;
- for (;;)
- {
- if (!(*s = *t)) break;
- if (++s==max) break;
- ++t;
+ char *tmp = dest;
+
+ if (count) {
+ while (*dest)
+ dest++;
+ while ((*dest++ = *src++)) {
+ if (--count == 0) {
+ *dest = '\0';
+ break;
+ }
+ }
}
- *s=0;
-fini:
- return dest;
+
+ return tmp;
}
char *strrchr(const char *t, int c)
diff --git a/libc/minilibc/string.h b/libc/minilibc/string.h
index 2435334170..93594dc64f 100644
--- a/libc/minilibc/string.h
+++ b/libc/minilibc/string.h
@@ -57,11 +57,11 @@ int strcasecmp(const char *a, const char *b);
int strncasecmp(const char *cs, const char *ct, size_t count);
int sscanf(const char * buf, const char * fmt, ...);
size_t strlen(const char *s);
-char * strstr(const char * s1,const char * s2);
+char *strstr(const char * s1,const char * s2);
char *strcpy(char *dest, const char *src);
char *strncpy(char *dest, const char *src, size_t n);
-char *strncat(char *s, const char *t, size_t n) ;
-char* strcat(register char* s,register const char* t);
+char *strncat(char *dest, const char *src, size_t count);
+char *strcat(char * dest, const char * src);
char *strrchr(const char *t, int c);
char *strdup(const char *s);