Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / pic16 / libc / string / memmove.c
1 /*-------------------------------------------------------------------------
2   _memmove.c - part of string library functions
3
4              Adapted By -  Erik Petrich  . epetrich@users.sourceforge.net
5              from _memcpy.c which was originally
6              Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
7
8    This library is free software; you can redistribute it and/or modify it
9    under the terms of the GNU Library General Public License as published by the
10    Free Software Foundation; either version 2, or (at your option) any
11    later version.
12    
13    This library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU Library General Public License for more details.
17    
18    You should have received a copy of the GNU Library General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21    
22    In other words, you are welcome to use, share and improve this program.
23    You are forbidden to forbid anyone else to use, share and improve
24    what you give them.   Help stamp out software-hoarding!  
25 -------------------------------------------------------------------------*/
26 #include <string.h>
27
28 void *memmove (void *dst, void *src, size_t acount) 
29 {
30   void *ret = dst;
31   char *d;
32   char *s;
33
34     if(((int)src < (int)dst) && ((((int)src)+acount) > (int)dst)) {
35       /*
36        * copy from higher addresses to lower addresses
37       */
38       d = ((char *)dst)+acount-1;
39       s = ((char *)src)+acount-1;
40       while (acount--) {
41         *d-- = *s--;
42       }
43     } else {
44       /*
45        * copy from lower addresses to higher addresses
46       */
47       d = dst;
48       s = src;
49       while (acount--) {
50         *d++ = *s++;
51       }
52     }
53
54   return(ret);
55 }