[PATCH v2 5/5] pbl: string: add strncmp

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Jan 14 04:00:59 PST 2026


From: Marco Felsch <m.felsch at pengutronix.de>

For use by PBL code, import the barebox proper definition of strncmp
into pbl/string.c.

Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 - > v2:
  - split off preparatory patch from
    https://lore.barebox.org/barebox/20251110-v2025-09-0-topic-optee-of-handling-v1-0-8f0625ac5471@pengutronix.de/T/#t
  - add a commit message body
---
 pbl/string.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/pbl/string.c b/pbl/string.c
index 528f62ef2055..89663fef3d6a 100644
--- a/pbl/string.c
+++ b/pbl/string.c
@@ -102,6 +102,21 @@ int strcmp(const char *cs, const char *ct)
 	return res;
 }
 
+int strncmp(const char *cs, const char *ct, size_t count)
+{
+	register signed char __res = 0;
+
+	BUG_ON(!cs || !ct);
+
+	while (count) {
+		if ((__res = *cs - *ct++) != 0 || !*cs++)
+			break;
+		count--;
+	}
+
+	return __res;
+}
+
 int strcasecmp(const char *s1, const char *s2)
 {
 	int c1, c2;
-- 
2.47.3




More information about the barebox mailing list