--- string/strncpy.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/string/strncpy.c b/string/strncpy.c index 0915e03..604417c 100644 --- a/string/strncpy.c +++ b/string/strncpy.c @@ -78,9 +78,12 @@ STRNCPY (char *s1, const char *s2, size_t n) while (c != '\0'); zero_fill: - do - *++s1 = '\0'; - while (--n > 0); + if (n >= 8) + memset (s1 + 1, '\0', n); + else + do + *++s1 = '\0'; + while (--n > 0); return s; } -- 1.7.9.5