chiark / gitweb /
volume_id: provide libvolume_id.a file
[elogind.git] / klibc / klibc / memmove.c
1 /*
2  * memmove.c
3  */
4
5 #include <string.h>
6
7 void *memmove(void *dst, const void *src, size_t n)
8 {
9   const char *p = src;
10   char *q = dst;
11 #if defined(__i386__) || defined(__x86_64__)
12   if ( q < p ) {
13     asm volatile("cld ; rep ; movsb" : "+c" (n), "+S" (p), "+D" (q));
14   } else {
15     p += (n-1);
16     q += (n-1);
17     asm volatile("std ; rep ; movsb" : "+c" (n), "+S" (p), "+D" (q));
18   }
19 #else
20   if ( q < p ) {
21     while ( n-- ) {
22       *q++ = *p++;
23     }
24   } else {
25     p += n;
26     q += n;
27     while ( n-- ) {
28       *--q = *--p;
29     }
30   }
31 #endif
32
33   return dst;
34 }