[LTP] [PATCH 05/10] KVM: Add memcmp() helper function
Martin Doucha
mdoucha@suse.cz
Tue Jan 21 17:44:19 CET 2025
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
testcases/kernel/kvm/include/kvm_guest.h | 2 ++
testcases/kernel/kvm/lib_guest.c | 12 ++++++++++++
2 files changed, 14 insertions(+)
diff --git a/testcases/kernel/kvm/include/kvm_guest.h b/testcases/kernel/kvm/include/kvm_guest.h
index 0eabfb9a0..3f3e2f16c 100644
--- a/testcases/kernel/kvm/include/kvm_guest.h
+++ b/testcases/kernel/kvm/include/kvm_guest.h
@@ -48,6 +48,8 @@ void *memset(void *dest, int val, size_t size);
void *memzero(void *dest, size_t size);
void *memcpy(void *dest, const void *src, size_t size);
+int memcmp(const void *a, const void *b, size_t length);
+
char *strcpy(char *dest, const char *src);
char *strcat(char *dest, const char *src);
size_t strlen(const char *str);
diff --git a/testcases/kernel/kvm/lib_guest.c b/testcases/kernel/kvm/lib_guest.c
index 2e3e9cb6e..6f0b2824c 100644
--- a/testcases/kernel/kvm/lib_guest.c
+++ b/testcases/kernel/kvm/lib_guest.c
@@ -45,6 +45,18 @@ void *memcpy(void *dest, const void *src, size_t size)
return dest;
}
+int memcmp(const void *a, const void *b, size_t length)
+{
+ const unsigned char *x = a, *y = b;
+
+ for (; length; x++, y++, length--) {
+ if (*x != *y)
+ return (int)*x - (int)*y;
+ }
+
+ return 0;
+}
+
char *strcpy(char *dest, const char *src)
{
char *ret = dest;
--
2.47.0
More information about the ltp
mailing list