chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[PATCH] update klibc to version 0.181
[elogind.git]
/
klibc
/
klibc
/
strncat.c
diff --git
a/klibc/klibc/strncat.c
b/klibc/klibc/strncat.c
index 99d957594cfd07507d800edd867d06dc7625a285..0dd9deb984f1323874d64ef8fb5f0d11e8273387 100644
(file)
--- a/
klibc/klibc/strncat.c
+++ b/
klibc/klibc/strncat.c
@@
-3,9
+3,23
@@
*/
#include <string.h>
*/
#include <string.h>
+#include <klibc/compiler.h>
char *strncat(char *dst, const char *src, size_t n)
{
char *strncat(char *dst, const char *src, size_t n)
{
- strncpy(strchr(dst, '\0'), src, n);
+ char *q = strchr(dst, '\0');
+ const char *p = src;
+ char ch;
+ size_t nn = q-dst;
+
+ if ( __likely(nn <= n) )
+ n -= nn;
+
+ while (n--) {
+ *q++ = ch = *p++;
+ if ( !ch )
+ break;
+ }
+
return dst;
}
return dst;
}