forked from Bananymous/banan-os
Add strcpy and strncpy
This commit is contained in:
10
libc/string/strcpy.c
Normal file
10
libc/string/strcpy.c
Normal 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
11
libc/string/strncpy.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user