Message ID | 000701d052a0$79ec7910$6dc56b30$@com |
---|---|
State | New |
Headers | show |
diff --git a/string/memccpy.c b/string/memccpy.c index 70ee2ae..d4146f9 100644 --- a/string/memccpy.c +++ b/string/memccpy.c @@ -26,15 +26,15 @@ void * __memccpy (void *dest, const void *src, int c, size_t n) { - const char *s = src; - char *d = dest; - const char x = c; - size_t i = n; + void *p = memchr (src, c, n); - while (i-- > 0) - if ((*d++ = *s++) == x) - return d; + if (p != NULL) + { + n = p - src + 1; + return __mempcpy (dest, src, n); + } + memcpy (dest, src, n); return NULL; }