From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: ore@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] string: add nonempty helper
Date: Tue, 28 May 2024 10:25:42 +0200 [thread overview]
Message-ID: <20240528082542.3013919-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240528082542.3013919-1-a.fatoum@pengutronix.de>
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@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
next prev parent reply other threads:[~2024-05-28 8:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-28 8:25 [PATCH 1/2] string: inline isempty Ahmad Fatoum
2024-05-28 8:25 ` Ahmad Fatoum [this message]
2024-05-28 9:00 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240528082542.3013919-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=ore@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox