以下代码来自linux-2.6.38
1、strcat
在lib/string.c中实现。
1 /**
2 * strcat - Append one %NUL-terminated string to another
3 * @dest: The string to be appended to
4 * @src: The string to append to it
5 */
6
7 char *strcat(char *dest, const char *src)
8 {
9 char *tmp = dest;
10
11 while (*dest)
12 dest++;
13 while ((*dest++ = *src++) != '\0')
14 ;
15 return tmp;
16 }
2、strcpy
在lib/string.c中实现。
1 /** 2 * strcpy - Copy a %NUL terminated string 3 * @dest: Where to copy the string to 4 * @src: Where to copy the string from 5 */ 6 char *strcpy(char *dest, const char *src) 7 { 8 char *tmp = dest; 9 10 while ((*dest++ = *src++) != '\0') 11 /* nothing */; 12 return tmp; 13 }
3、strcmp
在lib/string.c中实现。
1 /** 2 * strcmp - Compare two strings 3 * @cs: One string 4 * @ct: Another string 5 */ 6 int strcmp(const char *cs, const char *ct) 7 { 8 unsigned char c1, c2; 9 10 while (1) { 11 c1 = *cs++; 12 c2 = *ct++; 13 if (c1 != c2) 14 return c1 < c2 ? -1 : 1; 15 if (!c1) 16</