summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-04-13 15:44:56 +0000
committerEric Andersen <andersen@codepoet.org>2002-04-13 15:44:56 +0000
commit0a15e8cd8938730820c9c607710831d3fc8461e9 (patch)
tree9c4d616c002b89f75248674364eb5f630a4aa1ee /libc
parent929686ba6a01168aee43cb3b854d24133f4ef38e (diff)
Fixed stpncpy() implementation from Manuel
Diffstat (limited to 'libc')
-rw-r--r--libc/string/string.c18
1 files changed, 10 insertions, 8 deletions
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