Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/string/strncat.c
Show All 39 Lines | |||||
#include <string.h> | #include <string.h> | ||||
/* | /* | ||||
* Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes | * Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes | ||||
* are written at dst (at most n+1 bytes being appended). Return dst. | * are written at dst (at most n+1 bytes being appended). Return dst. | ||||
*/ | */ | ||||
char * | char * | ||||
strncat(char * __restrict dst, const char * __restrict src, size_t n) | (strncat)(char * __restrict dst, const char * __restrict src, size_t n) | ||||
{ | { | ||||
if (n != 0) { | if (n != 0) { | ||||
char *d = dst; | char *d = dst; | ||||
const char *s = src; | const char *s = src; | ||||
while (*d != 0) | while (*d != 0) | ||||
d++; | d++; | ||||
do { | do { | ||||
if ((*d = *s++) == 0) | if ((*d = *s++) == 0) | ||||
break; | break; | ||||
d++; | d++; | ||||
} while (--n != 0); | } while (--n != 0); | ||||
*d = 0; | *d = 0; | ||||
} | } | ||||
return (dst); | return (dst); | ||||
} | } |