Commit 2a8864a7 authored by Ulrich Huber's avatar Ulrich Huber Committed by Oliver Horst
Browse files

[add] Add strncpy to libc-repl

parent 8881faa7
......@@ -7,6 +7,8 @@ void *memcpy(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
void *memmove(void *dst_void, const void *src_void, size_t length);
char *strncpy(char *dest, const char *src, size_t n);
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
......@@ -21,7 +23,6 @@ char * strtok(char *string, const char *delimiters);
#define strcat __builtin_strcat
#define strchr __builtin_strchr
#define strcpy __builtin_strcpy
#define strncpy __builtin_strncpy
#define strcspn __builtin_strcspn
#define strncat __builtin_strncat
#define strpbrk __builtin_strpbrk
......
......@@ -10,6 +10,7 @@ target_sources(
"${CMAKE_CURRENT_LIST_DIR}/memmove.S"
"${CMAKE_CURRENT_LIST_DIR}/strcmp.c"
"${CMAKE_CURRENT_LIST_DIR}/strncmp.c"
"${CMAKE_CURRENT_LIST_DIR}/strncpy.c"
"${CMAKE_CURRENT_LIST_DIR}/strlen.c"
"${CMAKE_CURRENT_LIST_DIR}/strnlen.c"
"${CMAKE_CURRENT_LIST_DIR}/strtok.c"
......
#include <string.h>
char *strncpy(char *dest, const char *src, size_t n) {
size_t num;
num = strlen(src) + 1;
if (num > n)
num = n;
memcpy(dest, src, num);
if (num < n) {
memset(dest[num], '\0', n-num);
}
return dest;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment