diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2024-03-04 19:58:46 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2024-03-05 16:28:04 +0100 |
commit | ab6b3b6b43a7e9f91a99fb8c1ff1c3a7c666fcd9 (patch) | |
tree | 61a0d2610fb816a4a245182e8f4ae9c3bde1fa7b | |
parent | 023cae6caa637c993b4ea0e65b2b6d97faab0f09 (diff) | |
download | barebox-ab6b3b6b43a7.tar.gz barebox-ab6b3b6b43a7.tar.xz |
string: implement strcmp_ptr and streq_ptr helpers
These helpers take care of NULL transparently and will be useful to
avoid explicit NULL checks in follow-up commits.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20240304190038.3486881-2-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | include/string.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/string.h b/include/string.h index 43911b7576..71810180b5 100644 --- a/include/string.h +++ b/include/string.h @@ -3,6 +3,7 @@ #define __STRING_H #include <linux/string.h> +#include <linux/minmax.h> void *mempcpy(void *dest, const void *src, size_t count); int strtobool(const char *str, int *val); @@ -20,4 +21,14 @@ char *parse_assignment(char *str); int strverscmp(const char *a, const char *b); +static inline int strcmp_ptr(const char *a, const char *b) +{ + return a && b ? strcmp(a, b) : compare3(a, b); +} + +static inline bool streq_ptr(const char *a, const char *b) +{ + return strcmp_ptr(a, b) == 0; +} + #endif /* __STRING_H */ |