1131 lines · 24.7 KB · C
RawDownload
char *skip_spaces(const char *str){	while (isspace(*str))		++str;	return (char *)str;}EXPORT_SYMBOL(skip_spaces); /** * strim - Removes leading and trailing whitespace from @s. * @s: The string to be stripped. * * Note that the first trailing whitespace is replaced with a %NUL-terminator * in the given string @s. Returns a pointer to the first non-whitespace * character in @s. */char *strim(char *s){	size_t size;	char *end; 	size = strlen(s);	if (!size)		return s; 	end = s + size - 1;	while (end >= s && isspace(*end))		end--;	*(end + 1) = '\0'; 	return skip_spaces(s);}EXPORT_SYMBOL(strim); #ifndef __HAVE_ARCH_STRLEN/** * strlen - Find the length of a string * @s: The string to be sized */size_t strlen(const char *s){	const char *sc; 	for (sc = s; *sc != '\0'; ++sc)		/* nothing */;	return sc - s;}EXPORT_SYMBOL(strlen);#endif #ifndef __HAVE_ARCH_STRNLEN/** * strnlen - Find the length of a length-limited string * @s: The string to be sized * @count: The maximum number of bytes to search */size_t strnlen(const char *s, size_t count){	const char *sc; 	for (sc = s; count-- && *sc != '\0'; ++sc)		/* nothing */;	return sc - s;}EXPORT_SYMBOL(strnlen);#endif #ifndef __HAVE_ARCH_STRSPN/** * strspn - Calculate the length of the initial substring of @s which only contain letters in @accept * @s: The string to be searched * @accept: The string to search for */size_t strspn(const char *s, const char *accept){	const char *p;	const char *a;	size_t count = 0; 	for (p = s; *p != '\0'; ++p) {		for (a = accept; *a != '\0'; ++a) {			if (*p == *a)				break;		}		if (*a == '\0')			return count;		++count;	}	return count;} EXPORT_SYMBOL(strspn);#endif #ifndef __HAVE_ARCH_STRCSPN/** * strcspn - Calculate the length of the initial substring of @s which does not contain letters in @reject * @s: The string to be searched * @reject: The string to avoid */size_t strcspn(const char *s, const char *reject){	const char *p;	const char *r;	size_t count = 0; 	for (p = s; *p != '\0'; ++p) {		for (r = reject; *r != '\0'; ++r) {			if (*p == *r)				return count;		}		++count;	}	return count;}EXPORT_SYMBOL(strcspn);#endif #ifndef __HAVE_ARCH_STRPBRK/** * strpbrk - Find the first occurrence of a set of characters * @cs: The string to be searched * @ct: The characters to search for */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;}EXPORT_SYMBOL(strpbrk);#endif #ifndef __HAVE_ARCH_STRSEP/** * strsep - Split a string into tokens * @s: The string to be searched * @ct: The characters to search for * * strsep() updates @s to point after the token, ready for the next call. * * It returns empty tokens, too, behaving exactly like the libc function * of that name. In fact, it was stolen from glibc2 and de-fancy-fied. * Same semantics, slimmer shape. ;) */char *strsep(char **s, const char *ct){	char *sbegin = *s;	char *end; 	if (sbegin == NULL)		return NULL; 	end = strpbrk(sbegin, ct);	if (end)		*end++ = '\0';	*s = end;	return sbegin;}EXPORT_SYMBOL(strsep);#endif /** * sysfs_streq - return true if strings are equal, modulo trailing newline * @s1: one string * @s2: another string * * This routine returns true iff two strings are equal, treating both * NUL and newline-then-NUL as equivalent string terminations.  It's * geared for use with sysfs input strings, which generally terminate * with newlines but are compared against values without newlines. */bool sysfs_streq(const char *s1, const char *s2){	while (*s1 && *s1 == *s2) {		s1++;		s2++;	} 	if (*s1 == *s2)		return true;	if (!*s1 && *s2 == '\n' && !s2[1])		return true;	if (*s1 == '\n' && !s1[1] && !*s2)		return true;	return false;}EXPORT_SYMBOL(sysfs_streq); /** * match_string - matches given string in an array * @array:	array of strings * @n:		number of strings in the array or -1 for NULL terminated arrays * @string:	string to match with * * This routine will look for a string in an array of strings up to the * n-th element in the array or until the first NULL element. * * Historically the value of -1 for @n, was used to search in arrays that * are NULL terminated. However, the function does not make a distinction * when finishing the search: either @n elements have been compared OR * the first NULL element was found. * * Return: * index of a @string in the @array if matches, or %-EINVAL otherwise. */int match_string(const char * const *array, size_t n, const char *string){	int index;	const char *item; 	for (index = 0; index < n; index++) {		item = array[index];		if (!item)			break;		if (!strcmp(item, string))			return index;	} 	return -EINVAL;}EXPORT_SYMBOL(match_string); /** * __sysfs_match_string - matches given string in an array * @array: array of strings * @n: number of strings in the array or -1 for NULL terminated arrays * @str: string to match with * * Returns index of @str in the @array or -EINVAL, just like match_string(). * Uses sysfs_streq instead of strcmp for matching. * * This routine will look for a string in an array of strings up to the * n-th element in the array or until the first NULL element. * * Historically the value of -1 for @n, was used to search in arrays that * are NULL terminated. However, the function does not make a distinction * when finishing the search: either @n elements have been compared OR * the first NULL element was found. */int __sysfs_match_string(const char * const *array, size_t n, const char *str){	const char *item;	int index; 	for (index = 0; index < n; index++) {		item = array[index];		if (!item)			break;		if (sysfs_streq(item, str))			return index;	} 	return -EINVAL;}EXPORT_SYMBOL(__sysfs_match_string); #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; 	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. */#undef bcmpint 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 == 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

Lines 501–1000 of 1131. Previous lines