Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rtla: Add str_has_prefix() helper function

Add a str_has_prefix() helper function that tests whether a string
starts with a given prefix. This function provides a cleaner interface
for prefix matching compared to using strncmp() with strlen() directly.

The function returns a boolean value indicating whether the string
starts with the specified prefix. This helper will be used in
subsequent changes to simplify prefix matching code throughout rtla.

Also add the missing string.h include which is needed for the strlen()
and strncmp() functions used by str_has_prefix() and the existing
strncmp_static() macro.

Signed-off-by: Wander Lairson Costa <wander@redhat.com>
Link: https://lore.kernel.org/r/20260309195040.1019085-11-wander@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>

authored by

Wander Lairson Costa and committed by
Tomas Glozar
0f4bc9d6 d847188b

+13
+13
tools/tracing/rtla/src/utils.h
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 3 #include <stdint.h> 4 + #include <string.h> 4 5 #include <time.h> 5 6 #include <sched.h> 6 7 #include <stdbool.h> ··· 24 23 25 24 /* Compare string with static string, length determined at compile time */ 26 25 #define strncmp_static(s1, s2) strncmp(s1, s2, ARRAY_SIZE(s2)) 26 + 27 + /** 28 + * str_has_prefix - Test if a string has a given prefix 29 + * @str: The string to test 30 + * @prefix: The string to see if @str starts with 31 + * 32 + * Returns: true if @str starts with @prefix, false otherwise 33 + */ 34 + static inline bool str_has_prefix(const char *str, const char *prefix) 35 + { 36 + return strncmp(str, prefix, strlen(prefix)) == 0; 37 + } 27 38 28 39 #define container_of(ptr, type, member)({ \ 29 40 const typeof(((type *)0)->member) *__mptr = (ptr); \