From 8657dc5b4f380b2c45e1f54b9843f8a80a0cd49e Mon Sep 17 00:00:00 2001
From: John Hodge <tpg@mutabah.net>
Date: Mon, 18 Jul 2011 10:10:04 +0800
Subject: [PATCH] Kernel - Implemented strcat/strncat

---
 Kernel/include/acess.h |  2 ++
 Kernel/lib.c           | 30 ++++++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h
index 31664769..545ecb11 100644
--- a/Kernel/include/acess.h
+++ b/Kernel/include/acess.h
@@ -335,6 +335,8 @@ extern int	sprintf(char *__s, const char *__format, ...);
 extern size_t	strlen(const char *Str);
 extern char	*strcpy(char *__dest, const char *__src);
 extern char	*strncpy(char *__dest, const char *__src, size_t max);
+extern char	*strcat(char *__dest, const char *__src);
+extern char	*strncat(char *__dest, const char *__src, size_t n);
 extern int	strcmp(const char *__str1, const char *__str2);
 extern int	strncmp(const char *Str1, const char *Str2, size_t num);
 extern int	strucmp(const char *Str1, const char *Str2);
diff --git a/Kernel/lib.c b/Kernel/lib.c
index 51dbe058..0b5ccfe8 100644
--- a/Kernel/lib.c
+++ b/Kernel/lib.c
@@ -62,6 +62,8 @@ EXPORT(ByteSum);
 EXPORT(strlen);
 EXPORT(strcpy);
 EXPORT(strncpy);
+EXPORT(strcat);
+EXPORT(strncat);
 EXPORT(strcmp);
 EXPORT(strncmp);
 //EXPORT(strdup);
@@ -464,7 +466,6 @@ size_t strlen(const char *__str)
 }
 
 /**
- * \fn char *strcpy(char *__str1, const char *__str2)
  * \brief Copy a string to a new location
  */
 char *strcpy(char *__str1, const char *__str2)
@@ -476,8 +477,8 @@ char *strcpy(char *__str1, const char *__str2)
 }
 
 /**
- * \fn char *strncpy(char *__str1, const char *__str2, size_t max)
  * \brief Copy a string to a new location
+ * \note Copies at most `max` chars
  */
 char *strncpy(char *__str1, const char *__str2, size_t max)
 {
@@ -488,6 +489,31 @@ char *strncpy(char *__str1, const char *__str2, size_t max)
 	return __str1;
 }
 
+/**
+ * \brief Append a string to another
+ */
+char *strcat(char *__dest, const char *__src)
+{
+	while(*__dest++);
+	while(*__src)
+		*__dest++ = *__src++;
+	*__dest = '\0';
+	return __dest;
+}
+
+/**
+ * \brief Append at most \a n chars to a string from another
+ * \note At most n+1 chars are written (the dest is always zero terminated)
+ */
+char *strncat(char *__dest, const char *__src, size_t n)
+{
+	while(*__dest++);
+	while(*__src && n-- >= 1)
+		*__dest++ = *__src++;
+	*__dest = '\0';
+	return __dest;
+}
+
 /**
  * \fn int strcmp(const char *str1, const char *str2)
  * \brief Compare two strings return the difference between
-- 
GitLab