diff --git a/include/string.h b/include/string.h index c4a93bd..cfca4d3 100644 --- a/include/string.h +++ b/include/string.h @@ -15,5 +15,8 @@ size_t strlen(const char *str); int strncmp(const char *s1, const char *s2, size_t len); char *strncpy(char *to, const char *from, size_t len); +char *strcat(char *s, const char *append); +char *strncat(char *s, const char *append, size_t count); + #endif /* __STRING_H__ */ diff --git a/lib/libc/string.c b/lib/libc/string.c index ec3730b..4731b68 100644 --- a/lib/libc/string.c +++ b/lib/libc/string.c @@ -2,6 +2,8 @@ * Copyright (c) 2013-2014 Stanford University * Copyright (c) 2006-2008 Ali Mashtizadeh * All rights reserved. + * + * XXX: add BSD copyright */ #include @@ -43,6 +45,41 @@ strncpy(char *to, const char *from, size_t length) return save; } +char * +strcat(char *s, const char *append) +{ + char *save = s; + + for (; *s; ++s); + while ((*s++ = *append++)); + + return save; +} + + +char * +strncat(char *dst, const char *src, size_t n) +{ + if (n != 0) { + char *d = dst; + const char *s = src; + + while (*d != 0) + d++; + + do { + if ((*d = *s++) == 0) + break; + + d++; + } while (--n != 0); + + *d = 0; + } + + return dst; +} + int strcmp(const char *s1, const char *s2) {