From 595086aec79bc4b0d30fab57d82e53695cce1c32 Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Fri, 6 Aug 2021 10:46:42 +0200 Subject: [PATCH] lib,string: add strcat() and strncat() functions Signed-off-by: Pawel Wieczorkiewicz --- include/string.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/string.h b/include/string.h index eb36890e..769b1259 100644 --- a/include/string.h +++ b/include/string.h @@ -419,6 +419,28 @@ static inline int strncasecmp(const char *s1, const char *s2, size_t n) { return res; } +static inline char *strcat(char *s1, const char *s2) { + strcpy(&s1[strlen(s1)], s2); + return s1; +} + +static inline char *strncat(char *s1, const char *s2, size_t n) { + char *dst; + + if (n == 0) + return s1; + + dst = &s1[strlen(s1)]; + while ((*dst++ = *s2++) != '\0') { + if (--n == 0) { + *dst = '\0'; + break; + } + } + + return s1; +} + /* External declarations */ extern unsigned long strtoul(const char *nptr, char **endptr, int base);