Linux内核中常用String库函数实现
来源:互联网 发布:星际争霸2机枪兵数据 编辑:程序博客网 时间:2024/04/29 09:58
//只列举了部分常用的strcpy,strcmp,strcat,strchr,strstr,strpbrk... char *strcpy(char *dest, const char *src){char *tmp = dest;while ((*dest++ = *src++) != '\0')/* nothing */;return tmp;}char *strncpy(char *dest, const char *src, size_t count){char *tmp = dest;while (count) {if ((*tmp = *src) != 0)src++;tmp++;count--;}return dest;}char *strcat(char *dest, const char *src){char *tmp = dest;while (*dest)dest++;while ((*dest++ = *src++) != '\0');return tmp;}char *strncat(char *dest, const char *src, size_t count){char *tmp = dest;if (count) {while (*dest)dest++;while ((*dest++ = *src++) != 0) {if (--count == 0) {*dest = '\0';break;}}}return tmp;}int strcmp(const char *cs, const char *ct){signed char __res;while (1) {if ((__res = *cs - *ct++) != 0 || !*cs++)break;}return __res;}int strncmp(const char *cs, const char *ct, size_t count){signed char __res = 0;while (count) {if ((__res = *cs - *ct++) != 0 || !*cs++)break;count--;}return __res;}char *strchr(const char *s, int c){for (; *s != (char)c; ++s)if (*s == '\0')return NULL;return (char *)s;}char *strrchr(const char *s, int c){ const char *p = s + strlen(s); do { if (*p == (char)c) return (char *)p; } while (--p >= s); return NULL;}char *strnchr(const char *s, size_t count, int c){for (; count-- && *s != '\0'; ++s)if (*s == (char)c)return (char *)s;return NULL;}size_t strlen(const char *s){const char *sc;for (sc = s; *sc != '\0'; ++sc)/* nothing */;return sc - s;}char *strpbrk(const char *cs, const char *ct){const char *sc1, *sc2;for (sc1 = cs; *sc1 != '\0'; ++sc1) {for (sc2 = ct; *sc2 != '\0'; ++sc2) {if (*sc1 == *sc2)return (char *)sc1;}}return NULL;}void *memcpy(void *dest, const void *src, size_t count){char *tmp = dest;const char *s = src;while (count--)*tmp++ = *s++;return dest;}int memcmp(const void *cs, const void *ct, size_t count){const unsigned char *su1, *su2;int res = 0;for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)if ((res = *su1 - *su2) != 0)break;return res;}char *strstr(const char *s1, const char *s2){int l1, l2;l2 = strlen(s2);if (!l2)return (char *)s1;l1 = strlen(s1);while (l1 >= l2) {l1--;if (!memcmp(s1, s2, l2))return (char *)s1;s1++;}return NULL;}
0 0
- Linux内核中常用String库函数实现
- linux中string库函数的实现,笔试时常考
- LINUX内核中string函数实现
- string.h中库函数的实现
- C中常用库函数的简单实现
- linux 内核库函数
- Linux内核库函数
- linux 内核库函数
- linux 内核库函数
- 模拟实现string库函数
- 常用库函数的实现
- C常用库函数实现
- linux常用库函数
- string.h中库函数的实现代码(部分)
- linux下的string库函数
- linux c string库函数总结
- C语言中String库函数
- C语言中String库函数
- ASP.NET获取客户端IP及MAC地址
- MyEclipse 8.5安装Aptana
- android 屏幕适配
- int main(int argc,char* argv[])详解
- POJ--1087--A Plug for UNIX【Dinic】网络最大流
- Linux内核中常用String库函数实现
- 牛人也得看的15个CSS常识(转)
- Codeforces Round #260 (Div. 1)B题(字典树+DFS+博弈)
- C++ 虚拟基类
- hdu-2187
- FZU1759 Super A^B mod C(快速幂求余+ a^b%c = a^( b%phic+phic )%c)
- Web开发小技巧
- JSP验证码
- 大数相乘