From 186595864c4c7c47fe3a9795e4867b8a72205e38 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 9 Feb 2021 13:39:48 -0500 Subject: [PATCH] includes: add strchra() and strchrnula() impls Unfortunately GNU-EFI doesn't currently implement ascii versions of strchr() or strchrnul(), and we kind of need them, so add an implementation here for now. Signed-off-by: Peter Jones --- include/str.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/str.h b/include/str.h index f73c621..ea03ee3 100644 --- a/include/str.h +++ b/include/str.h @@ -64,4 +64,30 @@ translate_slashes(CHAR8 *out, const char *str) return out; } +static inline UNUSED CHAR8 * +strchrnula(const CHAR8 *s, int c) +{ + unsigned int i; + + if (s == NULL) + return NULL; + + for (i = 0; s[i] != '\000' && s[i] != c; i++) + ; + + return (CHAR8 *)&s[i]; +} + +static inline UNUSED CHAR8 * +strchra(const CHAR8 *s, int c) +{ + const CHAR8 *s1; + + s1 = strchrnula(s, c); + if (!s1 || s1[0] == '\000') + return NULL; + + return (CHAR8 *)s1; +} + #endif /* SHIM_STR_H */