about summary refs log tree commit diff
path: root/string/memccpy.c
diff options
context:
space:
mode:
Diffstat (limited to 'string/memccpy.c')
-rw-r--r--string/memccpy.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/string/memccpy.c b/string/memccpy.c
index d9ed6975ef..0987c84aa0 100644
--- a/string/memccpy.c
+++ b/string/memccpy.c
@@ -26,15 +26,12 @@
 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)
+    return __mempcpy (dest, src, p - src + 1);
 
+  memcpy (dest, src, n);
   return NULL;
 }