Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/string/stpncpy.c
Show All 26 Lines | |||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <string.h> | #include <string.h> | ||||
char * | char * | ||||
stpncpy(char * __restrict dst, const char * __restrict src, size_t n) | (stpncpy)(char * __restrict dst, const char * __restrict src, size_t n) | ||||
{ | { | ||||
for (; n--; dst++, src++) { | for (; n--; dst++, src++) { | ||||
if (!(*dst = *src)) { | if (!(*dst = *src)) { | ||||
char *ret = dst; | char *ret = dst; | ||||
while (n--) | while (n--) | ||||
*++dst = '\0'; | *++dst = '\0'; | ||||
return (ret); | return (ret); | ||||
} | } | ||||
} | } | ||||
return (dst); | return (dst); | ||||
} | } |