Browse Source

Fixed stpncpy() implementation from Manuel

Eric Andersen 23 years ago
parent
commit
0a15e8cd89
1 changed files with 10 additions and 8 deletions
  1. 10 8
      libc/string/string.c

+ 10 - 8
libc/string/string.c

@@ -82,16 +82,18 @@ char *stpcpy(char *dst, const char *src)
 /********************** Function stpncpy ************************************/
 
 #ifdef L_stpncpy
-char *stpncpy(char *dst, const char *src, size_t len)
+char *stpncpy(register char * __restrict s1, 
+		register const char * __restrict s2, size_t n)
 {
-	while (len--) {
-		if (*src)
-			*dst++ = *src++;
-		else
-			*dst++ = '\0';
-	}
+	char *s = s1;
+	const char *p = s2;
 
-	return dst;
+	while (n) {
+		if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
+		++s;
+		--n;
+	}
+	return s1 + (s2 - p);
 }
 #endif