string: add strncpy

This commit is contained in:
Michael Shaw 2023-10-18 20:58:03 -04:00
commit 746c907a43
2 changed files with 12 additions and 0 deletions

View file

@ -35,6 +35,16 @@ char *strcpy(char *dest, const char *src)
return dest;
}
char *strncpy(char *dest, const char *src, size_t n)
{
for (size_t i = 0; i < n; i++) {
dest[i] = src[i];
if (!src[i])
break;
}
return dest;
}
size_t strlen(const char *c)
{
const char *b = c;