lib: string: Add strlcat() and memscpy()

Add strlcat() and memscpy() currently its not
present in uboot. make these function available
in uboot.

Update function declaration also in headers as
avoid warnings.

strlcat(): Append a length limited string to another.

memscpy(): Copy data between buffer. The main aim of memscpy
is to prevent buffer overflows by taking in both the
destination size and copy size.

Change-Id: Icfc4cb4f8d668c0cace02af97617ccc3eecc5651
Signed-off-by: Md Sadre Alam <mdalam@codeaurora.org>
diff --git a/include/linux/string.h b/include/linux/string.h
index c7047ba..8d168e0 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -39,6 +39,9 @@
 #ifndef __HAVE_ARCH_STRNCAT
 extern char * strncat(char *, const char *, __kernel_size_t);
 #endif
+#ifndef __HAVE_ARCH_STRLCAT
+extern size_t strlcat(char *, const char *, __kernel_size_t);
+#endif
 #ifndef __HAVE_ARCH_STRCMP
 extern int strcmp(const char *,const char *);
 #endif
diff --git a/lib/string.c b/lib/string.c
index 87c9a40..0dec46c 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -175,6 +175,34 @@
 }
 #endif
 
+#ifndef __HAVE_ARCH_STRLCAT
+/**
+ * strlcat - Append a length-limited, %NUL-terminated string to another
+ * @dest: The string to be appended to
+ * @src: The string to append to it
+ * @count: The size of the destination buffer.
+ *
+ */
+size_t strlcat(char *dest, const char *src, size_t count)
+{
+	size_t dsize = strlen(dest);
+	size_t len = strlen(src);
+	size_t res = dsize + len;
+
+	/* This would be a bug */
+	BUG_ON(dsize >= count);
+
+	dest += dsize;
+	count -= dsize;
+	if (len >= count)
+		len = count-1;
+	memcpy(dest, src, len);
+	dest[len] = 0;
+	return res;
+}
+EXPORT_SYMBOL(strlcat);
+#endif
+
 #ifndef __HAVE_ARCH_STRCMP
 /**
  * strcmp - Compare two strings
@@ -520,6 +548,12 @@
 }
 #endif
 
+size_t memscpy(void *dest, size_t dst_size, const void *src, size_t copy_size) {
+	size_t min_size = dst_size < copy_size ? dst_size : copy_size;
+	memcpy(dest, src, min_size);
+	return min_size;
+}
+
 #ifndef __HAVE_ARCH_MEMMOVE
 /**
  * memmove - Copy one area of memory to another