blob: f44bf0433a5e6a5d0df1117b302f95ab40289a7b [file] [log] [blame]
Guido van Rossumbe0e9421993-12-24 10:32:00 +00001/***********************************************************
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00002Copyright (c) 2000, BeOpen.com.
3Copyright (c) 1995-2000, Corporation for National Research Initiatives.
4Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
5All rights reserved.
Guido van Rossumbe0e9421993-12-24 10:32:00 +00006
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00007See the file "Misc/COPYRIGHT" for information on usage and
8redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumbe0e9421993-12-24 10:32:00 +00009******************************************************************/
10
11/* A perhaps slow but I hope correct implementation of memmove */
12
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000013extern char *memcpy(char *, char *, int);
Guido van Rossumbe0e9421993-12-24 10:32:00 +000014
15char *
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000016memmove(char *dst, char *src, int n)
Guido van Rossumbe0e9421993-12-24 10:32:00 +000017{
18 char *realdst = dst;
19 if (n <= 0)
20 return dst;
21 if (src >= dst+n || dst >= src+n)
22 return memcpy(dst, src, n);
23 if (src > dst) {
24 while (--n >= 0)
25 *dst++ = *src++;
26 }
27 else if (src < dst) {
28 src += n;
29 dst += n;
30 while (--n >= 0)
31 *--dst = *--src;
32 }
33 return realdst;
34}