string: add strncpy
This commit is contained in:
parent
a6ffef77b9
commit
746c907a43
2 changed files with 12 additions and 0 deletions
10
lib/string.c
10
lib/string.c
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue