git: 6a647ae51409 - main - LinuxKPI: string.h implement memcpy_and_pad()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 07 Nov 2022 12:51:23 UTC
The branch main has been updated by bz:
URL: https://cgit.FreeBSD.org/src/commit/?id=6a647ae51409cd56cc4a78d0a64ba3ff3aa3aac0
commit 6a647ae51409cd56cc4a78d0a64ba3ff3aa3aac0
Author: Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-10-31 22:17:00 +0000
Commit: Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-11-07 12:49:01 +0000
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_ */