diff options
Diffstat (limited to 'src/string/memccpy.c')
-rw-r--r-- | src/string/memccpy.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/string/memccpy.c b/src/string/memccpy.c new file mode 100644 index 00000000..a6aa6372 --- /dev/null +++ b/src/string/memccpy.c @@ -0,0 +1,20 @@ +#include <string.h> + +void *memccpy(void * restrict s1, const void * restrict s2, int c, size_t n) +{ + //__ASSERT_NOOVERLAP(s1, s2, n); + + unsigned char *dst = s1; + const unsigned char *src = s2; + for (size_t i = 0; i < n; i++) { + dst[i] = src[i]; + if (dst[i] == (unsigned char)c) { + return dst + i + 1; + } + } + return NULL; +} + +/* +XOPEN(4) +*/ |