From 6a647ae51409cd56cc4a78d0a64ba3ff3aa3aac0 Mon Sep 17 00:00:00 2001 From: "Bjoern A. Zeeb" Date: Mon, 31 Oct 2022 22:17:00 +0000 Subject: [PATCH] LinuxKPI: string.h implement memcpy_and_pad() Add a memcpy variant which takes length of source and destination buffers and a padding character in case there is free space in the destination. This is used by a wireless driver. MFC after: 3 days Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D37226 --- sys/compat/linuxkpi/common/include/linux/string.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/string.h b/sys/compat/linuxkpi/common/include/linux/string.h index 52110feda6df..36f27a385d65 100644 --- a/sys/compat/linuxkpi/common/include/linux/string.h +++ b/sys/compat/linuxkpi/common/include/linux/string.h @@ -236,4 +236,17 @@ memset_p(void **p, void *v, size_t n) return (memset64((uint64_t *)p, (uintptr_t)v, n)); } +static inline void +memcpy_and_pad(void *dst, size_t dstlen, const void *src, size_t len, int ch) +{ + + if (len >= dstlen) { + memcpy(dst, src, dstlen); + } else { + memcpy(dst, src, len); + /* Pad with given padding character. */ + memset((char *)dst + len, ch, dstlen - len); + } +} + #endif /* _LINUXKPI_LINUX_STRING_H_ */