[PATCH v2 001/113] string: implement strcmp_ptr and streq_ptr helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux