A common string library function implemented in Linux kernel

Source: Internet
Author: User
Tags strcmp

Only a subset of the commonly used Strcpy,strcmp,strcat,strchr,strstr,strpbrk... char *strcpy (char *dest, const char *src) {char *tmp = Dest;while ((*dest++ = *src++)! = ' + ')/* 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++)! = ' + '); return t MP;} 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 = ' + '; 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 = = ') ' 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! = '; ++s ') if (*s = = (char) c) return (char *) S;return NULL;} size_t strlen (const char *s) {const char *sc;for (sc = s; *sc! = '); ++sc)/* Nothing */;return sc-s;} Char *strpbrk (const char *CS, const char *ct) {const char *SC1, *sc2;for (SC1 = cs; *sc1! = '); ++sc1) {for (SC2 = ct; *s C2! = ' + '; ++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 = C T 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 (l 1 >= L2) {l1--;if (!memcmp (S1, S2, L2)) return (char *) s1;s1++;} return NULL;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.