forked from Bananymous/banan-os
Add strcpy and strncpy
This commit is contained in:
parent
db656fe469
commit
5a3596170c
|
@ -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) \
|
||||
|
|
|
@ -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
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue