From 0a15e8cd8938730820c9c607710831d3fc8461e9 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Sat, 13 Apr 2002 15:44:56 +0000 Subject: Fixed stpncpy() implementation from Manuel --- libc/string/string.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'libc/string') diff --git a/libc/string/string.c b/libc/string/string.c index 11666611a..019e358b5 100644 --- a/libc/string/string.c +++ b/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 -- cgit v1.2.3