From cf7260d432e789ae93947c245af1f4fdda799ac9 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Sat, 13 Feb 2021 13:14:02 -0500 Subject: [PATCH] add an ascii strndup() implementation. Signed-off-by: Peter Jones --- include/str.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/str.h b/include/str.h index ea03ee3..baa260e 100644 --- a/include/str.h +++ b/include/str.h @@ -42,6 +42,24 @@ strcata(CHAR8 *dest, const CHAR8 *src) return dest; } +static inline +__attribute__((unused)) +CHAR8 * +strndupa(const CHAR8 * const src, const UINTN srcmax) +{ + UINTN len; + CHAR8 *news = NULL; + + if (!src || !srcmax) + return news; + + len = strnlena(src, srcmax); + news = AllocateZeroPool(len); + if (news) + strncpya(news, src, len); + return news; +} + static inline __attribute__((unused)) CHAR8 *