[PATCH 001/112] string: implement strcmp_ptr and streq_ptr helpers
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed Jan 3 10:11:21 PST 2024
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 at pengutronix.de>
---
include/string.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/include/string.h b/include/string.h
index 43911b75762f..71810180b5ba 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 */
--
2.39.2
More information about the barebox
mailing list