mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] string: inline isempty
@ 2024-05-28  8:25 Ahmad Fatoum
  2024-05-28  8:25 ` [PATCH 2/2] string: add nonempty helper Ahmad Fatoum
  2024-05-28  9:00 ` [PATCH 1/2] string: inline isempty Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-05-28  8:25 UTC (permalink / raw)
  To: barebox; +Cc: ore, Ahmad Fatoum

The helper is trivial, so make it inline to save users the minimal
hassle of calling it out-of-line.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/string.h | 5 ++++-
 lib/string.c     | 6 ------
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/include/string.h b/include/string.h
index 4ee3be6d93cc..5139c7ef1f3d 100644
--- a/include/string.h
+++ b/include/string.h
@@ -33,6 +33,9 @@ static inline bool streq_ptr(const char *a, const char *b)
 	return strcmp_ptr(a, b) == 0;
 }
 
-bool isempty(const char *s);
+static inline bool isempty(const char *s)
+{
+	return !s || s[0] == '\0';
+}
 
 #endif /* __STRING_H */
diff --git a/lib/string.c b/lib/string.c
index 7e4bec2e99cc..374f326143a7 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -1049,9 +1049,3 @@ char *strreplace(char *str, char old, char new)
 	return str;
 }
 EXPORT_SYMBOL(strreplace);
-
-bool isempty(const char *s)
-{
-	return !s || s[0] == '\0';
-}
-EXPORT_SYMBOL(isempty);
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] string: add nonempty helper
  2024-05-28  8:25 [PATCH 1/2] string: inline isempty Ahmad Fatoum
@ 2024-05-28  8:25 ` Ahmad Fatoum
  2024-05-28  9:00 ` [PATCH 1/2] string: inline isempty Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-05-28  8:25 UTC (permalink / raw)
  To: barebox; +Cc: ore, Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] string: inline isempty
  2024-05-28  8:25 [PATCH 1/2] string: inline isempty Ahmad Fatoum
  2024-05-28  8:25 ` [PATCH 2/2] string: add nonempty helper Ahmad Fatoum
@ 2024-05-28  9:00 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-05-28  9:00 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum; +Cc: ore


On Tue, 28 May 2024 10:25:41 +0200, Ahmad Fatoum wrote:
> The helper is trivial, so make it inline to save users the minimal
> hassle of calling it out-of-line.
> 
> 

Applied, thanks!

[1/2] string: inline isempty
      https://git.pengutronix.de/cgit/barebox/commit/?id=6fc15d43dabc (link may not be stable)
[2/2] string: add nonempty helper
      https://git.pengutronix.de/cgit/barebox/commit/?id=7253e9872c95 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-28  9:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-28  8:25 [PATCH 1/2] string: inline isempty Ahmad Fatoum
2024-05-28  8:25 ` [PATCH 2/2] string: add nonempty helper Ahmad Fatoum
2024-05-28  9:00 ` [PATCH 1/2] string: inline isempty Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox