Add a simple implementation of strncpy
authorChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2004 20:15:47 +0000 (20:15 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2004 20:15:47 +0000 (20:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11672 91177308-0d34-0410-b5e6-96231b3b80d8

runtime/GCCLibraries/libc/string.c

index c13b11266cb8aeda85e8ffc55dbf0f16244a37c6..9cff5ece858e6d95d850d41d9939a1132064305c 100644 (file)
@@ -35,6 +35,12 @@ char *strcpy(char *s1, const char *s2) {
   return dest;
 }
 
+char *strncpy(char *s1, const char *s2, size_t n) {
+  char *dest = s1;
+  while (n-- && (*s1++ = *s2++));
+  return dest;
+}
+
 char *strcat(char *s1, const char *s2) {
   strcpy(s1+strlen(s1), s2);
   return s1;