git: c4c522788720 - stable/13 - LinuxKPI: string.h implement memcpy_and_pad()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 28 Nov 2022 17:27:02 UTC
The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=c4c5227887205f4a0d17b8f560f856ea79eb18ab commit c4c5227887205f4a0d17b8f560f856ea79eb18ab 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-28 16:30:57 +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. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D37226 (cherry picked from commit 6a647ae51409cd56cc4a78d0a64ba3ff3aa3aac0) --- 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 7a118bb17c48..c721ea6bab9d 100644 --- a/sys/compat/linuxkpi/common/include/linux/string.h +++ b/sys/compat/linuxkpi/common/include/linux/string.h @@ -227,4 +227,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_ */