Chinaunix首页 | 论坛 | 博客
  • 博客访问: 795311
  • 博文数量: 106
  • 博客积分: 1250
  • 博客等级: 少尉
  • 技术积分: 1349
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-09 09:38
文章分类

全部博文(106)

文章存档

2014年(1)

2013年(13)

2012年(92)

分类: LINUX

2012-02-21 18:39:03

  1. #ifndef __HAVE_ARCH_STRPBRK  
  2. /** 
  3.  * strpbrk - Find the first occurrence of a set of characters 
  4.  * @cs: The string to be searched 
  5.  * @ct: The characters to search for 
  6.  */  
  7. char *strpbrk(const char *cs, const char *ct)  
  8. {  
  9.     const char *sc1, *sc2;  
  10.   
  11.     for (sc1 = cs; *sc1 != '\0'; ++sc1) {  
  12.         for (sc2 = ct; *sc2 != '\0'; ++sc2) {  
  13.             if (*sc1 == *sc2)  
  14.                 return (char *)sc1;  
  15.         }  
  16.     }  
  17.     return NULL;  
  18. }  
  19. EXPORT_SYMBOL(strpbrk);  
  20. #endif  
  21.   
  22. #ifndef __HAVE_ARCH_STRSEP  
  23. /** 
  24.  * strsep - Split a string into tokens 
  25.  * @s: The string to be searched 
  26.  * @ct: The characters to search for 
  27.  * 
  28.  * strsep() updates @s to point after the token, ready for the next call. 
  29.  * 
  30.  * It returns empty tokens, too, behaving exactly like the libc function 
  31.  * of that name. In fact, it was stolen from glibc2 and de-fancy-fied. 
  32.  * Same semantics, slimmer shape. ;) 
  33.  */  
  34. char *strsep(char **s, const char *ct)  
  35. {  
  36.     char *sbegin = *s;  
  37.     char *end;  
  38.   
  39.     if (sbegin == NULL)  
  40.         return NULL;  
  41.   
  42.     end = strpbrk(sbegin, ct);  
  43.     if (end)  
  44.         *end++ = '\0';  
  45.     *s = end;  
  46.     return sbegin;  
  47. }  
  48. EXPORT_SYMBOL(strsep);  
  49. #endif  

阅读(4913) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~