mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 04:24:31 +01:00
Replace bpf_strlcpy() in bpf_util.h with a sized_strscpy(), which is a simplified sized_strscpy() from the kernel (lib/string.c [1]). It: * takes a count (destination size) parameter * guarantees NULL-termination * returns the number of characters copied or -E2BIG Re-define strscpy macro similar to in-kernel implementation [2]: allow the count parameter to be optional. Add #ifdef-s to tools/include/linux/args.h, as they may be defined in other system headers (for example, __CONCAT in sys/cdefs.h). Fixup the single existing bpf_strlcpy() call in cgroup_helpers.c [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/string.c?h=v6.19#n113 [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/string.h?h=v6.19#n91 Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://lore.kernel.org/r/20260223190736.649171-2-ihor.solodrai@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
32 lines
1 KiB
C
32 lines
1 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef _LINUX_ARGS_H
|
|
#define _LINUX_ARGS_H
|
|
|
|
/*
|
|
* How do these macros work?
|
|
*
|
|
* In __COUNT_ARGS() _0 to _12 are just placeholders from the start
|
|
* in order to make sure _n is positioned over the correct number
|
|
* from 12 to 0 (depending on X, which is a variadic argument list).
|
|
* They serve no purpose other than occupying a position. Since each
|
|
* macro parameter must have a distinct identifier, those identifiers
|
|
* are as good as any.
|
|
*
|
|
* In COUNT_ARGS() we use actual integers, so __COUNT_ARGS() returns
|
|
* that as _n.
|
|
*/
|
|
|
|
/* This counts to 15. Any more, it will return 16th argument. */
|
|
#define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _n, X...) _n
|
|
#define COUNT_ARGS(X...) __COUNT_ARGS(, ##X, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
|
|
|
|
/* Concatenate two parameters, but allow them to be expanded beforehand. */
|
|
#ifndef __CONCAT
|
|
#define __CONCAT(a, b) a ## b
|
|
#endif
|
|
#ifndef CONCATENATE
|
|
#define CONCATENATE(a, b) __CONCAT(a, b)
|
|
#endif
|
|
|
|
#endif /* _LINUX_ARGS_H */
|