From 5d310ea8c5f98bbf53078ec632f6441f54dc9e44 Mon Sep 17 00:00:00 2001 From: "Bjoern A. Zeeb" Date: Mon, 14 Nov 2022 23:26:22 +0000 Subject: [PATCH] LinuxKPI: add memset_startat macro Add a memset_startat() macro which sets a pattern from a struct member to the end of the struct. Needed by a wireless driver. MFC after: 3 days Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D37389 --- sys/compat/linuxkpi/common/include/linux/string.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/string.h b/sys/compat/linuxkpi/common/include/linux/string.h index 36f27a385d65..932bed81d034 100644 --- a/sys/compat/linuxkpi/common/include/linux/string.h +++ b/sys/compat/linuxkpi/common/include/linux/string.h @@ -249,4 +249,12 @@ memcpy_and_pad(void *dst, size_t dstlen, const void *src, size_t len, int ch) } } +#define memset_startat(ptr, bytepat, smember) \ +({ \ + uint8_t *_ptr = (uint8_t *)(ptr); \ + int _c = (int)(bytepat); \ + size_t _o = offsetof(typeof(*(ptr)), smember); \ + memset(_ptr + _o, _c, sizeof(*(ptr)) - _o); \ +}) + #endif /* _LINUXKPI_LINUX_STRING_H_ */