git: 5d310ea8c5f9 - main - LinuxKPI: add memset_startat macro
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 15 Nov 2022 12:54:39 UTC
The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=5d310ea8c5f98bbf53078ec632f6441f54dc9e44 commit 5d310ea8c5f98bbf53078ec632f6441f54dc9e44 Author: Bjoern A. Zeeb <bz@FreeBSD.org> AuthorDate: 2022-11-14 23:26:22 +0000 Commit: Bjoern A. Zeeb <bz@FreeBSD.org> CommitDate: 2022-11-15 12:52:10 +0000 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_ */