mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-11 13:16:47 +00:00
new: memcmp函数
This commit is contained in:
parent
b6a77da0c9
commit
c2fa7bf46d
@ -51,3 +51,28 @@ long strncpy_from_user(char *dst, const char *src, unsigned long size);
|
||||
* @return long
|
||||
*/
|
||||
long strnlen_user(const char *src, unsigned long maxlen);
|
||||
|
||||
/**
|
||||
* @brief 逐字节比较指定内存区域的值,并返回s1、s2的第一个不相等的字节i处的差值(s1[i]-s2[i])。
|
||||
* 若两块内存区域的内容相同,则返回0
|
||||
*
|
||||
* @param s1 内存区域1
|
||||
* @param s2 内存区域2
|
||||
* @param len 要比较的内存区域长度
|
||||
* @return int s1、s2的第一个不相等的字节i处的差值(s1[i]-s2[i])。若两块内存区域的内容相同,则返回0
|
||||
*/
|
||||
static inline int memcmp(const void *s1, const void *s2, size_t len)
|
||||
{
|
||||
int diff;
|
||||
|
||||
asm("cld \n\t" // 复位DF,确保s1、s2指针是自增的
|
||||
"repz; cmpsb\n\t" CC_SET(nz)
|
||||
: CC_OUT(nz)(diff), "+D"(s1), "+S"(s2)
|
||||
: "c"(len)
|
||||
: "memory");
|
||||
|
||||
if (diff)
|
||||
diff = *(const unsigned char *)(s1 - 1) - *(const unsigned char *)(s2 - 1);
|
||||
|
||||
return diff;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user