improve function of strcat and strncat
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@483 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
d45d23a96a
commit
e02d3fe86e
|
@ -60,38 +60,34 @@ int strncmp(const char * cs,const char * ct,rt_ubase_t count)
|
||||||
return __res;
|
return __res;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* strcat(register char* s,register const char* t)
|
char *strcat(char * dest, const char * src)
|
||||||
{
|
{
|
||||||
char *dest = s;
|
char *tmp = dest;
|
||||||
|
|
||||||
s += strlen(s);
|
while (*dest)
|
||||||
for (;;)
|
dest++;
|
||||||
{
|
while ((*dest++ = *src++) != '\0')
|
||||||
if (!(*s = *t)) break;
|
;
|
||||||
++s;
|
|
||||||
++t;
|
return tmp;
|
||||||
}
|
|
||||||
|
|
||||||
return dest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strncat(char *s, const char *t, size_t n)
|
char *strncat(char *dest, const char *src, size_t count)
|
||||||
{
|
{
|
||||||
char *dest = s;
|
char *tmp = dest;
|
||||||
register char *max;
|
|
||||||
|
if (count) {
|
||||||
s += rt_strlen(s);
|
while (*dest)
|
||||||
if ((max=s+n)==s)
|
dest++;
|
||||||
goto fini;
|
while ((*dest++ = *src++)) {
|
||||||
for (;;)
|
if (--count == 0) {
|
||||||
{
|
*dest = '\0';
|
||||||
if (!(*s = *t)) break;
|
break;
|
||||||
if (++s==max) break;
|
}
|
||||||
++t;
|
}
|
||||||
}
|
}
|
||||||
*s=0;
|
|
||||||
fini:
|
return tmp;
|
||||||
return dest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strrchr(const char *t, int c)
|
char *strrchr(const char *t, int c)
|
||||||
|
|
|
@ -57,11 +57,11 @@ int strcasecmp(const char *a, const char *b);
|
||||||
int strncasecmp(const char *cs, const char *ct, size_t count);
|
int strncasecmp(const char *cs, const char *ct, size_t count);
|
||||||
int sscanf(const char * buf, const char * fmt, ...);
|
int sscanf(const char * buf, const char * fmt, ...);
|
||||||
size_t strlen(const char *s);
|
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 *strcpy(char *dest, const char *src);
|
||||||
char *strncpy(char *dest, const char *src, size_t n);
|
char *strncpy(char *dest, const char *src, size_t n);
|
||||||
char *strncat(char *s, const char *t, size_t n) ;
|
char *strncat(char *dest, const char *src, size_t count);
|
||||||
char* strcat(register char* s,register const char* t);
|
char *strcat(char * dest, const char * src);
|
||||||
char *strrchr(const char *t, int c);
|
char *strrchr(const char *t, int c);
|
||||||
char *strdup(const char *s);
|
char *strdup(const char *s);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue