strcat,strcpy,strcmp,strstr,memset,memcpy,strsep在内核中的实现

以下代码来自linux-2.6.381、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 appen
摘要由CSDN通过智能技术生成
以下代码来自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</
  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值