strncasecmp函数

摘自linux内核4.11.1 string.c
author: Linus Torvalds

头文件:#include <strings.h>
作用:比较两个字符串s1,s2,且忽略字符大小写
参数:
s1:字符串1
s2:字符串2
len:比较的最大字符数
返回值:
若s1和s2匹配(相等)返回0
若s1大于s2,返回大于0的值

若s1小于s2,返回小于0的值

/**
 * strncasecmp - Case insensitive, length-limited string comparison
 * @s1: One string
 * @s2: The other string
 * @len: the maximum number of characters to compare
 */
 
int strncasecmp(const char *s1, const char *s2, size_t len)
{
	/* Yes, Virginia, it had better be unsigned */
	unsigned char c1, c2;

	if (!len)
		return 0;

	do {
		c1 = *s1++;
		c2 = *s2++;
		if (!c1 || !c2)
			break;
		if (c1 == c2)
			continue;
		c1 = tolower(c1);
		c2 = tolower(c2);
		if (c1 != c2)
			break;
	} while (--len);
	return (int)c1 - (int)c2;
}


已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页