[PATCH 2/2] string: add nonempty helper
Ahmad Fatoum
a.fatoum at pengutronix.de
Tue May 28 01:25:42 PDT 2024
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 at pengutronix.de>
---
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
More information about the barebox
mailing list