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

View File

@ -37,7 +37,9 @@ string/memcmp.o \
string/memcpy.o \
string/memmove.o \
string/memset.o \
string/strcpy.o \
string/strlen.o \
string/strncpy.o \
HOSTEDOBJS=\
$(ARCH_HOSTEDOBJS) \

View File

@ -13,6 +13,9 @@ void* memmove(void*, const void*, size_t);
void* memset(void*, int, size_t);
size_t strlen(const char*);
char* strcpy(char* __restrict, const char* __restrict);
char* strncpy(char* __restrict, const char* __restrict, size_t);
#ifdef __cplusplus
}
#endif

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;
}