VC源码:
char * __cdecl strcat (char * dst, const char * src)
{
char * cp = dst;
while( *cp )
cp++; /* find end of dst */
while( *cp++ = *src++ ) ; /* Copy src to end of dst */
return( dst ); /* return dst */
}
linux 下 glibc 2.9下
/* Append SRC onto DEST.
*/
#define _HAVE_STRING_ARCH_strcat 1
#define strcat(dest, src) \
(__extension__ (__builtin_constant_p (src)
\
? __strcat_c ((dest), (src), strlen (src) + 1)
\
: __strcat_g ((dest), (src))))
__STRING_INLINE char *__strcat_c (char *__dest, __const char __src[],
size_t __srclen);
__STRING_INLINE char *
__strcat_c (char *__dest, __const char __src[], size_t __srclen)
{
#ifdef __i686__
register unsigned long int __d0;
register char *__tmp;
__asm__ __volatile__
////内联汇编
("repne; scasb"
: "=D" (__tmp), "=&c" (__d0),
"=m" ( *(struct { char __x[0xfffffff]; } *)__dest)
: "0" (__dest), "1" (0xffffffff), "a" (0),
"m" ( *(struct { __extension__ char __x[__srclen]; } *)__src)
: "cc");
--__tmp;
#else
register char *__tmp = __dest - 1;
__asm__ __volatile__
("1:\n\t"
"incl
%0\n\t"
"cmpb
$0,(%0)\n\t"
"jne
1b\n"
: "=r" (__tmp),
"=m" ( *(struct { char __x[0xfffffff]; } *)__dest)
: "0" (__tmp),
"m" ( *(struct { __extension__ char __x[__srclen]; } *)__src)
: "cc");
#endif
(void) memcpy (__tmp, __src, __srclen);
return __dest;
}
__STRING_INLINE char *__strcat_g (char *__dest, __const char *__src);
__STRING_INLINE char *
__strcat_g (char *__dest, __const char *__src)
{
register char *__tmp = __dest - 1;
register char __dummy;
__asm__ __volatile__
("1:\n\t"
"incl
%1\n\t"
"cmpb
$0,(%1)\n\t"
"jne
1b\n"
"2:\n\t"
"movb
(%2),%b0\n\t"
"incl
%2\n\t"
"movb
%b0,(%1)\n\t"
"incl
%1\n\t"
"testb
%b0,%b0\n\t"
"jne
2b\n"
: "=&q" (__dummy), "=&r" (__tmp), "=&r" (__src),
"=m" ( *(struct { char __x[0xfffffff]; } *)__dest)
: "1"
(__tmp), "2"
(__src),
"m" ( *(struct { char __x[0xfffffff]; } *)__src)
: "memory", "cc");
return __dest;
}