Add strcpy and strncpy

This commit is contained in:
Bananymous
2022-11-12 23:47:06 +02:00
parent db656fe469
commit 5a3596170c
4 changed files with 26 additions and 0 deletions

10
libc/string/strcpy.c Normal file
View File

@@ -0,0 +1,10 @@
#include <string.h>
char* strcpy(char* restrict dest, const char* restrict src)
{
size_t i;
for (i = 0; src[i]; i++)
dest[i] = src[i];
dest[i] = '\0';
return dest;
}

11
libc/string/strncpy.c Normal file
View File

@@ -0,0 +1,11 @@
#include <string.h>
char* strncpy(char* restrict dest, const char* restrict src, size_t n)
{
size_t i;
for (i = 0; src[i] && i < n; i++)
dest[i] = src[i];
for (; i < n; i++)
dest[i] = '\0';
return dest;
}