diff options
author | Bjoern A. Zeeb <bz@FreeBSD.org> | 2022-10-31 22:17:00 +0000 |
---|---|---|
committer | Bjoern A. Zeeb <bz@FreeBSD.org> | 2022-11-07 12:49:01 +0000 |
commit | 6a647ae51409cd56cc4a78d0a64ba3ff3aa3aac0 (patch) | |
tree | 14bff98ad4c0afb9dcbf12bc07e9ba91552ae96b /sys/compat | |
parent | 4a67f1df8bdf70bc4a54ae212563dedfe4546e8d (diff) | |
download | src-6a647ae51409cd56cc4a78d0a64ba3ff3aa3aac0.tar.gz src-6a647ae51409cd56cc4a78d0a64ba3ff3aa3aac0.zip |
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
Diffstat (limited to 'sys/compat')
-rw-r--r-- | sys/compat/linuxkpi/common/include/linux/string.h | 13 |
1 files changed, 13 insertions, 0 deletions
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_ */ |