*s = end; return sbegin;}EXPORT_SYMBOL(strsep);#endif #ifndef __HAVE_ARCH_MEMSET/** * memset - Fill a region of memory with the given value * @s: Pointer to the start of the area. * @c: The byte to fill the area with * @count: The size of the area. * * Do not use memset() to access IO space, use memset_io() instead. */void *memset(void *s, int c, size_t count){ char *xs = s; while (count--) *xs++ = c; return s;}EXPORT_SYMBOL(memset);#endif #ifndef __HAVE_ARCH_MEMSET16/** * memset16() - Fill a memory area with a uint16_t * @s: Pointer to the start of the area. * @v: The value to fill the area with * @count: The number of values to store * * Differs from memset() in that it fills with a uint16_t instead * of a byte. Remember that @count is the number of uint16_ts to * store, not the number of bytes. */void *memset16(uint16_t *s, uint16_t v, size_t count){ uint16_t *xs = s; while (count--) *xs++ = v; return s;}EXPORT_SYMBOL(memset16);#endif #ifndef __HAVE_ARCH_MEMSET32/** * memset32() - Fill a memory area with a uint32_t * @s: Pointer to the start of the area. * @v: The value to fill the area with * @count: The number of values to store * * Differs from memset() in that it fills with a uint32_t instead * of a byte. Remember that @count is the number of uint32_ts to * store, not the number of bytes. */void *memset32(uint32_t *s, uint32_t v, size_t count){ uint32_t *xs = s; while (count--) *xs++ = v; return s;}EXPORT_SYMBOL(memset32);#endif #ifndef __HAVE_ARCH_MEMSET64/** * memset64() - Fill a memory area with a uint64_t * @s: Pointer to the start of the area. * @v: The value to fill the area with * @count: The number of values to store * * Differs from memset() in that it fills with a uint64_t instead * of a byte. Remember that @count is the number of uint64_ts to * store, not the number of bytes. */void *memset64(uint64_t *s, uint64_t v, size_t count){ uint64_t *xs = s; while (count--) *xs++ = v; return s;}EXPORT_SYMBOL(memset64);#endif #ifndef __HAVE_ARCH_MEMCPY/** * memcpy - Copy one area of memory to another * @dest: Where to copy to * @src: Where to copy from * @count: The size of the area. * * You should not use this function to access IO space, use memcpy_toio() * or memcpy_fromio() instead. */void *memcpy(void *dest, const void *src, size_t count){ char *tmp = dest; const char *s = src; while (count--) *tmp++ = *s++; return dest;}EXPORT_SYMBOL(memcpy);#endif #ifndef __HAVE_ARCH_MEMMOVE/** * memmove - Copy one area of memory to another * @dest: Where to copy to * @src: Where to copy from * @count: The size of the area. * * Unlike memcpy(), memmove() copes with overlapping areas. */void *memmove(void *dest, const void *src, size_t count){ char *tmp; const char *s; if (dest <= src) { tmp = dest; s = src; while (count--) *tmp++ = *s++; } else { tmp = dest; tmp += count; s = src; s += count; while (count--) *--tmp = *--s; } return dest;}EXPORT_SYMBOL(memmove);#endif #ifndef __HAVE_ARCH_MEMCMP/** * memcmp - Compare two areas of memory * @cs: One area of memory * @ct: Another area of memory * @count: The size of the area. */#undef memcmp__visible int memcmp(const void *cs, const void *ct, size_t count){ const unsigned char *su1, *su2; int res = 0; #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS if (count >= sizeof(unsigned long)) { const unsigned long *u1 = cs; const unsigned long *u2 = ct; do { if (get_unaligned(u1) != get_unaligned(u2)) break; u1++; u2++; count -= sizeof(unsigned long); } while (count >= sizeof(unsigned long)); cs = u1; ct = u2; }#endif for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) if ((res = *su1 - *su2) != 0) break; return res;}EXPORT_SYMBOL(memcmp);#endif #ifndef __HAVE_ARCH_BCMP/** * bcmp - returns 0 if and only if the buffers have identical contents. * @a: pointer to first buffer. * @b: pointer to second buffer. * @len: size of buffers. * * The sign or magnitude of a non-zero return value has no particular * meaning, and architectures may implement their own more efficient bcmp(). So * while this particular implementation is a simple (tail) call to memcmp, do * not rely on anything but whether the return value is zero or non-zero. */int bcmp(const void *a, const void *b, size_t len){ return memcmp(a, b, len);}EXPORT_SYMBOL(bcmp);#endif #ifndef __HAVE_ARCH_MEMSCAN/** * memscan - Find a character in an area of memory. * @addr: The memory area * @c: The byte to search for * @size: The size of the area. * * returns the address of the first occurrence of @c, or 1 byte past * the area if @c is not found */void *memscan(void *addr, int c, size_t size){ unsigned char *p = addr; while (size) { if (*p == (unsigned char)c) return (void *)p; p++; size--; } return (void *)p;}EXPORT_SYMBOL(memscan);#endif #ifndef __HAVE_ARCH_STRSTR/** * strstr - Find the first substring in a %NUL terminated string * @s1: The string to be searched * @s2: The string to search for */char *strstr(const char *s1, const char *s2){ size_t 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;}EXPORT_SYMBOL(strstr);#endif #ifndef __HAVE_ARCH_STRNSTR/** * strnstr - Find the first substring in a length-limited string * @s1: The string to be searched * @s2: The string to search for * @len: the maximum number of characters to search */char *strnstr(const char *s1, const char *s2, size_t len){ size_t l2; l2 = strlen(s2); if (!l2) return (char *)s1; while (len >= l2) { len--; if (!memcmp(s1, s2, l2)) return (char *)s1; s1++; } return NULL;}EXPORT_SYMBOL(strnstr);#endif #ifndef __HAVE_ARCH_MEMCHR/** * memchr - Find a character in an area of memory. * @s: The memory area * @c: The byte to search for * @n: The size of the area. * * returns the address of the first occurrence of @c, or %NULL * if @c is not found */void *memchr(const void *s, int c, size_t n){ const unsigned char *p = s; while (n-- != 0) { if ((unsigned char)c == *p++) { return (void *)(p - 1); } } return NULL;}EXPORT_SYMBOL(memchr);#endif static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes){ while (bytes) { if (*start != value) return (void *)start; start++; bytes--; } return NULL;} /** * memchr_inv - Find an unmatching character in an area of memory. * @start: The memory area * @c: Find a character other than c * @bytes: The size of the area. * * returns the address of the first character other than @c, or %NULL * if the whole buffer contains just @c. */void *memchr_inv(const void *start, int c, size_t bytes){ u8 value = c; u64 value64; unsigned int words, prefix; if (bytes <= 16) return check_bytes8(start, value, bytes); value64 = value;#if defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64 value64 *= 0x0101010101010101ULL;#elif defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) value64 *= 0x01010101; value64 |= value64 << 32;#else value64 |= value64 << 8; value64 |= value64 << 16; value64 |= value64 << 32;#endif prefix = (unsigned long)start % 8; if (prefix) { u8 *r; prefix = 8 - prefix; r = check_bytes8(start, value, prefix); if (r) return r; start += prefix; bytes -= prefix; } words = bytes / 8; while (words) { if (*(u64 *)start != value64) return check_bytes8(start, value, 8); start += 8; words--; } return check_bytes8(start, value, bytes % 8);}EXPORT_SYMBOL(memchr_inv);Lines 501–864 of 864. Previous lines
*s = end; return sbegin; } EXPORT_SYMBOL(strsep); #endif #ifndef __HAVE_ARCH_MEMSET /** * memset - Fill a region of memory with the given value * @s: Pointer to the start of the area. * @c: The byte to fill the area with * @count: The size of the area. * * Do not use memset() to access IO space, use memset_io() instead. */ void *memset(void *s, int c, size_t count) { char *xs = s; while (count--) *xs++ = c; return s; } EXPORT_SYMBOL(memset); #endif #ifndef __HAVE_ARCH_MEMSET16 /** * memset16() - Fill a memory area with a uint16_t * @s: Pointer to the start of the area. * @v: The value to fill the area with * @count: The number of values to store * * Differs from memset() in that it fills with a uint16_t instead * of a byte. Remember that @count is the number of uint16_ts to * store, not the number of bytes. */ void *memset16(uint16_t *s, uint16_t v, size_t count) { uint16_t *xs = s; while (count--) *xs++ = v; return s; } EXPORT_SYMBOL(memset16); #endif #ifndef __HAVE_ARCH_MEMSET32 /** * memset32() - Fill a memory area with a uint32_t * @s: Pointer to the start of the area. * @v: The value to fill the area with * @count: The number of values to store * * Differs from memset() in that it fills with a uint32_t instead * of a byte. Remember that @count is the number of uint32_ts to * store, not the number of bytes. */ void *memset32(uint32_t *s, uint32_t v, size_t count) { uint32_t *xs = s; while (count--) *xs++ = v; return s; } EXPORT_SYMBOL(memset32); #endif #ifndef __HAVE_ARCH_MEMSET64 /** * memset64() - Fill a memory area with a uint64_t * @s: Pointer to the start of the area. * @v: The value to fill the area with * @count: The number of values to store * * Differs from memset() in that it fills with a uint64_t instead * of a byte. Remember that @count is the number of uint64_ts to * store, not the number of bytes. */ void *memset64(uint64_t *s, uint64_t v, size_t count) { uint64_t *xs = s; while (count--) *xs++ = v; return s; } EXPORT_SYMBOL(memset64); #endif #ifndef __HAVE_ARCH_MEMCPY /** * memcpy - Copy one area of memory to another * @dest: Where to copy to * @src: Where to copy from * @count: The size of the area. * * You should not use this function to access IO space, use memcpy_toio() * or memcpy_fromio() instead. */ void *memcpy(void *dest, const void *src, size_t count) { char *tmp = dest; const char *s = src; while (count--) *tmp++ = *s++; return dest; } EXPORT_SYMBOL(memcpy); #endif #ifndef __HAVE_ARCH_MEMMOVE /** * memmove - Copy one area of memory to another * @dest: Where to copy to * @src: Where to copy from * @count: The size of the area. * * Unlike memcpy(), memmove() copes with overlapping areas. */ void *memmove(void *dest, const void *src, size_t count) { char *tmp; const char *s; if (dest <= src) { tmp = dest; s = src; while (count--) *tmp++ = *s++; } else { tmp = dest; tmp += count; s = src; s += count; while (count--) *--tmp = *--s; } return dest; } EXPORT_SYMBOL(memmove); #endif #ifndef __HAVE_ARCH_MEMCMP /** * memcmp - Compare two areas of memory * @cs: One area of memory * @ct: Another area of memory * @count: The size of the area. */ #undef memcmp __visible int memcmp(const void *cs, const void *ct, size_t count) { const unsigned char *su1, *su2; int res = 0; #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS if (count >= sizeof(unsigned long)) { const unsigned long *u1 = cs; const unsigned long *u2 = ct; do { if (get_unaligned(u1) != get_unaligned(u2)) break; u1++; u2++; count -= sizeof(unsigned long); } while (count >= sizeof(unsigned long)); cs = u1; ct = u2; } #endif for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) if ((res = *su1 - *su2) != 0) break; return res; } EXPORT_SYMBOL(memcmp); #endif #ifndef __HAVE_ARCH_BCMP /** * bcmp - returns 0 if and only if the buffers have identical contents. * @a: pointer to first buffer. * @b: pointer to second buffer. * @len: size of buffers. * * The sign or magnitude of a non-zero return value has no particular * meaning, and architectures may implement their own more efficient bcmp(). So * while this particular implementation is a simple (tail) call to memcmp, do * not rely on anything but whether the return value is zero or non-zero. */ int bcmp(const void *a, const void *b, size_t len) { return memcmp(a, b, len); } EXPORT_SYMBOL(bcmp); #endif #ifndef __HAVE_ARCH_MEMSCAN /** * memscan - Find a character in an area of memory. * @addr: The memory area * @c: The byte to search for * @size: The size of the area. * * returns the address of the first occurrence of @c, or 1 byte past * the area if @c is not found */ void *memscan(void *addr, int c, size_t size) { unsigned char *p = addr; while (size) { if (*p == (unsigned char)c) return (void *)p; p++; size--; } return (void *)p; } EXPORT_SYMBOL(memscan); #endif #ifndef __HAVE_ARCH_STRSTR /** * strstr - Find the first substring in a %NUL terminated string * @s1: The string to be searched * @s2: The string to search for */ char *strstr(const char *s1, const char *s2) { size_t 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; } EXPORT_SYMBOL(strstr); #endif #ifndef __HAVE_ARCH_STRNSTR /** * strnstr - Find the first substring in a length-limited string * @s1: The string to be searched * @s2: The string to search for * @len: the maximum number of characters to search */ char *strnstr(const char *s1, const char *s2, size_t len) { size_t l2; l2 = strlen(s2); if (!l2) return (char *)s1; while (len >= l2) { len--; if (!memcmp(s1, s2, l2)) return (char *)s1; s1++; } return NULL; } EXPORT_SYMBOL(strnstr); #endif #ifndef __HAVE_ARCH_MEMCHR /** * memchr - Find a character in an area of memory. * @s: The memory area * @c: The byte to search for * @n: The size of the area. * * returns the address of the first occurrence of @c, or %NULL * if @c is not found */ void *memchr(const void *s, int c, size_t n) { const unsigned char *p = s; while (n-- != 0) { if ((unsigned char)c == *p++) { return (void *)(p - 1); } } return NULL; } EXPORT_SYMBOL(memchr); #endif static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes) { while (bytes) { if (*start != value) return (void *)start; start++; bytes--; } return NULL; } /** * memchr_inv - Find an unmatching character in an area of memory. * @start: The memory area * @c: Find a character other than c * @bytes: The size of the area. * * returns the address of the first character other than @c, or %NULL * if the whole buffer contains just @c. */ void *memchr_inv(const void *start, int c, size_t bytes) { u8 value = c; u64 value64; unsigned int words, prefix; if (bytes <= 16) return check_bytes8(start, value, bytes); value64 = value; #if defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64 value64 *= 0x0101010101010101ULL; #elif defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) value64 *= 0x01010101; value64 |= value64 << 32; #else value64 |= value64 << 8; value64 |= value64 << 16; value64 |= value64 << 32; #endif prefix = (unsigned long)start % 8; if (prefix) { u8 *r; prefix = 8 - prefix; r = check_bytes8(start, value, prefix); if (r) return r; start += prefix; bytes -= prefix; } words = bytes / 8; while (words) { if (*(u64 *)start != value64) return check_bytes8(start, value, 8); start += 8; words--; } return check_bytes8(start, value, bytes % 8); } EXPORT_SYMBOL(memchr_inv);