[PATCH 2/2] string: add nonempty helper

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

 



We have a number of places where we coerce an empty string to NULL to
make life easier for callers. Add a helper that can be used in idioms
like:

  getenv_nonempty(s) -> nonempty(getenv(s));

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
Just talked with Oleksij and this would have been useful for a patch he
is preparing.
---
 include/string.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/string.h b/include/string.h
index 5139c7ef1f3d..cbe6eddf7f88 100644
--- a/include/string.h
+++ b/include/string.h
@@ -38,4 +38,9 @@ static inline bool isempty(const char *s)
 	return !s || s[0] == '\0';
 }
 
+static inline const char *nonempty(const char *s)
+{
+	return isempty(s) ? NULL : s;
+}
+
 #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